On 03/25/2012 02:04 PM, James Miller wrote:
On 26 March 2012 09:45, bls<bizp...@orange.fr>  wrote:
How do I "call" opDispatch(string name, E...)(E elements) ?
What I want to archive is to call f.i. fm.list with an arbitrary number of
arguments without using

fm.list(1, "abc", 4L, 3.33);

Instead I would prefer
fm.list = (1, "abc", 4L, 3.33);

You can use @property on opDispatch to use setter/getter notation,
however I wouldn't rely on that functionality long-term if you want to
keep the same function-call syntax (since -property flag is supposed
to enforce proper parenthesis use on `@property`s).

fm.list = (1, "abc", 4L, 3.33);

I'm hoping you mean `fm.list = [1, "abc", 4L, 3.33];` I think that
using the right template parameters, you can use the same code for
(T...)(T el) and (T)(T[]), I just can't remember what that is...


Ouch, yep, I mean [1, "abc", 4L, 3.33]
But I have no clue how to implement it.


Another question :
How do I bring in :

opDispatch(string name, T) (T[] t)

--
James Miller

(T) (T[] t) AND (T) (T t) seems not to work.
snip
struct FlexMap
{
        Variant[] [string] map;

        Variant[] opDispatch(string name)()
        {
       return map[name];
    }
        
    Variant[] opDispatch(string name, E...)(E elements)
        {
                foreach(element; elements)
                map[name] ~= to!Variant(element);

                return properties[name];
    }
        
        Variant[] opDispatch(string name, T) (T t)
        {
                map[name] ~= to!Variant(t);
                return map[name];
        }               
        // No go
        Variant[] opDispatch(string name, T) (T[] t) {}

}

Reply via email to