Re: Decompressing bzip2

2016-04-05 Thread Charles Hixson via Digitalmars-d-learn



On 04/05/2016 03:33 PM, Mike Parker via Digitalmars-d-learn wrote:

On Tuesday, 5 April 2016 at 19:27:20 UTC, Charles Hixson wrote:


...
Are you asserting that scope is soon to be officially deprecated? I'm 
finding "shouldn't really be used at all anymore" a bit of a worrying 
statement, as I much prefer the syntax used by scope.  Why shouldn't 
it "be used at all anymore"?


http://dlang.org/deprecate.html#scope%20for%20allocating%20classes%20on%20the%20stack 



Thanks. It is the "for other features" that I normally use scope. 
Mainly, admittedly, for timing the running of the destructor (or analogs 
thereto, like File.close), but the syntax is not the one being deprecated.


Re: Decompressing bzip2

2016-04-05 Thread Mike Parker via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 19:27:20 UTC, Charles Hixson wrote:


...
Are you asserting that scope is soon to be officially 
deprecated? I'm finding "shouldn't really be used at all 
anymore" a bit of a worrying statement, as I much prefer the 
syntax used by scope.  Why shouldn't it "be used at all 
anymore"?


http://dlang.org/deprecate.html#scope%20for%20allocating%20classes%20on%20the%20stack


Re: Convert wchar* to wstring?

2016-04-05 Thread Thalamus via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 19:19:10 UTC, ag0aep6g wrote:

On 05.04.2016 20:44, Thalamus wrote:

[...]


Aside: D has syntax for "// For wchar_t.": `import 
core.stdc.stddef: wchar_t;`.



[...]


wchar_t is not wchar. wstring is not (portably) compatible with 
a wchar_t array.


If you actually have a wchar_t* and you want a wstring as 
opposed to a wchar_t[], then you will potentially have to do 
some converting.


If you have a wchar*, then don't use wcslen, as that's defined 
in terms of wchar_t. There may be some function for finding the 
first null wchar from a wchar*, but I don't know it, and 
writing out a loop isn't exactly hard:



wstring toWstring(const(wchar)* value)
{
if (value is null) return null;
auto cursor = value;
while (*cursor != 0) ++cursor;
return value[0 .. cursor - value].dup;
}



Thank you for the feedback. You are correct.


Re: What's the rationale for considering "0x1.max" as invalid ?

2016-04-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 21:10:47 UTC, Basile B. wrote:

On Tuesday, 5 April 2016 at 20:56:54 UTC, Alex Parrill wrote:

On Tuesday, 5 April 2016 at 19:00:43 UTC, Basile B. wrote:

0x1.max // exponent expected in hex float
0x1 .max // OK
1.max // OK

What's the ambiguity when it's an hex literal ?


It's potentially ambiguous with hexadecimal floating point 
numbers


0xdeadbeef.p5 // hex float or hex int + method?

dlang.org/spec/lex.html#HexFloat


Yes but it's pointless to allow the decimal separator to be 
followed by the exponent:


void main()
{
import std.stdio;
writeln( typeof(0x1p5).stringof ); // double
writeln( typeof(0x1.p5).stringof ); // double
}


I mean that the rule could be: the decimal separator must be 
followed by a second group of digits. The second group of digits 
must be followed by an exponent. The first group of digits can be 
followed by an exponent.


0x1.0p5 // valid
0xp5 // valid
0x1.p5 // invalid (p is not a hex digit)
0x1.ap5 // valid


Re: What's the rationale for considering "0x1.max" as invalid ?

2016-04-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 20:56:54 UTC, Alex Parrill wrote:

On Tuesday, 5 April 2016 at 19:00:43 UTC, Basile B. wrote:

0x1.max // exponent expected in hex float
0x1 .max // OK
1.max // OK

What's the ambiguity when it's an hex literal ?


It's potentially ambiguous with hexadecimal floating point 
numbers


0xdeadbeef.p5 // hex float or hex int + method?

dlang.org/spec/lex.html#HexFloat


Yes but it's pointless to allow the decimal separator to be 
followed by the exponent:


