Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2003-10-23 06:06:52

David B. Held <dheld_at_[hidden]> wrote:
> "David B. Held" <dheld_at_[hidden]> wrote in message
> news:000901c39947$6894b610$
>> [...]
>> get<3>(f.v);
>> [...]
> It occurs to me that what is needed is a run-time analog of
> at<>, which has the same signature as get<> for tuples.
> Then I wouldn't need to convert to a tuple (though tuples do
> have a nice interface). How hard would that be?

template <int N, class S>
inline typename mpl::at_c<S, N>::type
    typedef typename mpl::at_c<S, N>::type result;
    return result();

However, be reminded that mpl::at has O(N) complexity.
The function could potentially generate lots of instantiations.
Well, the old tuples get<N> implementation is known to be
compile-time innefficient already.

How about:

template <class I>
inline typename mpl::deref<I>::type
    typedef typename mpl::deref<I>::type result;
    return result();


    typedef mpl::list<int, char, std::string> tlist;

    mpl::begin<tlist>::type i1;
    int i = *i1;

    mpl::next<i1>::type i2;
    char c = *i2;

    mpl::next<i2>::type i3;
    std::string s = *i3;

This is how it's done in Fusion.


Joel de Guzman

Boost list run by bdawes at, gregod at, cpdaniel at, john at