[fusion] at_c<> where index is a runtime variable

Under fusion namespace we can write vector<int, double, string> v(1, 2.4, "hello"); print_type( at_c<2>(v) ); // prints string print_value( at_c<2>(v) ); // prints "hello" But number 2 in our example must be a compile time constant, we cannot write int idx = 2; at_c<idx>(v); // compile error here Sometime accessing an element in a fusion sequence indexed by a runtime variable could be useful, something like the following: vector<int, double, string> v(1, 2.4, "hello"); int idx; cout << "Give me an index" << endl; cin >> idx; apply_at(v, idx, print_type); // prints string if idx == 2, or int if idx == 0 apply_at(v, idx, print_value); // prints "hello" if idx == 2, or 1 if idx == 0 Because I didn't find something similar in fusion and I needed that for code I'm writing I cooked up my solution, it's very easy and if someone is interested I can post it. Marco P.S: If someone could point me to an already available solution it would be appreciated ;-) I just missed it.

On 06/04/08 15:53, Steven Watanabe wrote:
Steven, there was also something on the c.l.c++.m newsgroup about this. There's even a comparison with switch_ here: http://groups.google.com/group/comp.lang.c++.moderated/msg/771d715f3f238fee

AMDG Larry Evans wrote:
Ok. I think that the easiest way to state the difference is that Switch is a lower level generic component, while the solution proposed there is specific to accessing tuples. Both the performance considerations mentioned in that post can be implemented on top of switch. Optimizing away the default can be handled by passing a function object like template<class R> struct never_called { template<class N> R operator()(N) { __assume(0); } }; In Christ, Steven Watanabe

I have read now the performance comparsion from boost::variant and the other library.Is the performance of boost::variant really so bad with VS 8.0?? Has anyone mad any similar tests? Best regards Hansjörg Larry Evans schrieb:
participants (4)
-
Hansi
-
Larry Evans
-
Marco Costalba
-
Steven Watanabe