void main()
{
import std.stdio;
writeln( typeof(0x1p5).stringof ); // double
writeln( typeof(0x1.p5).stringof ); // double
}



Re: What's the rationale for considering "0x1.max" as invalid ?

2016-04-05 Thread Alex Parrill via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 19:00:43 UTC, Basile B. wrote:

0x1.max // exponent expected in hex float
0x1 .max // OK
1.max // OK

What's the ambiguity when it's an hex literal ?


It's potentially ambiguous with hexadecimal floating point numbers

0xdeadbeef.p5 // hex float or hex int + method?

dlang.org/spec/lex.html#HexFloat


Re: What's the rationale for considering "0x1.max" as invalid ?

2016-04-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 19:00:43 UTC, Basile B. wrote:

0x1.max // exponent expected in hex float
0x1 .max // OK
1.max // OK

What's the ambiguity when it's an hex literal ?


https://issues.dlang.org/show_bug.cgi?id=15880


Re: Decompressing bzip2

2016-04-05 Thread Charles Hixson via Digitalmars-d-learn



On 04/04/2016 04:38 PM, Mike Parker via Digitalmars-d-learn wrote:

On Monday, 4 April 2016 at 21:32:10 UTC, stunaep wrote:


Can you please explain what the scope keyword does and if there


scope was originally intended to be used primarily with classes in 
order to get deterministic destruction. It ensures the destructor of a 
class is called when the scope exits, just as with a struct. It's not 
needed here and shouldn't really be used at all anymore. It has been 
superseded by std.typecons.scoped [1]. It's not needed here at all, 
though. bz_stream is a struct, so there's no need to allocate an 
instance of it:

...
Are you asserting that scope is soon to be officially deprecated? I'm 
finding "shouldn't really be used at all anymore" a bit of a worrying 
statement, as I much prefer the syntax used by scope.  Why shouldn't it 
"be used at all anymore"?


Re: overriding methods

2016-04-05 Thread pineapple via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 18:54:39 UTC, stunaep wrote:
I had no error on the examples I posted, only when using 
@Override previously. It just says to use override attribute 
instead of @Override


Unlike in Java, D's override indicator doesn't look like an 
annotation, it's just a keyword placed before a method along the 
same lines as "static" or "public" or "protected".


Re: Convert wchar* to wstring?

2016-04-05 Thread ag0aep6g via Digitalmars-d-learn

On 05.04.2016 20:44, Thalamus wrote:

import core.stdc.stddef; // For wchar_t. This is defined differently for
Windows vs POSIX.
import core.stdc.wchar_; // For wcslen.


Aside: D has syntax for "// For wchar_t.": `import core.stdc.stddef: 
wchar_t;`.



wstring toWstring(wchar_t* value)
{
 return value ? cast(wstring) value[0..wcslen(wstr)].dup : null;
}


wchar_t is not wchar. wstring is not (portably) compatible with a 
wchar_t array.


If you actually have a wchar_t* and you want a wstring as opposed to a 
wchar_t[], then you will potentially have to do some converting.


If you have a wchar*, then don't use wcslen, as that's defined in terms 
of wchar_t. There may be some function for finding the first null wchar 
from a wchar*, but I don't know it, and writing out a loop isn't exactly 
hard:



wstring toWstring(const(wchar)* value)
{
if (value is null) return null;
auto cursor = value;
while (*cursor != 0) ++cursor;
return value[0 .. cursor - value].dup;
}



What's the rationale for considering "0x1.max" as invalid ?

2016-04-05 Thread Basile B. via Digitalmars-d-learn

0x1.max // exponent expected in hex float
0x1 .max // OK
1.max // OK

What's the ambiguity when it's an hex literal ?


Re: overriding methods

2016-04-05 Thread Ali Çehreli via Digitalmars-d-learn

On 04/05/2016 11:54 AM, stunaep wrote:

> when using @Override previously. It just says to use override
> attribute instead of @Override

> source\game\client.d(7,3): Error: undefined identifier 'Override'

