Any chance to call Tango as Extended Standard Library
BLS
nanali at nospam.wanadoo.fr
Sun Jan 18 13:38:13 PST 2009
BLS schrieb:
> Andrei Alexandrescu schrieb:
>> Jarrett Billingsley wrote:
>>> On Sun, Jan 18, 2009 at 1:00 PM, dsimcha <dsimcha at yahoo.com> wrote:
>>>> Nice. Glad to see that this is documented somewhere so I can start
>>>> playing with
>>>> it. One thing, though: In my dstats library, I have a custom hash
>>>> table
>>>> implementation that's used very heavily in my information theory
>>>> module. (I have
>>>> my reasons for using a custom hash table instead of the builtin, but
>>>> they're
>>>> beyond the scope of this post.) Right now, the hash table uses
>>>> opApply. Now that
>>>> I realize how horribly slow opApply is, I'd like to port this to
>>>> ranges. However,
>>>> I need to be able to iterate over either key, value pairs or just
>>>> values. Is
>>>> there any way to make this work with ranges?
>>>>
>>>
>>> You could handle key or value iteration by using a proxy struct type
>>> that follows the range protocol, and have your hash table return one
>>> of those structs from methods such as "keysIter" or "valuesIter". But
>>> unless I'm mistaken, D2 still doesn't support returning tuples, so you
>>> still can't have keys _and_ values at the same time. (Unless you're
>>> content with using a Pair or something.)
>>
>> Returning a std.typecons.Tuple is entirely possible.
>>
>> Andrei
>
> tuple(K,V) foo(K,V)(K k, V v)
> {
> ...
> }
> ????, I have no idea, pls help Bjoern
>
Look like this works... However it would be nice if we could place the
alias Tuple Pair stuff outside of foo()
module tt;
import std.stdio;
import std.typecons;
//alias Tuple!(K, "key", V, "value") Pair; This don't work
auto foo(K,V)(K k, V v)
{
alias Tuple!(K, "key", V, "value") Pair;
Pair P;
P.key = ++k;
P.value = v;
return P;
}
void main()
{
//Pair KV;
auto KV = foo!(int,string) (10,"Hello");
writefln("%8s %s\n", KV.key, KV.value);
}
This is a really nice feature, guess there are smarter ways to implement
tuple returns..
Bjoern
More information about the Digitalmars-d
mailing list