Re: Postblit not invokable with MyStruct(MyStruct()); ?

2014-05-02 Thread Mark Isaacson via Digitalmars-d-learn
@bearophile - Unless I'm missing something, alas, no. Neither A nor B is a subtype of the other. In particular, in the real code one is a CartesianVector and the other a PolarVector. For what it's worth, 'foo' is actually opBinary addition. Thanks for the thought though.

Re: Postblit not invokable with MyStruct(MyStruct()); ?

2014-05-02 Thread bearophile via Digitalmars-d-learn
Mark Isaacson: Accordingly, I no longer need an answer to my second question unless someone knows of a more idiomatic way to get the same results. Is the "alias this" useful in this case? Bye, bearophile

Re: Postblit not invokable with MyStruct(MyStruct()); ?

2014-05-02 Thread Mark Isaacson via Digitalmars-d-learn
Did some thinking: Realized that the appropriate mechanism to express that A and B are two ways of representing the same thing is to do so via opCast. I had not considered this option carefully initially as I am translating someone else's C++ code to D and hoped that they had used the appropria

Postblit not invokable with MyStruct(MyStruct()); ?

2014-05-02 Thread Mark Isaacson via Digitalmars-d-learn
I have just discovered that the postblit constructor is not able to be invoked like a "normal" constructor, or, as one would manually do so in C++ with a copy constructor. Accordingly I have a couple questions: 1) What are the various ways to invoke the postblit constructor? I have not tested

Re: const ref parameters and r-value references

2014-05-02 Thread Meta via Digitalmars-d-learn
On Friday, 2 May 2014 at 21:29:51 UTC, Mark Isaacson wrote: Auto ref parameters seem to be just what I need. Thanks! I'd still be curious if anyone has additional information regarding the rationale at play (I'm spoiled, reading TDPL and having each decision explained in text). The C++ way wa

Math-Parser

2014-05-02 Thread Tim Holzschuh via Digitalmars-d-learn
Hi there, I currently try to write a simple math-parser in D. However.. something isn't working and I just can't figure out what's the problem. (I'm relative new to D, and this is my first test to write a parser/lexer) I'm pretty sure it's a simple layer-8-problem, but I always overlook it.

Re: const ref parameters and r-value references

2014-05-02 Thread Mark Isaacson via Digitalmars-d-learn
Auto ref parameters seem to be just what I need. Thanks! I'd still be curious if anyone has additional information regarding the rationale at play (I'm spoiled, reading TDPL and having each decision explained in text).

Re: why arithmetic for bytes different than for ints?

2014-05-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On Fri, 02 May 2014 16:32:54 -0400, Vlad Levenfeld wrote: Dunno why I didn't try it earlier, but splitting it across lines like y += 1; y %= 2; assert (y == 1); works. So, bug, then? Yes. -Steve

Re: why arithmetic for bytes different than for ints?

2014-05-02 Thread Vlad Levenfeld via Digitalmars-d-learn
Dunno why I didn't try it earlier, but splitting it across lines like y += 1; y %= 2; assert (y == 1); works. So, bug, then?

why arithmetic for bytes different than for ints?

2014-05-02 Thread Vlad Levenfeld via Digitalmars-d-learn
Can anyone explain to me why this test passes? I have read through the Types page on the dlang website and can't find anything that would explain this. Is it a bug or am I doing it wrong? uint x = 0; (x += 1) %= 2; assert (x == 1); ubyte y = 0; (y += 1)

Re: formattedWrite writes nothing

2014-05-02 Thread Jared Miller via Digitalmars-d-learn
I logged this bug a while ago: https://issues.dlang.org/show_bug.cgi?id=10291 On Friday, 2 May 2014 at 10:06:43 UTC, ref2401 wrote: Is it a bug or is there a reason for such behaviour?

Re: In need for CommonOriginalType