Note that it doesn't say _instead of Override_. Override is an undefined 
symbol in your code. @Override is user defined attribute (UDA) syntax. 
The programmer is responsible for defining the semantics of user defined 
attributes.


Ali



Re: overriding methods

2016-04-05 Thread Adam D. Ruppe via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 18:54:39 UTC, stunaep wrote:
I had no error on the examples I posted, only when using 
@Override previously. It just says to use override attribute 
instead of @Override


source\game\client.d(8,20): Deprecation: implicitly overriding 
base class method game.GameWindow.startThread with 
game.client.Client.startThread deprecated; add 'override' 
attribute
source\game\client.d(7,3): Error: undefined identifier 
'Override'


Yeah, that just means use the override keyword on the method. 
There is no @Override thing, it is a plain lowercase keyword.


Re: overriding methods

2016-04-05 Thread stunaep via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 18:42:33 UTC, Adam D. Ruppe wrote:

On Tuesday, 5 April 2016 at 18:38:43 UTC, stunaep wrote:
I get a deprecation warning with @Override, but I was unable 
to find the proper way to do it.


What error message exactly are you getting and on what code?

Both styles you put there should work equally well.


I had no error on the examples I posted, only when using 
@Override previously. It just says to use override attribute 
instead of @Override


source\game\client.d(8,20): Deprecation: implicitly overriding 
base class method game.GameWindow.startThread with 
game.client.Client.startThread deprecated; add 'override' 
attribute

source\game\client.d(7,3): Error: undefined identifier 'Override'


Re: Convert wchar* to wstring?

2016-04-05 Thread Thalamus via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 11:26:44 UTC, Thalamus wrote:

Thanks everyone! You've all been very helpful.


For anyone who has the same question and happens on this thread, 
I wanted to post what I finally came up with. I combined the 
information everyone in this thread gave me with what I saw in 
Phobos source for the to!string() implementation, closely 
following the latter. The important to!string() code is in the 
toImpl implementation in conv.d at line 880. The existing code 
uses strlen, but that's an ANSI function. Fortunately, D has 
wcslen available, too.


import core.stdc.stddef; // For wchar_t. This is defined 
differently for Windows vs POSIX.

import core.stdc.wchar_; // For wcslen.

wstring toWstring(wchar_t* value)
{
return value ? cast(wstring) value[0..wcslen(wstr)].dup : 
null;

}

The Phobos code notes that this operation is unsafe, because 
there's no guarantee the string is null-terminated as it should 
be. That's definitely true. The only outcome you can be really 
sure is accurate is an access violation. :)


thanks!
Thalamus



Re: overriding methods

2016-04-05 Thread Adam D. Ruppe via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 18:38:43 UTC, stunaep wrote:
I get a deprecation warning with @Override, but I was unable to 
find the proper way to do it.


What error message exactly are you getting and on what code?

Both styles you put there should work equally well.


overriding methods

2016-04-05 Thread stunaep via Digitalmars-d-learn
I get a deprecation warning with @Override, but I was unable to 
find the proper way to do it.

Am I meant to add override before the method like this?

override public void startThread(Thread t, int pri) {
   ...
}

Am I meant to wrap the entire method in override { } like this?

override {
   public void startThread(Thread t, int pri) {
   ...
   }
}


Both of them compile, so I'm wondering which to use. Is override 
{} supposed to be for adding multiple methods inside to avoid 
writing override before each method, or is putting override in 
front of the method without brackets just wrong?




Re: Get third part of front-end version number

2016-04-05 Thread Johan Engelen via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 18:01:05 UTC, Nick Sabalausky wrote:
These days, DMD/DMDFE version numbers are three parts, ex: 
2.070.1.


I can get the first two via std.compiler.version_major and 
std.compiler.version_minor. Is there a way to get the third 
part?


I know I can "dmd --help | grep DMD", but that only works for 
DMD. GDC's "gdc --version" doesn't appear to show the DMDFE 
version, and I have no idea about LDC.


"ldc2 --version" will give you the full DMDFE version it is based 
on.

