"Douglas Gregor" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
----- Original Message -----
From: "Brian Simpson" <[EMAIL PROTECTED]>
> The general case devolves into an else-if-then:
> Let us assume that we have specializations up to a certain number, > 'max_specialization_count'. Then we know that we can get > switch-based runtime type selection ("rtts") on any mpl::Sequence > whose size is not greater than 'max_specialization_count'. To > provide rtts for Sequences whose size is greater than > 'max_specialization_count', we provide a more general template > definition. Its "invoke" function sets up a switch-based selection > among the first 'max_specialization_count' types, and then sets
up
> a (recursive) selection among the remaining types.


Of course, you can do slightly better than this by switching in chunks of size max_specialization_count, so there there are only a few if statements (to determine which chunk we're in). Granted, the effort would be large and the return potentially small, so it may not be of interest. (My assumption is that most people do not use variants with huge numbers of possibilities, so that few variants require the if statements).

I agree that in general, variants will have a small enough number of possibilities to avoid an if statement completely, so the return would, indeed, be small. That said, I think you'll be happy to hear that the effort is even smaller, in fact it is the current implementation (I think my original description was lacking).
Just so you don't have to wade through the code, here is the general case "invoke" function:
<code>
template <typename Operator, typename StoragePtr>
static
Operator::result_type
invoke(Operator & op, StoragePtr storage, long index)
{
if (index < max_selection_specialization_count_t::value)
{
return n_ary_rtts_invoker<Sequence, max_selection_specialization_count_t>::invoke(op, storage, index);
}
else
{
typedef /*see source*/ remaining_types_t;
typedef /*see source*/ remaining_selection_count_t;
return
n_ary_rtts_invoker<remaining_types_t, remaining_selection_count_t>
::invoke(op, storage, index - max_selection_specialization_count_t::value);
}
}
</code>
This is what you were suggesting, right?



> Questions or comments?


I haven't reviewed the code itself, but the idea is good and I believe this would be a boon to the variant library. Itay and/or Eric will need to look this over if it is to be included.

Thanks! I appreciate your comments.


Brian

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to