variant==dependent pair, dependent function possible?

IIUC, the variant library is similar to a "dependent product" which can be thought of as a pseudo_pair<Index,TypeList>. where an instance: pseudo_pair<I,T> dpIT; is a pair of values (i,t) where: I i; T<i> t; IOW, there is only one value, but it can be one of many types depending on the valid values of I. BTW, would variant be made for readable by making variant take an enumeration: enum I{i0, i1, ...., in-1} as the discriminator? Anyway, back to the original question. Is there any interest in a "dependent function" where: dependent_function<I,T> df; where: T<i0>& df<i0>(); T<i1>& df<i1>(); ... T<in-1>& df<in-1>(): IOW, this would be like a regular struct (a record type), however, instead of: df.ix there would be: df<ix>(); BTW, this idea comes from Nuprl: http://www.cs.cornell.edu/Info/Projects/NuPrl/nuprl.html and I've recently had a need for it because I've got a template which is specialized on an enumeration; hence, this would come in handy if I wanted to have a structure containing all instances of the specializations.

On 12/01/2004 04:18 PM, Larry Evans wrote: [snip]
Anyway, back to the original question. Is there any interest in a "dependent function" where:
dependent_function<I,T> df;
There's currently in: */boost-sandbox/boost/indexed_types/product.hpp a prototype of the idea. It can be fairly easily extended to a counterpart of variant.hpp which allows repeating a type in the type sequence (see Preconditions: in variant_fwd.hpp). For example, instead of product and factor templates, there would be summation and term templates and instead of product<Tseq>::project<field_id>, there would be summation<Tseq>::inject<field_id>( at_c<Tseq,field_id> const& ). The names, project and inject come from the previously cited nuprl pages. I suspect the product might be simplified via mpl fold, as done with mpl::inherit_recursively. I'd like feedback on any suggested improvements. I'm thinking changing the parameters to: template < typename Enumeration , template <Enumeration>class TypeMap > where Enumeration would have to be an enumeration and TypeMap would have specializations: template<>class TypeMap<e_i>{ typedef i-th type;}; to make clearer what the names of the fields are.
participants (1)
-
Larry Evans