E.g.
❯ bin/ldc2 --version
LDC - the LLVM D compiler (dff841):
  based on DMD v2.068.2 and LLVM 3.8.0svn-r262738



Get third part of front-end version number

2016-04-05 Thread Nick Sabalausky via Digitalmars-d-learn

These days, DMD/DMDFE version numbers are three parts, ex: 2.070.1.

I can get the first two via std.compiler.version_major and 
std.compiler.version_minor. Is there a way to get the third part?


I know I can "dmd --help | grep DMD", but that only works for DMD. GDC's 
"gdc --version" doesn't appear to show the DMDFE version, and I have no 
idea about LDC.


Or is the third part of the DMDFE version completely irrelevant to LDC/GDC?


Re: Using a macro for a function signature

2016-04-05 Thread pineapple via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 13:17:38 UTC, Anonymouse wrote:
You can't get rid of the signature completely as the functions 
still need a parameter list with x declared. You will get 
"Error: undefined identifier 'x'" otherwise. You can largely 
omit the *type* of x if it can be inferred from the signature, 
but you can't have its name be solely in the signature alias.


On Tuesday, 5 April 2016 at 13:19:43 UTC, ag0aep6g wrote:

On 05.04.2016 13:35, pineapple wrote:
Saves you some typing, especially with complicated parameter 
types.


Another thing is std.traits.Parameters


You are both wonderful, this is exactly what I was trying to work 
out. Thank you so much!





Re: Using a macro for a function signature

2016-04-05 Thread ag0aep6g via Digitalmars-d-learn

On 05.04.2016 13:35, pineapple wrote:

alias somelongsignature = int(in int x);


alias somelongsignature = int function(in int);

Or if you want to accept methods and such:

alias somelongsignature = int delegate(in int);

You can name the parameter, but it won't be part of the type.


int examplefunc0(in int x){
 return x * 2;
}

somelongsignature testfunc0 = examplefunc1;


somelongsignature testfunc0 = &examplefunc0;

Note the ampersand.


somelongsignature testfunc1 = somelongsignature {return x + 3};


I don't think there's a way to do this as nicely as you want.

One thing you can do is declare the parameters without types:

somelongsignature testfunc1 = (x) {return x + 3;};

Saves you some typing, especially with complicated parameter types.

Another thing is std.traits.Parameters:

alias F = int function(int, float, string, void*);
import std.traits: Parameters;
F testfunc2 = (Parameters!F args) {return args[0] + 3;};

This way you don't have to type out a long list of parameters, but 
`args[0]` isn't as nice as `x`, of course.


There may be a way to transfer the parameter names as well, but I 
suspect that's going to be a little more fiddly.


Re: Using a macro for a function signature

2016-04-05 Thread Anonymouse via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 11:35:24 UTC, pineapple wrote:
If I have a common function signature I'm using throughout my 
code, and I feel like there should be a way to condense it 
using a macro. The intuitive method isn't working, but this 
seems like something D would be able to do. What've I got wrong 
in this example?




alias somelongsignature = int(in int x);


alias somelongsignature = int function(in int);


int examplefunc0(in int x){
return x * 2;
}

somelongsignature testfunc0 = examplefunc1;
somelongsignature testfunc1 = somelongsignature {return x + 3};


somelongsignature testfunc0 = &examplefunc0;
somelongsignature testfunc1 = function(in int x){return x + 3;};
somelongsignature testfunc2 = function(x){return x + 15;};
somelongsignature testfunc3 = (in int x){return x + 20;};
somelongsignature testfunc4 = (x){return x + 25;};
somelongsignature testfunc5 = (x => x+30);
// probably more

You can't get rid of the signature completely as the functions 
still need a parameter list with x declared. You will get "Error: 
undefined identifier 'x'" otherwise. You can largely omit the 
*type* of x if it can be inferred from the signature, but you 
can't have its name be solely in the signature alias.


Parantheses are optional when calling functions without 
arguments. This is valid D:


