Re: Referencing an overloaded function

2012-03-24 Thread Mantis
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

Re: Capturing caller's file/line number in variadic template functions

2012-03-16 Thread Mantis
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) {

Re: Capturing caller's file/line number in variadic template functions

2012-03-16 Thread Mantis
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

Re: How to avoid code duplication in static if branches?

2012-03-03 Thread Mantis
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))

Re: Cannot cast void* to arrays..?

2012-02-24 Thread Mantis
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

Re: interface final members

2012-02-21 Thread Mantis
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 }

Re: delegate as memeber

2012-02-21 Thread Mantis
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

Re: Mixins: Using the type name to generate a method name

2012-02-21 Thread Mantis
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.

Re: Flushing denormals to zero

2012-02-17 Thread Mantis
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

Re: Range question

2012-02-17 Thread Mantis
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.

Re: Range question

2012-02-17 Thread Mantis
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

Re: i18n

2012-02-03 Thread Mantis
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

Re: Chained Catch Statements

2012-01-30 Thread Mantis
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

Re: KeyType, ValueType traits for hashes

2012-01-24 Thread Mantis
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

Re: KeyType, ValueType traits for hashes

2012-01-24 Thread Mantis
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

Re: char* to long

2012-01-24 Thread Mantis
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:

Re: for loop

2012-01-23 Thread Mantis
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

Re: Exceptions documentation

2012-01-17 Thread Mail Mantis
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

Re: floating point precision

2012-01-11 Thread Mail Mantis
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