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
Thanks.
The problem is that if we tag _aaApply2 as nothrow, then can we still
put throwable codes in the body of foreach?
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.
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
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 this
Thanks. Removing the ';' after struct and class is really helpful. The
; keeps trapping me in C++ coding. :)
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?
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.
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?
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,
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 must be a
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
Is there any usable profiler for D2?
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.
#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.
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 this a bug?
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.
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 to
Sorry, the 'for' should be 'foreach'.
19 matches
Mail list logo