Re: mixin template can't contain statements: workaround?

2015-03-15 Thread ketmar via Digitalmars-d-learn
On Sun, 15 Mar 2015 13:28:33 +, ketmar wrote: template Foo(int a, string b) { import std.format : format; enum Foo = q{ { import std.conv : to; return %2$s+to!string(%1$s); } }.format(a, b.stringof); } positional args, syntax highlighting, usage like

Re: mixin template can't contain statements: workaround?

2015-03-15 Thread ketmar via Digitalmars-d-learn
On Sat, 14 Mar 2015 18:20:47 -0700, Timothee Cour via Digitalmars-d-learn wrote: Why can't we allow mixin templates to contain statements, as is the case for regular mixins? Is there a workaround? here's a dummy example: template mixin Foo{ //some statement, eg: 'return;' } void

Re: Using std.format required std.string?

2015-03-15 Thread via Digitalmars-d-learn
On Sunday, 15 March 2015 at 15:48:34 UTC, Robert M. Münch wrote: Hi, wondering why this happens: import std.format; void ods(T...)(auto ref T args){ format(args).ptr; return; } ods(%s @ %s, mystring, mystring.ptr); Error: undefined identifier format If I add: import std.string;

Re: Garbage collector returning pointers

2015-03-15 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-03-14 20:45:21 +, Marc Schütz said: As long as the pointer remains on the stack or in a register, the GC will keep the allocation alive. Hi Marc, ok, got it. Thanks. But if your C code stores the pointer on the C heap or in a global, the GC won't know anything about it and can

Using std.format required std.string?

2015-03-15 Thread Robert M. Münch via Digitalmars-d-learn
Hi, wondering why this happens: import std.format; void ods(T...)(auto ref T args){ format(args).ptr; return; } ods(%s @ %s, mystring, mystring.ptr); Error: undefined identifier format If I add: import std.string; everything compiles and works. Since the docs of std.format contains all

Testing implicit conversion to template instance with is() expression

2015-03-15 Thread via Digitalmars-d-learn
Should this work? struct V(string s) { } struct S(int U) { V!xyz x; alias x this; } void main() { S!10 a; static assert(is(a : V!Args, Args...)); } With DMD Git master, the static assert() fails. Should it? Am I doing something wrong?

Re: Garbage collector returning pointers

2015-03-15 Thread via Digitalmars-d-learn
On Sunday, 15 March 2015 at 15:08:43 UTC, Robert M. Münch wrote: On 2015-03-14 20:45:21 +, Marc Schütz said: As long as the pointer remains on the stack or in a register, the GC will keep the allocation alive. Hi Marc, ok, got it. Thanks. But if your C code stores the pointer on the C

Re: Dlang seems like java now,but why not let d more like C# Style?

2015-03-15 Thread Idan Arye via Digitalmars-d-learn
On Sunday, 15 March 2015 at 00:56:24 UTC, Ellery Newcomer wrote: On Saturday, 14 March 2015 at 23:57:33 UTC, weaselcat wrote: On Saturday, 14 March 2015 at 23:46:28 UTC, Ellery Newcomer wrote: And C# has LINQ, which when combined with the last point is fricken awesome. what does LINQ offer

Re: Formatting floats and ints

2015-03-15 Thread via Digitalmars-d-learn
On Sunday, 15 March 2015 at 15:41:09 UTC, Darts wrote: Hey, I'm just looking for how to turn some numbers into strings in particualr ways. Specifically, I want to force some ints (and maybe floats too) to give me a string that consists of exactly four numbers ( 3005, 0038, 0130, etc ). I'd

Formatting floats and ints

2015-03-15 Thread Darts via Digitalmars-d-learn
Hey, I'm just looking for how to turn some numbers into strings in particualr ways. Specifically, I want to force some ints (and maybe floats too) to give me a string that consists of exactly four numbers ( 3005, 0038, 0130, etc ). I'd also like to know how to format a float to give me only

Re: Dlang seems like java now,but why not let d more like C# Style?

2015-03-15 Thread Idan Arye via Digitalmars-d-learn
On Saturday, 14 March 2015 at 09:59:05 UTC, dnewer wrote: yes,java is good lang,but i dont think it's better than c#,if no oracle or google support java will less and less. C# is a good and easy lang. i like C# . but,C# cant compiled to native code. So far, I have been searching for a

Re: OutputDebugString()

2015-03-15 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-03-14 22:55:57 +, Jonathan M Davis via Digitalmars-d-learn said: In case you didn't know, if you're not running the program in visual studio, you should see the output in in DebugView: https://technet.microsoft.com/en-us/library/bb896647.aspx Hi, yes I know, nevertheless thanks

Re: Using std.format required std.string?

2015-03-15 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-03-15 17:36:24 +, Robert M. Münch said: Is there a way to use version(...) to have code sections depending on compiler version? Something like: version(dmd = 2.067) or version(dmd 2.067)? Answerting myself: static if (__traits(compiles, version_minor 67)) import std.string;

What is: Orphan format arguments: args[0..1]

2015-03-15 Thread Charles Hixson via Digitalmars-d-learn
What is: Orphan format arguments: args[0..1] It appears to come from within unittest at the line: strings={0}.format(cast(int)d2[i]); d2 is: ubyted2[]; It should be 512 bytes long, but that hasn't been checked at the point of the error. The compilation used was: rdmd

Re: Using std.format required std.string?

2015-03-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 March 2015 at 18:03:55 UTC, Robert M. Münch wrote: On 2015-03-15 17:36:24 +, Robert M. Münch said: Is there a way to use version(...) to have code sections depending on compiler version? Something like: version(dmd = 2.067) or version(dmd 2.067)? Answerting myself:

Re: Testing implicit conversion to template instance with is() expression

2015-03-15 Thread Ali Çehreli via Digitalmars-d-learn
On 03/15/2015 08:47 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: Should this work? struct V(string s) { } struct S(int U) { V!xyz x; alias x this; } void main() { S!10 a; static assert(is(a : V!Args,

Re: Testing implicit conversion to template instance with is() expression

2015-03-15 Thread via Digitalmars-d-learn
On Sunday, 15 March 2015 at 16:44:14 UTC, Ali Çehreli wrote: On 03/15/2015 08:47 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: Should this work? struct V(string s) { } struct S(int U) { V!xyz x; alias x this; } void main() {

Re: Testing implicit conversion to template instance with is() expression

2015-03-15 Thread via Digitalmars-d-learn
https://issues.dlang.org/show_bug.cgi?id=14286 In the meantime, does someone know of a suitable workaround?

Re: Dlang seems like java now,but why not let d more like C# Style?

2015-03-15 Thread dnewer via Digitalmars-d-learn
On Sunday, 15 March 2015 at 14:58:54 UTC, Idan Arye wrote: On Sunday, 15 March 2015 at 00:56:24 UTC, Ellery Newcomer wrote: On Saturday, 14 March 2015 at 23:57:33 UTC, weaselcat wrote: On Saturday, 14 March 2015 at 23:46:28 UTC, Ellery Newcomer wrote: And C# has LINQ, which when combined with

Re: Testing implicit conversion to template instance with is() expression

2015-03-15 Thread via Digitalmars-d-learn
On Sunday, 15 March 2015 at 16:53:34 UTC, Marc Schütz wrote: On Sunday, 15 March 2015 at 16:44:14 UTC, Ali Çehreli wrote: On 03/15/2015 08:47 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: Should this work? struct V(string s) { } struct S(int U) { V!xyz

Re: Testing implicit conversion to template instance with is() expression

2015-03-15 Thread via Digitalmars-d-learn
On Sunday, 15 March 2015 at 18:53:33 UTC, Nicolas Sicard wrote: Can be reduced to: struct Foo(int i) {} alias Foo1 = Foo!1; static assert(is(Foo!2 == Foo1!T, T...)); // OK I think it's another bug. Right, I've filed another report: https://issues.dlang.org/show_bug.cgi?id=14290

Re: Formatting floats and ints

2015-03-15 Thread Darts via Digitalmars-d-learn
Thanks! That works perfectly! ;) I'll remember they're called Format Strings now. Tangentially related follow up: if I want to cast a string to a dstring... what are the rules for that? I'm getting an object.Error@(0): array cast misalignment message when my program crashes tring to convert

Re: Using std.format required std.string?

2015-03-15 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-03-15 16:22:03 +, Marc Schütz said: For whatever reasons, format() used to be defined in std.string. Indeed it's unintuitive to have it there, and it also pulls in lots of other unrelated things like Unicode tables when you import std.string. That's why it was moved into

Re: Dlang seems like java now,but why not let d more like C# Style?

2015-03-15 Thread Kagamin via Digitalmars-d-learn
On Saturday, 14 March 2015 at 09:59:05 UTC, dnewer wrote: yes,java is good lang,but i dont think it's better than c#,if no oracle or google support java will less and less. C# is a good and easy lang. i like C# . Not sure what do you mean. D has classes, interfaces and foreach, that should

Re: Formatting floats and ints

2015-03-15 Thread via Digitalmars-d-learn
On Sunday, 15 March 2015 at 18:52:29 UTC, Marc Schütz wrote: On Sunday, 15 March 2015 at 17:11:07 UTC, Darts wrote: Thanks! That works perfectly! ;) I'll remember they're called Format Strings now. Tangentially related follow up: if I want to cast a string to a dstring... what are the rules

Re: Testing implicit conversion to template instance with is() expression

2015-03-15 Thread via Digitalmars-d-learn
On Sunday, 15 March 2015 at 17:03:42 UTC, Marc Schütz wrote: https://issues.dlang.org/show_bug.cgi?id=14286 In the meantime, does someone know of a suitable workaround? I found the following workaround. Not beautiful, but it works: enum isValue(alias T) = __traits(compiles, typeof(T));

Re: Dlang seems like java now,but why not let d more like C# Style?

2015-03-15 Thread Kagamin via Digitalmars-d-learn
On Sunday, 15 March 2015 at 14:58:54 UTC, Idan Arye wrote: Here is a very crude, very basic example: http://dpaste.dzfl.pl/94d851d7ca63. U++ approach will probably give more succinct result. Not sure how it fares against D philosophy: does it replace range primitives with whole new thing?

Re: Testing implicit conversion to template instance with is() expression

2015-03-15 Thread Nicolas Sicard via Digitalmars-d-learn
On Sunday, 15 March 2015 at 18:33:32 UTC, Marc Schütz wrote: On Sunday, 15 March 2015 at 17:03:42 UTC, Marc Schütz wrote: https://issues.dlang.org/show_bug.cgi?id=14286 In the meantime, does someone know of a suitable workaround? I found the following workaround. Not beautiful, but it works:

Re: Formatting floats and ints

2015-03-15 Thread via Digitalmars-d-learn
On Sunday, 15 March 2015 at 17:11:07 UTC, Darts wrote: Thanks! That works perfectly! ;) I'll remember they're called Format Strings now. Tangentially related follow up: if I want to cast a string to a dstring... what are the rules for that? I'm getting an object.Error@(0): array cast

Re: What is: Orphan format arguments: args[0..1]

2015-03-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 March 2015 at 18:46:52 UTC, Charles Hixson wrote: What is: Orphan format arguments: args[0..1] It appears to come from within unittest at the line: strings={0}.format(cast(int)d2[i]); It means you gave `format` more arguments than placeholders. `format` uses C style

What is the best practice of organization multi-threading ?

2015-03-15 Thread Suliman via Digitalmars-d-learn
I have App that read config sections. If the section is true I want to run it in new thread. if (parseconfig.obsmpplots_load == true) { auto obsmpplots = new ObsmpPlots(db); auto theTask = task(obsmpplots.getPlots);

Re: get from tuple by type

2015-03-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 March 2015 at 23:13:58 UTC, Charles Cooper wrote: And yes, I could use names. But then you are subject to name clashes and using strings instead of types as member identifiers is more prone to error anyways. Ever gotten this wrong before -- void CRITICAL_TO_GET_THIS_RIGHT(uint

Re: struct / cast / ? design problem

2015-03-15 Thread ketmar via Digitalmars-d-learn
On Sun, 15 Mar 2015 16:34:14 -0700, Charles Hixson via Digitalmars-d-learn wrote: if you know the exact layouts of `spare`, you can use union for that: struct S { // ... union { ulong[61] spare; struct { int vala; ubyte valb; } // etc. } } and then you can use it like this:

Re: get from tuple by type

2015-03-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 March 2015 at 21:59:18 UTC, Charles Cooper wrote: C++14 has: templateclass T, class... Types constexpr T get(tupleTypes... t); Which allows you to get a member of the tuple struct by type. Is there an idiomatic / library way to do this in D? Preferably by indexing. I don't

Re: get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
foo[1] is sometimes better, but not always. One has to go back to the definition of the thing and literally calculate by hand which element of the tuple you want, and then try compiling it, and so forth. Although the type system will guarantee that you eventually get it right it is a waste of

struct / cast / ? design problem

2015-03-15 Thread Charles Hixson via Digitalmars-d-learn
I've got, say, a file header in a routine that looks like: structBlockHead { uintmagic=20150312;//block magic uintmagic2;//magic for use by the using routine uintblockSize; uintunused1; ulongunused2;

Re: get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
Not offended at all :), in fact it was not even my suggestion that it be included in the standard. I was just knee jerk reacting to the comment that, just because something is simple to do precludes it from getting standardized On Sunday, 15 March 2015 at 23:28:18 UTC, ketmar wrote: sorry

Re: get from tuple by type

2015-03-15 Thread bearophile via Digitalmars-d-learn
Charles Cooper: Yes, I could say external_api1_react_to_event(event_t[1], event_t[0]) .. but that is barbaric. It's a productivity sink because I have to go back to the original definition, align the arguments, and then context switch back to whatever I was working on before. If you are

get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
C++14 has: templateclass T, class... Types constexpr T get(tupleTypes... t); Which allows you to get a member of the tuple struct by type. Is there an idiomatic / library way to do this in D? Preferably by indexing. Here is what I have, it is ugly but works: /* CODE */ static import

Re: get from tuple by type

2015-03-15 Thread ketmar via Digitalmars-d-learn
On Sun, 15 Mar 2015 22:35:03 +, weaselcat wrote: Seems like a useful feature(useful enough to get past the C++ standards committee,) consider submitting a phobos PR? ah, c++ committee accepts by randomness. ;-) honestly, i can't see why it's useful and where it can be used. and it's so

Re: get from tuple by type

2015-03-15 Thread ketmar via Digitalmars-d-learn
p.s. to be clear: it's freaking hard to do metaprogramming and template functional programming in c++, that's why c++ committee accepts such things. and it's very easy to write such code in D, so this is a good excersise for newcomers and almost no-brainer for expirienced D user. signature.asc

Re: get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
Thanks for the style recommendations. On Sunday, 15 March 2015 at 23:14:32 UTC, anonymous wrote: I don't think there is. I don't know if there should be. Distinguishing tuple fields by their type doesn't seem very useful to me, since multiple fields can have the same type. Using combined

Re: get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
Sure. It is also easy to write merge sort. Or std.typetuple.Erase. Or Tuple.opIndex(size_t). But that doesn't mean everybody does it. Some utilities (and I am not saying this is, but it could be) are widely used enough that it makes sense to put them in the standard. On Sunday, 15 March 2015

Re: get from tuple by type

2015-03-15 Thread ketmar via Digitalmars-d-learn
On Sun, 15 Mar 2015 23:30:48 +, Charles Cooper wrote: Not offended at all :), in fact it was not even my suggestion that it be included in the standard. I was just knee jerk reacting to the comment that, just because something is simple to do precludes it from getting standardized ah, i

Re: get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
http://dlang.org/phobos/std_variant.html#.Algebraic Thanks! This is fascinating, really a breath of fresh air coming from the C++ way of doing things. On Sunday, 15 March 2015 at 23:31:59 UTC, bearophile wrote: If you are experiencing those problems it's probably the way D/Phobos to tell you

Re: get from tuple by type

2015-03-15 Thread ketmar via Digitalmars-d-learn
On Sun, 15 Mar 2015 21:59:16 +, Charles Cooper wrote: C++14 has: templateclass T, class... Types constexpr T get(tupleTypes... t); Which allows you to get a member of the tuple struct by type. Is there an idiomatic / library way to do this in D? Preferably by indexing. why indexing?

Re: get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
True. If I had to do something involving such an API I would first wrap the API with a type safe one before doing anything else. void external_api_do_something(uint dollars, uint cents); /* I think this could somehow be automated with staticMap and ParameterTypeTuple /

Re: get from tuple by type

2015-03-15 Thread ketmar via Digitalmars-d-learn
On Sun, 15 Mar 2015 23:17:34 +, Charles Cooper wrote: Sure. It is also easy to write merge sort. Or std.typetuple.Erase. Or Tuple.opIndex(size_t). But that doesn't mean everybody does it. Some utilities (and I am not saying this is, but it could be) are widely used enough that it makes

Re: Using std.format required std.string?

2015-03-15 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 15 March 2015 at 17:36:24 UTC, Robert M. Münch wrote: Ok, good to here. Didn't cath/remember this one. Is there a way to use version(...) to have code sections depending on compiler version? Something like: version(dmd = 2.067) or version(dmd 2.067)? static if( __VERSION__ =

Re: Using std.format required std.string?

2015-03-15 Thread Mike Parker via Digitalmars-d-learn
On Monday, 16 March 2015 at 04:31:19 UTC, Mike Parker wrote: On Sunday, 15 March 2015 at 17:36:24 UTC, Robert M. Münch wrote: Ok, good to here. Didn't cath/remember this one. Is there a way to use version(...) to have code sections depending on compiler version? Something like:

exclude current directory from search path in dmd ?

2015-03-15 Thread Timothee Cour via Digitalmars-d-learn
Is there a way to exclude current directory from search path in dmd, so that the search path is only given by '-I' arguments (+ones from dmd.conf)? use case: files: /base/foo.d /base/bar/foo.d /base/bar/main.d #contains: import foo.d cd /base/bar dmd -I/base main.d = I want 'import foo.d' to