$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Matthias Schabel (boost_at_[hidden])
Date: 2007-02-10 13:35:05
Hi Andrey,
> 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 {};
The problem with this is that you still need to keep track of previously
defined tags. That is, you need to know what the last tag defined was to
call ::next on it. Imagine that you wanted to extend the SI system
with a
new fundamental unit for fabulousness. As it stands now, you would do
something like this in your code:
namespace boost {
namespace units {
struct fabulousness_tag : public ordinal<10> { };
typedef fundamental_dimension<fabulousness_tag>::type fabulousness_type;
namespace SI {
// SI unit of fabulousness
typedef unit<SI::system,fabulousness_type> fabulousness;
static const fabulousness fab,
fabs;
} // namespace SI
} // namespace units
} // namespace boost
Here, you need to know that there are already 9 tags defining the pre-
existing fundamental types in the SI system. What I want to do is to
query the compiler as to how many previous distinct instantiations of
ordinal<N> have already been encountered so you could write
struct fabulousness_tag : public ordinal<N_prev_ordinal_instantiations
+1> { };
This would allow you to add tags without ever having to look around
to determine the current upper limit...If may not be possible, though.
Matthias