Boost logo

Boost :

From: Peder Holt (peder.holt_at_[hidden])
Date: 2007-08-31 04:43:42


2007/8/30, Mathias Gaunard <mathias.gaunard_at_[hidden]>:
> Daryle Walker wrote:
> > We have some class templates in forms like:
> >
> > //==========================================================
> > template <unsigned X> struct my_test;
> >
> > template <> struct my_test<0u> {};
> >
> > template <unsigned X>
> > struct my_test { typedef my_test<(X - 1u)> type; };
> > //==========================================================
> >

Do you mean something like this?

template<unsigned X>
struct my_test {
    typedef int type;
};

typedef boost::mpl::list_c<unsigned,1,2,5,6,7> limit_type;

template<typename T,typename Limiter>
struct test_item_limit : boost::mpl::false_
{};

template<unsigned X,typename Limiter>
struct test_item_limit<my_test<X>,Limiter> :
    boost::mpl::not_<
        boost::is_same<
            typename boost::mpl::find<
                Limiter,
                boost::mpl::integral_c<unsigned,X>
>::type,
            typename boost::mpl::end<Limiter>::type
>
>
{
};

template < unsigned X >
typename my_test<X>::type print_out( my_test<X> const &x,typename
boost::enable_if<test_item_limit<my_test<X>,limit_type> >::type* =0)
{
    std::cout << "There's a specialization at " << X
        << '.' << std::endl;
    return my_test<X>::type();
}

template < typename T >
void print_out( T const &x )
{ std::cout << "There's no 'type' here." << std::endl; }

void main() {
    print_out(my_test<5>());
    print_out(my_test<7>());
    print_out(my_test<4>());
}

Regards
Peder

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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk