Re: operator "~" does not check type?

2011-10-13 Thread Cheng Wei
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article > On Wed, 12 Oct 2011 09:46:57 -0400, Trass3r wrote: > >> I believe that the primary reasoning for allowing the implicit > >> conversion > >> between int and dchar is so that code like this > >> > >> dchar c = 'a' + 7; > > > > That

Re: Why foreach is not nothrow even for a simple associative array?

2011-10-13 Thread Cheng Wei
Yeah, the problem could be solved if _aaApply2 was a template instead of a function. Alternatively, maybe the compiler can skip the purity/throwbility check for __aaApply2 and directly check the statements inside. That means to treat the compiler generated function __aaApply2 differently than the

does "private import" means "static import" to other modules importing it?

2011-10-13 Thread Cheng Wei
suppose we have in module A, we have import B; Then in module C; import A; B.fun1(); B.fun2(); can be compiled successfully even without "static import B". Is this correct? Thanks.

Re: Why foreach is not nothrow even for a simple associative array?

2011-10-13 Thread Cheng Wei
Thanks. The problem is that if we tag _aaApply2 as nothrow, then can we still put throwable codes in the body of foreach?

Why foreach is not nothrow even for a simple associative array?

2011-10-13 Thread Cheng Wei
import std.c.stdio int[int] g_map; void main() { test(); } nothrow void test() { foreach(k, v) { printf("%d, %d\n", k, v); } } Cannot compile with the error: Error: _aaApply2 is not nothrow It is not so convenient that we have to use try-catch for all iteration even when we

operator "~" does not check type?

2011-10-12 Thread Cheng Wei
The following expression compiles but does not make sense. string str = "hello" ~ 10; assert(str == "hello\n"); Is this a useful feature or just a bug?

Re: compare struct with string member is wield;

2011-10-11 Thread Cheng Wei
Thanks. Removing the ';' after struct and class is really helpful. The ";" keeps trapping me in C++ coding. :)

Re: compare struct with string member is wield;

2011-10-11 Thread Cheng Wei
Sorry. The previous is not the one causes the problem. Try this: struct S { string str = "Hello"; // Adding an initial value here. }; S g_s; unittest { S s1; S s2; assert(s1 == s2); // Success assert(g_s == s1); // Fail auto s3 = g_s; assert(s3 == g_s);; // Even thi

compare struct with string member is wield;

2011-10-11 Thread Cheng Wei
struct S { string str; }; S g_s; unittest { S s1; S s2; assert(s1 == s2); // Success assert(g_s == s1);// Failed } Is this expected? If so, may I know the reason? Thanks.

Re: Why an abstract pointer cannot be used as value in an associate array?

2011-09-29 Thread Cheng Wei
Thanks a lot. This solves the problem. However, it breaks the abstractness. Now in D side, we can call auto v = ab(). This does not make sense, because then &v cannot be used in the C library. I don't understand why when we manipulate AB*, D compiler needs to know the size of struct ab. Moreover,

Re: Why an abstract pointer cannot be used as value in an associate array?

2011-09-29 Thread Cheng Wei
The problem is that the void* cannot convert back to AB* when we want to use it in c library. Just don't understand why the cast(AB*)p (p is void *) needs to know the size of AB. Is there any unsafe cast which can blindly cast the pointers?

Why an abstract pointer cannot be used as value in an associate array?

2011-09-28 Thread Cheng Wei
extern(C) { struct ab; } ab*[int] map; void main() { map.clear(); } Cannot be compiled. Why? Thanks.

why global immutable string variable cannot be used after "case"?

2011-09-23 Thread Cheng Wei
import std.stdio; immutable HELLO = "hello"; void main() { auto string = "hello"; switch(string) { case HELLO: writeln("hello"); break; default: writeln("unknown"); break; } } testCase.d(7): Error: case mus

Why this simple binaryHeap program does not compile?

2011-09-22 Thread Cheng Wei
import std.container; class T { int i; } void main() { auto array = Array!(T); auto heap = BinaryHeap!(Array!(T), "a.i < b.i")(array); } After compiling: dmd2/linux/bin32/../../src/phobos/std/container.d(1612): Error: template std.conv.emplace(T) if (!is(T == class)) does not match

Re: How to read output of a script

2011-09-20 Thread Cheng Wei
Thanks a lot. Weird. It is not in the library reference in http://www.d-programming- language.org/, but it is in the library reference in digitalmars.com. I throught the previous one was the official web site now. It seems it still is not synced well.

Is it a bug in execvb (std.process)?

2011-09-20 Thread Cheng Wei
import std.process; void main() { execvp("ip", ["route"]); } result: Object "ute" is unknown, try "ip help". So the first two bytes are lost. After adding two spaces in the first argument, it works. import std.process; void main() { execvp("ip", [" route"]); } dmd 2.055 linux 32bit. Is

Is this a bug in execvp of std.process

2011-09-20 Thread Cheng Wei
#import std.process void main() { execvp("ip", "route"); } result: Object "ute" is unknown, try "ip help". That is the first two bytes are lost Adding two spaces works: #import std.process void main() { execvp("ip", " route"); } Version 2.055, linux, 32bit Thanks.

How to read output of a script

2011-09-20 Thread Cheng Wei
In D2, how can we get the output of running a script. We can use 'system' to run the script, but how we cannot assign the standard output of the running script. Is there any way to do it, or whether it will be included into future version of std.process? Thanks a lot.

Is there a profiler for D2?

2011-09-19 Thread Cheng Wei
Is there any usable profiler for D2?

Re: How to filter an array so the result is an array again?

2011-09-15 Thread Cheng Wei
Sorry, the 'for' should be 'foreach'.

How to filter an array so the result is an array again?

2011-09-15 Thread Cheng Wei
The standard library std.algorithm is based on Range. So if a = [1, 2, 3, 4]; auto r = filter!("a < 2")(a); Here, r is a range. How about I want an new array? Is there any easy way to convert the result to array? If we have to do like: int[] b; for (v; r) { b ~= v; } Then maybe it is easier