void main() {
import std.stdio;
writeln;  // valid, no parantheses makes it writeln(), 
compare 'testfunc0 = examplefunc1/*()*/;'
writeln = "Hello world!";  // valid, looks funky but helps 
with properties


// auto doesntwork = writeln;  // invalid, writeln() returns 
void
// auto doesntworkeither = &writeln;  // invalid, writeln is 
a template


alias println = writeln;  // valid, aliases to templates work
println("Hello world again!");
println;
println(3.14);
}

So the original code was trying to assign testfunc0 the return 
value of a call to examplefunc1(), which doesn't exist. You want 
the function pointer instead.


Re: Using a macro for a function signature

2016-04-05 Thread pineapple via Digitalmars-d-learn
Ah, aside from the mismatched "examplefunc" numbers - please 
disregard


Can't post example code without stupid typos for the life of me


Using a macro for a function signature

2016-04-05 Thread pineapple via Digitalmars-d-learn
If I have a common function signature I'm using throughout my 
code, and I feel like there should be a way to condense it using 
a macro. The intuitive method isn't working, but this seems like 
something D would be able to do. What've I got wrong in this 
example?




alias somelongsignature = int(in int x);

int examplefunc0(in int x){
return x * 2;
}

somelongsignature testfunc0 = examplefunc1;
somelongsignature testfunc1 = somelongsignature {return x + 3};

public void main(){
import std.stdio;
writeln(testfunc0(5)); // Should output 10
writeln(testfunc1(5)); // Should output 8
}



Thanks!


Re: Segmentation Fault on rt.tlsgc.init

2016-04-05 Thread Jacob Carlborg via Digitalmars-d-learn

On 2016-04-05 11:46, tcak wrote:

If I create many threads (starts, does a short work, and ends)
repeatedly (>10,000), at some point rt.tlsgc.init() gives
SEGMENTATION_FAULT.

It doesn't check whether malloc fails to allocate any memory, and I
cannot find the source code of "rt.sections.initTLSRanges()" anywhere.

Is it left there without a check purposefully?


rt.sections.initTLSRanges is available here for Linux and FreeBSD [1]. 
For other platforms there are similar files.


https://github.com/D-Programming-Language/druntime/blob/master/src/rt/sections_elf_shared.d#L145

--
/Jacob Carlborg


Re: Convert wchar* to wstring?

2016-04-05 Thread Thalamus via Digitalmars-d-learn

Thanks everyone! You've all been very helpful.




Re: PostgreSQL. Unknown parameter of configuration : "autocommit"

2016-04-05 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 10:30:58 UTC, Suliman wrote:

http://www.symmetricds.org/issues/view.php?id=2439


http://www.postgresql.org/docs/9.5/static/ecpg-sql-set-autocommit.html - 
doesn't look deprecated or anything.


Re: Convert wchar* to wstring?

2016-04-05 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 01:21:55 UTC, Thalamus wrote:
I am invoking an entry point in a D DLL from C# (via extern 
(C)), and one of the parameters is a string. This works just 
fine for ANSI, but I'm having trouble with the Unicode 
equivalent.


When the message parameter is wchar*, wstring info = 
to!wstring(message) populates the string with the _address_ of 
the wchar*. So when message was in the debugger as 
0x035370e8 L"Writing Exhaustive unit tests is 
exhausting.", the wstring info variable ended up as {length=7 
ptr=0x1c174a20 L"35370E8" }. The dstring*/wchar_t* 
version had equivalent results.


Strings passed from C# are pinned, but temporary. You probably 
want to receive them as immutable (StringBuilder is for mutable 
string buffers), it's also easier to just pass the string length 
from C# side:

C#:
[DllImport(...)]
extern void dfunc(string s, int len);
dfunc(s, s.Length);
D:
extern(C) void dfunc(immutable(wchar)* s, int len)
{
  wstring ws = s[0..len];
}

Since the string is temporary, you'll have to idup it if you want 
to retain it after the call finishes.


Re: Convert wchar* to wstring?

2016-04-05 Thread Mike Parker via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 07:10:50 UTC, tsbockman wrote:


You can also combine both steps into a one-liner:

wstring wstr = cw[0 .. cw_len].idup;


This should do the trick, too:

