opDispatch(string name, E...) (E e) question.

bls bizprac at orange.fr
Sun Mar 25 13:45:57 PDT 2012


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);

Is this somehow possible ?

import std.variant;
import std.conv;
....
auto fm = FlexMap();

fm.ten = 10;
fm.ten = ["Ten", "Zehn", "Tein"];
fm.list = [20, 10, 2, 2, 44 ] ;
fm.list = "Hello opDispatch";

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 map[name];
     }
	
     Variant[] opDispatch(string name, T) (T t)
     {
	map[name] ~= to!Variant(t);
	return map[name];
     }		
}



Another question :
How do I bring in :

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

into FlexMap ?

TIA, Bjoern


More information about the Digitalmars-d-learn mailing list