24.03.2012 14:13, John написал:
Is there any way to refer to a specific function overload?
For example:
import std.stdio;
import std.traits;
void foo() {}
void foo(int x) {}
void main() {
writeln(foo.mangleof);
writeln(ParameterTypeTuple!(foo).stringof);
}
Both of these statements
16.03.2012 20:23, H. S. Teoh пишет:
I'm writing some unittests with very repetitive tests for a myriad of
different types, so I wrote a helper function:
version(unittest) {
void checkConsistency(T...)(T args) {
foreach (a; args) {
16.03.2012 20:35, H. S. Teoh пишет:
[...]
Actually, I found the solution: the compiler understands __FILE__ and
__LINE__ in compile-time arguments too, so this works: void
checkConsistency(string file=__FILE__, size_t line=__LINE__, T...)(T
args) { ... } It's a bit painful with the assert
04.03.2012 3:42, Andrej Mitrovic пишет:
[...code...]
I want to avoid writing check() twice. I only have to statically
check a field of a member if it's of a certain type (Foo).
One solution would be to use a boolean:
void test(T)(T t)
{
bool isTrue = true;
static if (is(T == Foo))
24.02.2012 21:34, simendsjo пишет:
char[] a;
auto b = cast(void*)a;
auto c = cast(char[])b; // Error: e2ir: cannot cast b of type
void* to type char[]
Generally, you should not cast a struct to pointer and vise-versa.
Besides, size of array structure is larger than size of
21.02.2012 14:46, Joshua Reusch пишет:
interface I {
final int foo(I other, int a, int b) {
return other.foo(a,b) + a*b;
}
int foo(int a, int b);
}
class A : I {
int foo(int a, int b) {
return a*b;
}
}
void main() {
A a = new A;
a.foo(5,5);
a.I.foo(a, 5,5);
a.foo(a, 5,5); //line 22
}
21.02.2012 17:24, deadalnix пишет:
struct stuff {
private Exception delegate() exceptionBuilder = delegate Exception() {
return new Exception(foobar);
};
}
The following piece of code trigger a compiler error : delegate
module.stuff.__dgliteral1 function literals cannot be class members
Why
21.02.2012 21:42, Robert Rouse пишет:
...
mixin(alias _method ~ toLower(typeid(T)) ~ ; );
...
Try
typeid(T).toString();
or
typeof(T).stringof;
typeid does not return a string type.
17.02.2012 4:30, bearophile пишет:
After seeing this interesting thread:
http://stackoverflow.com/questions/9314534/why-does-changing-0-1f-to-0-slow-down-performance-by-10x
Do you know if there's a simple way to perform _MM_SET_FLUSH_ZERO_MODE in D?
According to Agner that operation is not
18.02.2012 2:50, H. S. Teoh пишет:
...
You cannot have ref local variable, so e is a copy in any case. It may
be a class reference or a pointer, so calling potentially non-const
methods is probably not safe here, but assignment shouldn't give you
problems.
18.02.2012 7:51, H. S. Teoh пишет:
On Sat, Feb 18, 2012 at 05:19:52AM +0200, Mantis wrote:
18.02.2012 2:50, H. S. Teoh пишет:
...
You cannot have ref local variable, so e is a copy in any case. It
may be a class reference or a pointer, so calling potentially
non-const methods is probably
03.02.2012 22:03, xancorreu пишет:
Al 03/02/12 18:07, En/na Trass3r ha escrit:
I deduce so that there is no official support for that. If it's,
it's a pain.
Pain? Writing such a system can be done in a couple of lines.
How? I don't know how to do that. How to read user current locale?
An
30.01.2012 16:37, Jared пишет:
However, this doesn't seem to be possible in D.
Why not?
import std.stdio;
class Exception1 : Throwable { this( string s ) { super( s ); } }
class Exception2 : Throwable { this( string s ) { super( s ); } }
void foo() {
throw new Exception1( foo );
}
void
24.01.2012 8:43, Andrej Mitrovic пишет:
But I did implement them poorly, this is better:
import std.traits;
template KeyType(AA)
if (isAssociativeArray!AA)
{
static if (is(AA V : V[K], K))
{
alias K KeyType;
}
}
template ValueType(AA)
if
24.01.2012 20:49, bearophile пишет:
Mantis:
Of course, most likely that user already did type check, but if not,
this will give less cryptic error:
Error: static assert Not associative array: int
instantiated from here: KeyType!(int)
, instead of:
Error: template instance KeyType!(int
24.01.2012 22:48, Mars пишет:
Hello everybody.
I have to convert a char* (from a C function) to long. At the moment
I'm using
long foo = to!long( to!string(bar) );
but this doesn't feel right... with 2 to calls. Is this the way to go?
Or is there something better?
Mars
This seems to work:
23.01.2012 20:06, bearophile пишет:
Ellery Newcomer:
void main(){
for ({int x=0; short y=0;} x 10; x++, y++){
}
}
I don't understand, is that a compiler bug?
Aren't x and y in a sub-scope that ends before you use x and y?
Bye,
bearophile
According to specs, this is
2012/1/17 simendsjo simend...@gmail.com:
Where is documentation on exceptions located?
Not here http://www.d-programming-language.org/exception-safe.html
or here http://www.d-programming-language.org/errors.html
or here http://www.d-programming-language.org/phobos/std_exception.html
Do I
All is passed, to print, say, 50 signs after period use following:
writefln(%.50f, var);
2012/1/12 dsmith dsm...@nomail.com:
How do you increase floating point precision beyond the default of 6?
example:
double var = exp(-1.987654321123456789);
writeln(var);
-- 0.137016
Assuming this
19 matches
Mail list logo