import std.conv : to;
auto wstr = to!wstring(cw);


Re: PostgreSQL. Unknown parameter of configuration : "autocommit"

2016-04-05 Thread Suliman via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 07:53:20 UTC, Suliman wrote:
Is there anybody who have success connect to PostgreSQL with 
ddbc?


I am getting next error: 
https://github.com/buggins/ddbc/issues/22


Look like driver do not support PG 9.5

http://www.symmetricds.org/issues/view.php?id=2439


Segmentation Fault on rt.tlsgc.init

2016-04-05 Thread tcak via Digitalmars-d-learn
If I create many threads (starts, does a short work, and ends) 
repeatedly (>10,000), at some point rt.tlsgc.init() gives 
SEGMENTATION_FAULT.


It doesn't check whether malloc fails to allocate any memory, and 
I cannot find the source code of "rt.sections.initTLSRanges()" 
anywhere.


Is it left there without a check purposefully?


Re: Convert wchar* to wstring?

2016-04-05 Thread Rene Zwanenburg via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 01:21:55 UTC, Thalamus wrote:
I'm sorry for this total newbie question, but for some reason 
this is eluding me. I must be overlooking something obvious, 
but I haven't been able to figure this out and haven't found 
anything helpful.


In case you haven't done so already, you'll also have to use 
CharSet = CharSet.Unicode in the DllImport attribute.


PostgreSQL. Unknown parameter of configuration : "autocommit"

2016-04-05 Thread Suliman via Digitalmars-d-learn

Is there anybody who have success connect to PostgreSQL with ddbc?

I am getting next error: https://github.com/buggins/ddbc/issues/22


Re: Convert wchar* to wstring?

2016-04-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 01:21:55 UTC, Thalamus wrote:
I'm sorry for this total newbie question, but for some reason 
this is eluding me. [...]


You've been given the right answer by the other participants but 
I'd like to share this simple helper range from my user lib:


auto nullTerminated(C)(C c)
if (isPointer!C && isSomeChar!(PointerTarget!(C)))
{
struct NullTerminated(C)
{
private C _front;
///
this(C c)
{
_front = c;
}
///
@property bool empty()
{
return *_front == 0;
}
///
auto front()
{
return *_front;
}
///
void popFront()
{
++_front;
}
///
C save()
{
return _front;
}
}
return NullTerminated!C(c);
}

The idea is to get rid of the conversion and to process directly 
the pointer in all phobos function.


Re: Convert wchar* to wstring?

2016-04-05 Thread tsbockman via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 01:21:55 UTC, Thalamus wrote:
When the message parameter is wchar*, wstring info = 
to!wstring(message) populates the string with the _address_ of 
the wchar*. So when message was in the debugger as 
0x035370e8 L"Writing Exhaustive unit tests is 
exhausting.", the wstring info variable ended up as {length=7 
ptr=0x1c174a20 L"35370E8" }.


`wchar*` is a raw pointer. D APIs generally expect a dynamic 
array - also known as a "slice" - which packs the pointer 
together with an explicit `length` field. You can easily get a 
slice from a pointer using D's convenient slicing syntax:

https://dlang.org/spec/arrays.html#slicing

wchar* cw;
size_t cw_len; // be sure to use the right length, or you'll 
suffer buffer overruns.


wchar[] dw = cw[0 .. cw_len];

Slicing is extremely fast, because it does not allocate any new 
heap memory: `dw` is still pointing to the same chunk of memory 
as cw. D APIs that work with text will often accept a mutable 
character array like `dw` without issue.


However, `wstring` in D is an alias for `immutable(wchar[])`. In 
the example above, `dw` cannot be immutable because it is reusing 
the same mutable memory chunk as `cw`. If the D code you want to 
interface with requires a real `wstring`, you'll need to copy the 
text into a new immutable memory chunk:


wstring wstr = dw.idup; // idup is short for "immutable 
duplicate"


`idup` will allocate heap memory, so if you care about 
performance and memory usage, don't use it unless you actually 
need it.


You can also combine both steps into a one-liner:

wstring wstr = cw[0 .. cw_len].idup;