Boost logo

Boost :

From: Andrey Semashev (andysem_at_[hidden])
Date: 2007-02-09 16:00:52


Hello Matthias,

> Is there some method to count specializations of a template class?
> That is, if I have

> template<long N> struct ordinal { typedef typename
> boost::mpl::int_<N> value; };

> I want to be able to do something like this (warning not C++):

> struct tag1 : public next_ordinal::type { };
> struct tag2 : public next_ordinal::type { };
> struct tag3 : public next_ordinal::type { };

> etc... where next_ordinal::type resolves to ordinal<1>, ordinal<2>,
> and ordinal<3> on sequential calls. Anyone have any ideas? This would
> simplify and make safer the process of defining user-defined unit
> systems.

Maybe something like this?

// the_library.hpp

template< unsigned int N = 0 >
struct ordinal :
  public mpl::int_< N >
{
  typedef ordinal< N + 1 > next;
};

// We may use ordinals in the lib, in that case
// initial_ordinal below should be the first
// available ordinal for users

typedef ordinal< > initial_ordinal;

// user_code.hpp

struct tag1 : public initial_ordinal {};
struct tag2 : public tag1::next {};
struct tag3 : public tag2::next {};

-- 
Best regards,
 Andrey                            mailto:andysem_at_[hidden]

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