August 08, 2012
On 8/8/12, Philippe Sigaud <philippe.sigaud@gmail.com> wrote:
> Hey, every time I do something like that, you ask me to put it in my template tutorial ;)

Well yeah, we don't want a future Banana(tm) company patenting our
codez, we need prior art! :p

So maybe it's not book-worthy. Perhaps there should be a github repo with mildly interesting boost-licensed code that anyone can use. Or maybe I'm overthinking it.
August 08, 2012
On Wed, Aug 8, 2012 at 7:45 PM, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:
> On 8/8/12, Philippe Sigaud <philippe.sigaud@gmail.com> wrote:
>> Hey, every time I do something like that, you ask me to put it in my template tutorial ;)
>
> Well yeah, we don't want a future Banana(tm) company patenting our
> codez, we need prior art! :p
>
> So maybe it's not book-worthy. Perhaps there should be a github repo with mildly interesting boost-licensed code that anyone can use. Or maybe I'm overthinking it.

Like the Python Cookbook?

There was a dsource project like this IIRC, but it was for small modules, not code snippets.
August 08, 2012
On Tuesday, 7 August 2012 at 16:11:05 UTC, Andrej Mitrovic wrote:
> On 8/7/12, "Øivind" <oivind.loe@gmail.com> 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)

You can also use slice operator instead of expand property.


import std.stdio, std.typecons;
void f(T ...)(T t) {
    writeln(t.length);
}

void main(){
    auto v = tuple(1, 2, 3);
    f(v[]); // prints 3

    auto v0 = tuple(1, 2, 3);
    auto v1 = tuple(4, 5, 6);
    f(v0[], v1[]);  // prints 6
}

August 09, 2012
On Thu, Aug 9, 2012 at 1:26 AM, Kenji Hara <k.hara.pg@gmail.com> wrote:

> You can also use slice operator instead of expand property.

>
> import std.stdio, std.typecons;
>
> void f(T ...)(T t) {
>     writeln(t.length);
> }
>
> void main(){
>
>     auto v = tuple(1, 2, 3);
>     f(v[]); // prints 3

I didn't know that.
Nice one. Indeed, it's almost like a range. A bit dangerous, as people
might forget that what they get is a tuple with possibly different
types, instead of a range, but good to know as it offers a homogeneous
syntax.

Hey, I have map/filter/reduce functions for tuples, should they be part of Phobos?

auto t = tupleMap!(a => to!string(a))(1,'a',"abc'", 3.14); // eager, not lazy

assert(t == tuple("1", "a", "abc", "3.14"));

auto arr = [t[]]; // crack open & transform into an array
assert(is(typeof(arr) == string[]));


Of course, the mapping function must be polymorphic or overloaded. The good news is, it may very well have different return types for each argument type, thus giving back another, entirely different tuple.

But I'm not sure people use tuples that much in D...
>     auto v0 = tuple(1, 2, 3);
>     auto v1 = tuple(4, 5, 6);
>     f(v0[], v1[]);  // prints 6
> }
>
1 2
Next ›   Last »