Re: Vararg-templated class with matching member func

2013-04-06 Thread Nick Sabalausky
On Sun, 07 Apr 2013 01:53:34 +0200 "bearophile" wrote: > Nick Sabalausky: > > > I have a feeling I'm missing something obvious, but how do I > > create > > something like this?: > > > > class Foo(TArgs...) > > { > > void func(/+ args must exactly match TArgs +/) > > { > > } > > } >

Re: rationale for opSlice, opSliceAssign, vs a..b being syntax suger for a Slice struct?

2013-04-06 Thread bearophile
Timothee Cour: * it breaks _orthogonality_ of features: opIndex should work with everything (indexes, slices), whereas now we're having an opSliceIndex that works on slices and opIndex that works on non-slices. Don has discussed about this more than one time. Generally I think there is spac

Re: Vararg-templated class with matching member func

2013-04-06 Thread bearophile
Nick Sabalausky: I have a feeling I'm missing something obvious, but how do I create something like this?: class Foo(TArgs...) { void func(/+ args must exactly match TArgs +/) { } } new Foo(int).func(5); // Ok new Foo(int, string).func(5, "hello"); // Ok // Error! Overload not fo

Vararg-templated class with matching member func

2013-04-06 Thread Nick Sabalausky
I have a feeling I'm missing something obvious, but how do I create something like this?: class Foo(TArgs...) { void func(/+ args must exactly match TArgs +/) { } } new Foo(int).func(5); // Ok new Foo(int, string).func(5, "hello"); // Ok // Error! Overload not found! new Foo(int).fun

rationale for opSlice, opSliceAssign, vs a..b being syntax suger for a Slice struct?

2013-04-06 Thread Timothee Cour
Currently x[a...b] calls opSlice(a,b); This has several drawbacks: * it breaks _orthogonality_ of features: opIndex should work with everything (indexes, slices), whereas now we're having an opSliceIndex that works on slices and opIndex that works on non-slices. * one can't have multiple slicing

Re: map with void fun

2013-04-06 Thread bearophile
cal: Ah thank you, I did not realize a call to front was required. Whenever you can, don't create side effects inside a map(). It will not work reliably. A higher order function like map is not meant to be used that way. Bye, bearophile

Re: map with void fun

2013-04-06 Thread cal
On Saturday, 6 April 2013 at 21:40:37 UTC, bearophile wrote: First, to see the side effects you have also to call front: Ah thank you, I did not realize a call to front was required. But this is wrong still. map() is a higher order function, it's meant to take a function and an iterable and p

Re: map with void fun

2013-04-06 Thread bearophile
cal: Should the code below print anything (it currently doesn't)? I'm not sure I understand map: import std.stdio, std.algorithm; void main() { int[] a = [1,2,3,4,5]; auto r = a.map!( i => writeln(i) ); while(!r.empty) r.popFront(); } The code is working as requested. Bu

map with void fun

2013-04-06 Thread cal
Should the code below print anything (it currently doesn't)? I'm not sure I understand map: import std.stdio, std.algorithm; void main() { int[] a = [1,2,3,4,5]; auto r = a.map!( i => writeln(i) ); while(!r.empty) r.popFront(); }

Re: Return enum-templated struct based on runtime value

2013-04-06 Thread Sebastian Graf
On Saturday, 6 April 2013 at 15:38:55 UTC, Tobias Pankrath wrote: Is there however some way to generate that switch with cases for each enum member in a template, so that each case calls (Machine)() instantiated with the appropriate enum member? I know you could do it with string mixins, but

Re: Return enum-templated struct based on runtime value

2013-04-06 Thread Tobias Pankrath
Is there however some way to generate that switch with cases for each enum member in a template, so that each case calls (Machine)() instantiated with the appropriate enum member? I know you could do it with string mixins, but that be a hassle to implement... Eventually, I want my code to l

Re: Return enum-templated struct based on runtime value

2013-04-06 Thread Sebastian Graf
On Friday, 5 April 2013 at 18:00:56 UTC, bearophile wrote: Sebastian Graf: I wonder if there is a good way to dry up this: I suggest to improve that code a lot. For machineWord there is: alias machineWord = Select!(machine == Machine.I386, uint, ulong); This: (1 << 32) Gives: Error: shi

Re: A little of coordination for Rosettacode

2013-04-06 Thread bearophile
Jos van Uden: http://rosettacode.org/wiki/Set_puzzle#Alternative_Version Ledrug tagged it. The output says: striped open open. That shouldn't happen. I don't know what's wrong, and why, so I've killed that alternative version... Bye, bearophile