Topic: Missing availibility of integral, non-type template parameters


Author: dsp@bdal.de (Daniel =?iso-8859-1?Q?Kr=FCgler?= (nee Spangenberg))
Date: Mon, 8 Dec 2003 10:17:02 +0000 (UTC)
Raw View
Hello,

I notized, that both the current std::bitset class template and the
current
proposal for the array class template (have a look at

http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1548.htm

) lack of a constant, static class member, which allows access
to their corresponding non-type template parameter.

Due to the fact, that the current C++ standard library does not
contain many template classes with integral, non-type template
parameters I assume, that this lack is probably an oversight
and not by design, isn't it?

I propose to add accessors to these template parameter values
by means of constant, static class data members of integral type:

For std::bitset:

namespace std {
template<size_t N> class bitset {
public:
  static const size_t static_size =3D N;
  ... // Remaining members as given by the current C++ standard
};
...
}

For the current array proposal:

namespace std {
template <class T, size_t N>
struct array {
  static const size_t static_size =3D N;
  ... // Remaining members as given by the current proposal
};
...
}

The reasons for such a pure extension of those library classes
are:

(a) Constant, integral non-type template parameters often do have
some similarities to typed template parameters (where the last
ones usually are accessible by standardised typedefs inside class
templates, e.g. value_type, element_type or the like), because
of well-known and important template techniques which take
advantages from type <-> value mappings. Those mapping techniques
can be found in template libraries like Loki or boost.

(b) From the point of implementation, the addition of a constant,
static class member of integral or enumeration type is usually
cheap compared to other static members. There do exist (traits)
classes in the current standard library which provide a lot of such
constant static data members (std::numeric_limits).

(c) Constant, static data members of integral or enumeration can
immediately be initialized inside their in-class-declaration and
can be used as part of integral constant expressions. This is an
important property, which is exploited in important metaprogramming
techniques (see also point (a)).

Also note, that pre-proposal implementations of the array class
template does have such a static class member (see

http://www.boost.org/libs/array/array.html

)

Thanks for your attention,

Daniel Kr=FCgler (nee Spangenberg)








---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]