2014-05-02 Thread Nordlöw
is(CommonType!(OriginalType!T1, OriginalType!T2) ... ? I need it to be variadic. I cracked it: import std.typetuple: staticMap; import std.traits: CommonType, OriginalType; alias CommonOriginalType(T...) = CommonType!(staticMap!(OriginalType, T)); /per

Re: In need for CommonOriginalType

2014-05-02 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On 02/05/14 20:03, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: On 02/05/14 19:24, "Nordlöw" via Digitalmars-d-learn wrote: Do I have to use recursion (like in CommonType) to implement this or is there a better way? Won't it work to use, is(CommonType!(OriginalType!T1, OriginalTy

Re: In need for CommonOriginalType

2014-05-02 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On 02/05/14 19:24, "Nordlöw" via Digitalmars-d-learn wrote: Do I have to use recursion (like in CommonType) to implement this or is there a better way? Won't it work to use, is(CommonType!(OriginalType!T1, OriginalType!T2) ... ?

In need for CommonOriginalType

2014-05-02 Thread Nordlöw
In order to make https://github.com/nordlow/justd/blob/master/enums.d more type-safe (restrict type arguments to EnumUnion) I need a type trait, say, CommonOriginalType(E...) Do I have to use recursion (like in CommonType) to implement this or is there a better way? See also: http://forum

Re: Making enum join variadic

2014-05-02 Thread Nordlöw
artur Collision detection should now be complete. https://github.com/nordlow/justd/blob/master/enums.d Superb!

Re: Making enum join variadic

2014-05-02 Thread Artur Skawina via Digitalmars-d-learn
On 05/02/14 17:27, Meta via Digitalmars-d-learn wrote: > On Friday, 2 May 2014 at 15:18:06 UTC, Artur Skawina via Digitalmars-d-learn > wrote: >> On 05/02/14 15:38, "Nordlöw" via Digitalmars-d-learn wrote: >>> >>> template MemberNamesUnion(E...) if (allSatisfy!(isEnum, E)) >>> { >>> bool[strin

Re: Making enum join variadic

2014-05-02 Thread Meta via Digitalmars-d-learn
On Friday, 2 May 2014 at 15:18:06 UTC, Artur Skawina via Digitalmars-d-learn wrote: On 05/02/14 15:38, "Nordlöw" via Digitalmars-d-learn wrote: template MemberNamesUnion(E...) if (allSatisfy!(isEnum, E)) { bool[string] allMembers; // used to detect member collisions mixin({

Re: Reading ELF Files

2014-05-02 Thread Nordlöw
On Friday, 2 May 2014 at 10:42:40 UTC, yazd wrote: On Thursday, 1 May 2014 at 17:31:52 UTC, Nordlöw wrote: Here you go, https://github.com/yazd/elf-d. Thanks! Anytime. By the way, if you need more stuff out of it or help, post an issue on github. I think I'll be able to help a bit more. Bu

Re: Making enum join variadic

2014-05-02 Thread Artur Skawina via Digitalmars-d-learn
On 05/02/14 15:38, "Nordlöw" via Digitalmars-d-learn wrote: > > template MemberNamesUnion(E...) if (allSatisfy!(isEnum, E)) > { > bool[string] allMembers; // used to detect member collisions > mixin({ > string r = "enum MemberNamesUnion { "; > foreach (T; E) { >

Re: "Error 42: Symbol Undefined" for asserts

2014-05-02 Thread Andre Steenveld via Digitalmars-d-learn
I seem to have partially solved the problem myself. It seems that when using the Unittest target makes the linker look in to the /bin/Unittest directory even though project can be build using a different target. (right click the solution -> options -> configurations -> Configuration Mappings) I

Re: Making enum join variadic

2014-05-02 Thread Nordlöw
So that leaves me with using an array of bool and rank() then, I guess... Correction: I mean array of strings and find.

Re: Making enum join variadic

2014-05-02 Thread Nordlöw
On Friday, 2 May 2014 at 14:36:16 UTC, Meta wrote: On Friday, 2 May 2014 at 13:38:39 UTC, Nordlöw wrote: enums.d(25,46): Error: static variable allMembers cannot be read at compile time enums.d(25,21):while evaluating: static assert("a" in allMembers) Is there a solution to this probl

Re: Making enum join variadic

2014-05-02 Thread Meta via Digitalmars-d-learn
On Friday, 2 May 2014 at 13:38:39 UTC, Nordlöw wrote: enums.d(25,46): Error: static variable allMembers cannot be read at compile time enums.d(25,21):while evaluating: static assert("a" in allMembers) Is there a solution to this problem? Associative arrays are not CTFE-able.

Re: Making enum join variadic

2014-05-02 Thread Nordlöw
On Friday, 2 May 2014 at 12:45:44 UTC, Nordlöw wrote: I'd be verbose. It's an uncommon operation, bound to surprise a reader a bit.It's better to type a few more letters. See update. I did not try to compile it, but what happens if the enum elements have the same name ? The same min/max/val

Re: Making enum join variadic

2014-05-02 Thread Nordlöw
I'd be verbose. It's an uncommon operation, bound to surprise a reader a bit.It's better to type a few more letters. See update. I did not try to compile it, but what happens if the enum elements have the same name ? The same min/max/values ? Like this: enum E1 { a, b, c } alias E111 = jo

Re: Making enum join variadic

2014-05-02 Thread Philippe Sigaud via Digitalmars-d-learn
On Fri, May 2, 2014 at 12:59 PM, "Nordlöw" wrote: > Some final questions: > > - Is join a good naming for this? Is chain better? > - Is it better to be verbose with joinEnums? I'd be verbose. It's an uncommon operation, bound to surprise a reader a bit.It's better to type a few more letters. I

Re: "Error 42: Symbol Undefined" for asserts

2014-05-02 Thread FrankLike via Digitalmars-d-learn
Maybe not add -L+somelib.lib

"Error 42: Symbol Undefined" for asserts

2014-05-02 Thread Andre Steenveld via Digitalmars-d-learn
Hello all, I just started learning D and I thought it would be a good idea to port the Reactive Extensions to D. So far so good, I have been using Xamarin Studio in combination with Mono-D on Windows 7 and DMD 2.065.0. Even though unit testing is baked in to the language I wanted to set up

Re: Making enum join variadic

2014-05-02 Thread Nordlöw
Its up: https://github.com/nordlow/justd/blob/master/enums.d

Re: Making enum join variadic

2014-05-02 Thread Nordlöw
artur Thx! Here's my final version that compiles and run: import std.stdio: writeln; import traits_ex: isEnum; import std.typetuple: allSatisfy; /** Join/Chain/Concatenate/Unite Enums $(D E1), $(D E2), ... into $(D E). See also: http://forum.dlang.org/thread/f9vc6p$1b7k$1...@digitalmars

Allocation-free message passing?

2014-05-02 Thread JR via Digitalmars-d-learn
I'm trying to impose limits upon myself to, well, learn. Currently I'm exploring ways to avoid allocations -- but my program is running in three threads with considerable amounts of message passing between them. Unless I'm misinterpreting my callgraph, std.concurrency.MessageBox contains a st

Re: Reading ELF Files

2014-05-02 Thread yazd via Digitalmars-d-learn
On Thursday, 1 May 2014 at 17:31:52 UTC, Nordlöw wrote: Here you go, https://github.com/yazd/elf-d. Thanks! Anytime. By the way, if you need more stuff out of it or help, post an issue on github. I think I'll be able to help a bit more. But if this library is to move forward, the API will n

Re: formattedWrite writes nothing

2014-05-02 Thread anonymous via Digitalmars-d-learn
On Friday, 2 May 2014 at 10:23:03 UTC, Andrej Mitrovic via Digitalmars-d-learn wrote: Ouch, ouch, ouch! What's happening is that the 'clear' Appender method is only compiled-in if the data is mutable, otherwise you end up calling the object.clear UFCS function. So don't use clear here. I don't

Re: const ref parameters and r-value references

2014-05-02 Thread via Digitalmars-d-learn
On Friday, 2 May 2014 at 08:17:09 UTC, Mark Isaacson wrote: I'm in the process of learning/practicing D and I noticed something that seems peculiar coming from a C++ background: If I compile and run: void fun(const ref int x) { //Stuff } unittest { fun(5); //Error! Does not compile } I g

Re: formattedWrite writes nothing

2014-05-02 Thread Andrej Mitrovic via Digitalmars-d-learn
On 5/2/14, ref2401 via Digitalmars-d-learn wrote: > class MyClass { > Appender!string _stringBuilder; > > this() { > _stringBuilder = Appender!string(null); > _stringBuilder.clear(); Ouch, ouch, ouch! What's happening is that the 'clear' Appender method is

formattedWrite writes nothing

2014-05-02 Thread ref2401 via Digitalmars-d-learn
class MyClass { Appender!string _stringBuilder; this() { _stringBuilder = Appender!string(null); _stringBuilder.clear(); } @property string str() { return _stringBuilder.data; } void append(string s)

const ref parameters and r-value references

2014-05-02 Thread Mark Isaacson via Digitalmars-d-learn
I'm in the process of learning/practicing D and I noticed something that seems peculiar coming from a C++ background: If I compile and run: void fun(const ref int x) { //Stuff } unittest { fun(5); //Error! Does not compile } I get the specified error in my unit test. I understand that the

Re: Unresolved external symbol

2014-05-02 Thread Ga via Digitalmars-d-learn
On Friday, 2 May 2014 at 06:07:48 UTC, evilrat wrote: On Thursday, 1 May 2014 at 22:23:22 UTC, Ga wrote: And I am getting a "error LNK2019: unresolved external symbol GetDeviceCaps referenced in function _Dmain" have you linked gdi32.lib? Thanks a lot, I wasn't sure what to link with, I must