|
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$6701a8c0_at_genosoft.com...
>> [...]
>> 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
get(S)
{
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
operator*(I)
{
typedef typename mpl::deref<I>::type result;
return result();
}
Then:
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.
Cheers,
-- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk