Re: User defined attributes use

2013-09-20 Thread ilya-stromberg
On Monday, 16 September 2013 at 07:36:13 UTC, simendsjo wrote: I don't have a full example without adding a lot of code, but this partial example might give you the gist of it. // This is the type that validates struct matches(string mustMatch) { alias re = ctRegex!(mustMatch); static

Re: User defined attributes use

2013-09-20 Thread Jacob Carlborg
On 2013-09-20 08:59, ilya-stromberg wrote: Can I explicitly specify when I can use attribute? Something like this: @attribute("field") struct matches(string mustMatch) { } string wrongAttribute { } class Foo { @matches("[0-9]+") string someNumber; //OK, it's a field } @matches("[0-

Re: References

2013-09-20 Thread andrea9940
Remove the "ref" in "ref A opAdd(const ref A a) {"

References

2013-09-20 Thread andrea9940
Running this code I would expect to get "ref" three times, but ... --- import std.stdio; struct A { int[128] data; ref A opAdd(const ref A a) { A cp = this; cp.data[] += a.data[]; return cp; } } void fun(A a) { writeln("

Re: References

2013-09-20 Thread Namespace
On Friday, 20 September 2013 at 09:36:18 UTC, andrea9940 wrote: Running this code I would expect to get "ref" three times, but ... --- import std.stdio; struct A { int[128] data; ref A opAdd(const ref A a) { A cp = this; cp.data[] += a.data[];

Re: References

2013-09-20 Thread andrea9940
On Friday, 20 September 2013 at 09:44:51 UTC, Namespace wrote: This prints 'ref' if you change func(A a) to func(const A a) the match of const ref isn't prefered over A a because const need an implicit conversion. Thanks for the tip. a + b is an rvalue and will moved to func(A a). This is eve

Re: References

2013-09-20 Thread Namespace
On Friday, 20 September 2013 at 10:29:24 UTC, andrea9940 wrote: On Friday, 20 September 2013 at 09:44:51 UTC, Namespace wrote: This prints 'ref' if you change func(A a) to func(const A a) the match of const ref isn't prefered over A a because const need an implicit conversion. Thanks for the

Re: References

2013-09-20 Thread andrea9940
Output: CTor A with 42 CTor A with 23 CTor A with 65 Value call with A::65 DTor A with 65 CTor A with 1337 Value call with A::1337 DTor A with 1337 Ref call with A::42 DTor A with 23 DTor A with 42 No Postblit call. The beahvior is correct but at assembly level the compiler still cre

Re: Compile time data structure

2013-09-20 Thread Dicebot
On Friday, 20 September 2013 at 06:20:09 UTC, Ali Çehreli wrote: On 09/19/2013 04:32 AM, Dicebot wrote: > Some obvious catches: Thank you. I have made those changes except the following one. > Variadic template arg chapter should probably mention "variadic args of > length 1" idiom used to hav

Re: User defined attributes use

2013-09-20 Thread simendsjo
On Friday, 20 September 2013 at 07:57:43 UTC, Jacob Carlborg wrote: On 2013-09-20 08:59, ilya-stromberg wrote: Can I explicitly specify when I can use attribute? Something like this: @attribute("field") struct matches(string mustMatch) { } string wrongAttribute { } class Foo { @matches(

Re: non virtual interfaces

2013-09-20 Thread Alexandr Druzhinin
20.09.2013 12:45, Ali Çehreli пишет: On 09/19/2013 10:31 PM, Alexandr Druzhinin wrote: > if I use protected instead of private in interface like: private member functions are non-virtual. But I just use code example from TDPL russian edition. And TDPL says clearly that (un)transmogrify() are

Re: non virtual interfaces

2013-09-20 Thread Jonathan M Davis
On Friday, September 20, 2013 22:40:48 Alexandr Druzhinin wrote: > 20.09.2013 12:45, Ali Çehreli пишет: > > On 09/19/2013 10:31 PM, Alexandr Druzhinin wrote: > > > if I use protected instead of private in interface like: > > private member functions are non-virtual. > > But I just use code exampl

Re: non virtual interfaces

2013-09-20 Thread Alexandr Druzhinin
20.09.2013 23:09, Jonathan M Davis пишет: You can use NVI with classes just fine just so long as you use protected rather than private, but making it private there won't work either, because private is never virtual (and it wouldn't really help you any if it were, because while the base class pri