|
Boost Users : |
Subject: Re: [Boost-users] Type arithmetic library?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-06-12 12:06:26
AMDG
Peng Yu wrote:
> boost typeof library can automatically deduce the type.
>
> But I'm interested in finding the nested type. For example, if I have
> a template S<T1, T2>. I'd like to deduce that it has two template
> arguments, I'd like to access its template argument by index (say, 0
> and 1 for this case).
>
> I did a preliminary search, but found no such facilities. I may
> overlook something. Would you please let me know if there is such a
> facility in boost?
>
There isn't, but it's fairly easy to do
template<class T>
struct template_parameters;
template<template<class> class T, class T0>
struct template_parameters<T<T0> > : boost::mpl::vector<T0> {};
template<template<class, class> class T, class T0, class T1>
struct template_parameters<T<T0, T1> > : boost::mpl::vector<T0, T1> {};
template<template<class, class, class> class T, class T0, class T1,
class T2>
struct template_parameters<T<T0, T1, T2> > : boost::mpl::vector<T0, T1,
T2> {};
template<template<class, class, class, class> class T, class T0, class
T1, class T2, T3>
struct template_parameters<T<T0, T1, T2, T3> > : boost::mpl::vector<T0,
T1, T2, T3> {};
//...
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net