
On Aug 6, 2006, at 6:13 AM, Ion GaztaƱaga wrote:
Good. I can set the bar higher if you want ;-). What about storing the return value in a tuple:
bool test() { /**/ }
template<typename... Values> void test_all(const Values&... values) { //Is this possible? //tuple<decltype(test(Values))...> ret_tuple = ...
//or using "auto" auto ret_tuple = variadic_unroll(test(values)); }
No need for a "variadic_unroll"; just use make_tuple: auto ret_tuple = make_tuple(test(values)...)
It would be also nice a way to define a tuple of N objects of the same type: auto tup = make_tuple_n<bool, 6>;
I bet you can write a short metaprogram to do this using variadic templates.
And iterate at runtime in a tuple of N objects of the same type, to get each value (the iterator would climb in the inheritance-emulation code when incremeting it):
for( bool ok : ret_tuple ) std::cout << "return value:" << ok;
As Alisdair points out, we have array<>, which we can easily loop over. And, of course, that std::cout << ... bit is just an expression, so you can "unroll" the loop like this: variadic_unroll(std::cout << "return value: " << ret_tuple...); Cheers, Doug