Topic: Extension of tuple interface for std::bitset


Author: dsp@bdal.de (=?ISO-8859-1?Q?Daniel_Kr=FCgler?=)
Date: Tue, 16 Aug 2005 13:32:26 GMT
Raw View
After reading about the current application of std::tr1::tuple_size in

http://www2.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf

I found that it should should result in well-formed code if one of the fo=
r
the following class templates are used as template arguments:

std::pair<typename, typename>
std::tr1::tuple<...>
std::tr1::array<typename, size_t>

I suggest, that

template<size_t N> class bitset

should also provide a similar tuple interface. I propose to add the
following clauses:

"Tuple interface to class template bitset [tr.bitset.tuple]
tuple_size<bitset<N> >::value
1 Return type: integral constant expression.
2 Value: N
tuple_element<I, bitset<N> >::type
3 Requires:0 <=3D I < N. The program is ill-formed if I is out of bounds.
4 value: The type bool.
template <int I, size_t N> typename bitset<N>::reference get(bitset<N>& a=
);
5 Requires: 0 <=3D I < N. The program is ill-formed if I is out of bounds.
6 Returns: A reference to the Ith element of a, where indexing is=20
zero-based.
template <int I, size_t N> bool get(const bitset<N>& a);
7 Requires: 0 <=3D I < N. The program is ill-formed if I is out of bounds.
8 Return type: bool.
9 Returns: The value of the Ith element of a, where indexing is zero-base=
d."

To my opinion std::bitset<size_t> can be compared to
std::tr1::array<typename, size_t> as the static analogon of
std::vector<bool> compared to std::vector<T !=3D bool>.
Another argument is, that std::bitset<size_t> has no compile-time=20
accessor for its template argument (The member function size() is a=20
runtime function).

I understand that their might exist dissenting votes to this proposals.
One major argument, I can think of, is that vector<bool> does not
fulfill the C++ Conatiner requirements, and I have to confess, that this
partially is true for std::bitset, too, concerning the tuple-interface,=20
namely that all other tuple classes do return **real** references to
the underlying tuple elements, while std::bitset<N> does not.

So a minimum proposal would be that there shall exist a specialization
tuple_size<bitset<size_t> >.

Greetings from Bremen,

Daniel Kr=FCgler

---
[ 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                       ]