Re: Nested struct member has no access to the enclosing class data

2012-08-07 Thread RivenTheMage
On Monday, 6 August 2012 at 23:42:45 UTC, Era Scarecrow wrote: On Monday, 6 August 2012 at 22:28:40 UTC, RivenTheMage wrote: On Monday, 6 August 2012 at 21:51:24 UTC, Andrej Mitrovic wrote: There is no "outer". A nested struct has the same access as a nested static class, meaning no access to

Why __traits(compile,...) fails here?

2012-08-07 Thread Zhenya
import std.stdio; template isType(alias s) { enum isType = !__traits(compiles,mixin("typeof(s)")); } void main() { // writeln(isType!int);// Error: template instance isType!(int) isType!(int) does not match template declaration isType(alias s) writeln(__traits(compiles,mixin("t

Re: Why __traits(compile,...) fails here?

2012-08-07 Thread David
Am 07.08.2012 09:51, schrieb Zhenya: import std.stdio; template isType(alias s) { enum isType = !__traits(compiles,mixin("typeof(s)")); } void main() { //writeln(isType!int);// Error: template instance isType!(int) isType!(int) does not match template declaration isType(alias s) w

Re: Why __traits(compile,...) fails here?

2012-08-07 Thread Artur Skawina
On 08/07/12 09:51, Zhenya wrote: > import std.stdio; > > template isType(alias s) > { > enum isType = !__traits(compiles,mixin("typeof(s)")); > } > > void main() > { > //writeln(isType!int);// Error: template instance isType!(int) > isType!(int) does not match template declaration isType

Re: Why __traits(compile,...) fails here?

2012-08-07 Thread Zhenya
On Tuesday, 7 August 2012 at 09:47:58 UTC, Artur Skawina wrote: On 08/07/12 09:51, Zhenya wrote: import std.stdio; template isType(alias s) { enum isType = !__traits(compiles,mixin("typeof(s)")); } void main() { //writeln(isType!int);// Error: template instance isType!(int) isType!(in

Is this a std.regex bug?

2012-08-07 Thread Andrea Fontana
dmd 2.060 64bit ubuntu: // Doesn't work: auto r = ctRegex!(r"/api/places/(id|related|search|count)\.(json|xml)", "g"); // Works: auto r = regex(r"/api/places/(id|related|search|count)\.(json|xml)", "g");

How to const-overload opEquals(R)(R rhs)?

2012-08-07 Thread Tobias Pankrath
Hey, let's say I have a simple struct and I want to give it an opEquals like this. struct Point { int x, y; bool opEquals(R)(R rhs) { return x == rhs.x && y == rhs.y; } } With this I can't call opEquals on const instances of Point, because dmd says bug.d(13): Error: function bug.P

Re: Why __traits(compile,...) fails here?

2012-08-07 Thread Philippe Sigaud
On Tue, Aug 7, 2012 at 12:42 PM, Zhenya wrote: >> Template alias parameters do not accept built-in types. The trick is: - A template type parameter (like (T)) recognizes types - A template alias parameter(like (alias a)) recognizes names, symbols. A built-in type is 'purely' a type. It's a key

Re: How to const-overload opEquals(R)(R rhs)?

2012-08-07 Thread David
Really? It compiles: http://dpaste.dzfl.pl/e0470f9a

Re: Is this a std.regex bug?

2012-08-07 Thread Dmitry Olshansky
On 07-Aug-12 16:06, Andrea Fontana wrote: dmd 2.060 64bit ubuntu: // Doesn't work: auto r = ctRegex!(r"/api/places/(id|related|search|count)\.(json|xml)", "g"); Could be. It is experimental and is known to have bugs. What is the exact problem statement? // Works: auto r = regex(r"/api/place

How to create TypeTuple/ExpressionTuple from tuple/tuples

2012-08-07 Thread Øivind
Given e.g. a function template void f(T ...)(T t) { writeln(t.length); } How can I call this function with an already-constructed tuple but pass the pule as an expressiontuple? auto v = tuple(1, 2, 3); f(v); In the case above, f will print 1 because 1 tuple is given to the function, but I

Re: How to create TypeTuple/ExpressionTuple from tuple/tuples

2012-08-07 Thread Andrej Mitrovic
On 8/7/12, "Øivind" wrote: > How can I call this function with an already-constructed tuple > but pass the pule as an expressiontuple? > > auto v = tuple(1, 2, 3); > f(v); Use the .expand property: f(v.expand)

Daemon Threads

2012-08-07 Thread David
I have a threaded connection: class ThreadedConnection : Connection { protected Thread _thread = null; @property Thread thread() { return _thread; } void run() { if(_thread is null) { _thread = new Thread(&(super.run)); _thread.isDaemon = true;

Re: How to create TypeTuple/ExpressionTuple from tuple/tuples

2012-08-07 Thread Øivind
On Tuesday, 7 August 2012 at 16:11:05 UTC, Andrej Mitrovic wrote: On 8/7/12, "Øivind" wrote: How can I call this function with an already-constructed tuple but pass the pule as an expressiontuple? auto v = tuple(1, 2, 3); f(v); Use the .expand property: f(v.expand) Works like a charm. Than

Re: How to const-overload opEquals(R)(R rhs)?

2012-08-07 Thread Ali Çehreli
On 08/07/2012 06:40 AM, Tobias Pankrath wrote: > bool opEquals(R)(R rhs) { return x == rhs.x && y == rhs.y; } > bool opEquals(R)(R rhs) const { return x == rhs.x && y == rhs.y; } I strongly recommend that only the const version should be defined. That would work on both mutable and immutable ob

Re: How to const-overload opEquals(R)(R rhs)?

2012-08-07 Thread Tobias Pankrath
On Tuesday, 7 August 2012 at 16:46:04 UTC, Ali Çehreli wrote: On 08/07/2012 06:40 AM, Tobias Pankrath wrote: > bool opEquals(R)(R rhs) { return x == rhs.x && y == rhs.y; } > bool opEquals(R)(R rhs) const { return x == rhs.x && y == rhs.y; } I strongly recommend that only the const version shoul

enum string

2012-08-07 Thread Namespace
[code] import std.regex; enum Token : string { Blank = r"\s+" } void main() { const string text = "Foo Bar"; // text.split(regex(Token.Blank)); // don't work const string blank = Token.Blank; text.split(regex(blank)); // work } [/code] Can me so

Re: enum string

2012-08-07 Thread Dmitry Olshansky
On 07-Aug-12 21:05, Namespace wrote: [code] import std.regex; enum Token : string { Blank = r"\s+" } void main() { const string text = "Foo Bar"; // text.split(regex(Token.Blank)); // don't work const string blank = Token.Blank; text.split(regex(blank)); // work } [/c

Re: How to create TypeTuple/ExpressionTuple from tuple/tuples

2012-08-07 Thread Andrej Mitrovic
On 8/7/12, "Øivind" wrote: > The last one then becomes f(v0.expand, v1.expand) Yeah. It's somewhat possible to use a helper function for multiple TypeTuples, but the problem is D functions cannot return language tuples (only TypeTuple from std.typecons which is what the tuple() call creates) so y

Re: Function that calculates in compile time when it can

2012-08-07 Thread Marco Leise
Am Mon, 06 Aug 2012 14:21:37 +0200 schrieb "Minas Mina" : > I want to write a fibonacci(n) function that calculates the > result. > a) if n is known at compile time, use a template > b) if not, use a normal function > > I know how to write a template version: > template fib(ulong n) > { >

Re: How to const-overload opEquals(R)(R rhs)?

2012-08-07 Thread Jonathan M Davis
On Tuesday, August 07, 2012 15:40:18 Tobias Pankrath wrote: > Hey, > > let's say I have a simple struct and I want to give it an > opEquals like this. > > struct Point > { > int x, y; > bool opEquals(R)(R rhs) { return x == rhs.x && y == rhs.y; } > } > > > With this I can't call opEquals on con

Re: enum string

2012-08-07 Thread Namespace
On Tuesday, 7 August 2012 at 17:14:03 UTC, Dmitry Olshansky wrote: On 07-Aug-12 21:05, Namespace wrote: [code] import std.regex; enum Token : string { Blank = r"\s+" } void main() { const string text = "Foo Bar"; // text.split(regex(Token.Blank)); // don't work const string b

Re: enum string

2012-08-07 Thread Jonathan M Davis
On Tuesday, August 07, 2012 21:14:00 Dmitry Olshansky wrote: > isSomeString!T regression? See enum & std.traits topic in d.D. > Seems like it will work again in 2.061... Yeah. In 2.060, std.traits doesn't treat enums as their base type for stuff like isSomeString and isIntegral, which is the prob

Re: How to create TypeTuple/ExpressionTuple from tuple/tuples

2012-08-07 Thread Philippe Sigaud
On Tue, Aug 7, 2012 at 7:35 PM, Andrej Mitrovic wrote: > Yeah. It's somewhat possible to use a helper function for multiple > TypeTuples, but the problem is D functions cannot return language > tuples (only TypeTuple from std.typecons which is what the tuple() > call creates) so you would always

Re: Daemon Threads

2012-08-07 Thread Sean Kelly
On Aug 7, 2012, at 9:36 AM, David wrote: > I have a threaded connection: > ... > Since this is a daemon thread, I'd expect it to stop/terminate when the main > thread stops. This is not the case (it keeps running), is this a known bug > and how can I workaround this? Daemon threads will keep r

ctRegex - named submatch

2012-08-07 Thread Daniel
Hi, I tried using named submatch for ctRegex... it works but seemingly only for maximum 1 named submatch... OK (\w changed to \S to avoid, out of memory) `(?P\S+)\s*=\s*(\d+);` `(?\S+)\s*=\s*(?P\d+);` NOT OK `(?P\w+)\s*=\s*(?P\d+);` Is this a known bug? I used the regex example from the Libr

Re: ctRegex - named submatch

2012-08-07 Thread Dmitry Olshansky
On 08-Aug-12 00:24, Daniel wrote: Hi, I tried using named submatch for ctRegex... it works but seemingly only for maximum 1 named submatch... Great! I never tried ;) Should just work though... OK (\w changed to \S to avoid, out of memory) `(?P\S+)\s*=\s*(\d+);` `(?\S+)\s*=\s*(?P\d+);` NOT O

Re: How to create TypeTuple/ExpressionTuple from tuple/tuples

2012-08-07 Thread Andrej Mitrovic
On 8/7/12, Philippe Sigaud wrote: > You can also take the 'dual' of your solution and have a template that > makes a function automatically expand tuples But that doesn't work for variadic templates, which is the OP's case: int foo(T...)(T t) { return 1; } alias expander!foo efoo; // error

Re: ctRegex - named submatch

2012-08-07 Thread Daniel
On Tuesday, 7 August 2012 at 20:51:28 UTC, Dmitry Olshansky wrote: Great! I never tried ;) Should just work though... hehe :) That all being said experimental tag on ctRegex in DDoc is here for a reason, and that is: ctRegex can't compile nor match full regex testsuite. Understood, thank

Re: DMD out of memory issues

2012-08-07 Thread Andrej Mitrovic
On 8/6/12, Andrej Mitrovic wrote: > Unfortunately anything big won't work because I get out of memory errors when > compiling the > D wrapper. It doesn't seem to be caused by any infinite loops, DMD just simply runs out of memory. I've enabled some printf's and created a log file: dmd -v -c _en

Re: Daemon Threads

2012-08-07 Thread David
Daemon threads will keep running until the process terminates.Forcibly halting them any earlier risks leaving mutexes they hold in a locked state, etc, which could break shutdown and hang the app. Typically, you'll want to have a shared module dtor communicate to any daemon threads that it's tim

Re: Daemon Threads

2012-08-07 Thread Alex Rønne Petersen
On 07-08-2012 21:38, Sean Kelly wrote: On Aug 7, 2012, at 9:36 AM, David wrote: I have a threaded connection: ... Since this is a daemon thread, I'd expect it to stop/terminate when the main thread stops. This is not the case (it keeps running), is this a known bug and how can I workaround t

thread exceptions

2012-08-07 Thread Martin Krejcirik
Hi, using std.concurrency, is it possible to print an exception if a thread throws (and the main thread is still running) ? It just terminates and prints nothing. I tried to catch it and send as a message to the main thread, but haven't succeeded so far. -- mk

Re: Error while trying to allocate memory (malloc)

2012-08-07 Thread Marco Leise
Am Mon, 6 Aug 2012 18:25:01 +0200 schrieb Andrej Mitrovic : > On 8/6/12, CrudOMatic wrote: > > another quick question - are these allocations automatically > > entered into the GC heap? If so then I can just disable garbage > > collection? > > No, there is the standard C malloc/free in std.c.std

Re: thread exceptions

2012-08-07 Thread Ali Çehreli
On 08/07/2012 06:25 PM, Martin Krejcirik wrote: > Hi, > > using std.concurrency, is it possible to print an exception if a thread > throws (and the main thread is still running) ? It just terminates and > prints nothing. I tried to catch it and send as a message to the main > thread, but haven't s

Re: How to create TypeTuple/ExpressionTuple from tuple/tuples

2012-08-07 Thread Philippe Sigaud
On Tue, Aug 7, 2012 at 11:31 PM, Andrej Mitrovic wrote: > On 8/7/12, Philippe Sigaud wrote: >> You can also take the 'dual' of your solution and have a template that >> makes a function automatically expand tuples > > But that doesn't work for variadic templates, which is the OP's case: > > int f

two-dimensional C array and its analog in D

2012-08-07 Thread Alexandr Druzhinin
Hello, there is the following C function: void foo(const void** data); in C I can do: int data[N][M]; data[0][0] = ..; data[0][1] = ..; data[1][0] = ..; data[1][1] = ..; foo(data); // for C code it works and in D code it doesn't (compile, but do nothing) I've "solved" the problem like this

Re: two-dimensional C array and its analog in D

2012-08-07 Thread Ali Çehreli
On 08/07/2012 11:07 PM, Alexandr Druzhinin wrote: > Hello, > there is the following C function: > > void foo(const void** data); > > in C I can do: > > int data[N][M]; > > data[0][0] = ..; > data[0][1] = ..; > data[1][0] = ..; > data[1][1] = ..; > > foo(data); // for C code it works and in D code

Re: Daemon Threads

2012-08-07 Thread Sean Kelly
On Aug 7, 2012, at 4:01 PM, David wrote: >> Daemon threads will keep running until the process terminates.Forcibly >> halting them any earlier risks leaving mutexes they hold in a > locked state, etc, which could break shutdown and hang the app. Typically, > you'll want to have a shared module

Re: Daemon Threads

2012-08-07 Thread Sean Kelly
On Aug 7, 2012, at 5:41 PM, Alex Rønne Petersen wrote: > On 07-08-2012 21:38, Sean Kelly wrote: >> On Aug 7, 2012, at 9:36 AM, David wrote: >> >>> I have a threaded connection: >>> ... >>> Since this is a daemon thread, I'd expect it to stop/terminate when the >>> main thread stops. This is no

Re: How to create TypeTuple/ExpressionTuple from tuple/tuples

2012-08-07 Thread Philippe Sigaud
On Wed, Aug 8, 2012 at 7:01 AM, Philippe Sigaud wrote: >> But that doesn't work for variadic templates, which is the OP's case: >> >> int foo(T...)(T t) { return 1; } >> alias expander!foo efoo; // error > > The template can easily be modified to deal with template functions, > but in that case,