58template <std::
size_t N>
69 for (std::size_t
i = 0;
i !=
N; ++
i)
75 for (std::size_t
i = 0;
i !=
N; ++
i)
82 const char*
bits ()
const {
87 for (std::size_t
i = 0;
i !=
N; ++
i)
94 for (std::size_t
i = 0;
i !=
N; ++
i)
100 for (std::size_t
i = 0;
i !=
N; ++
i)
106 for (std::size_t
i = 0;
i !=
N; ++
i)
112 for (std::size_t
i = 0;
i !=
N; ++
i)
118 for (std::size_t
i = 0;
i <
N -
n &&
i +
n + 1 <
N + 1; ++
i)
120 for (std::size_t
j =
N -
n;
j !=
N; ++
j)
126 for (std::size_t
i =
N - 1;
i !=
n - 1; --
i)
128 for (std::size_t
j =
n;
j != 0; )
134 for (std::size_t
i = 0;
i !=
N; ++
i)
145 for (std::size_t
i = 0;
i !=
N; ++
i)
159 for (std::size_t
i = 0;
i !=
N; ++
i)
171 for (std::size_t
i = 0;
i !=
N; ++
i)
177 for (std::size_t
i = 0;
i !=
N; ++
i)
209test_synopsis (std::bitset<0>*)
212 volatile bool dummy =
false;
217 typedef std::bitset<0> Bitset;
220 Bitset::reference *pr = (Bitset::reference*)0;
225#define MEMFUN(result, name, arg_list) do { \
226 result (Bitset::reference::*pf) arg_list = &Bitset::reference::name; \
227 _RWSTD_UNUSED (pf); \
233 MEMFUN (
bool,
operator~, ()
const);
234 MEMFUN (
bool,
operator bool, ()
const);
238#if (!defined (__SUNPRO_CC) || __SUNPRO_CC > 0x530) \
239 && (!defined (__GNUG__) || __GNUG__ >= 3)
248 (void)Bitset (std::string ());
249 (void)Bitset (std::string (), std::string::size_type ());
254#define MEMFUN(result, name, arg_list) do { \
255 result (Bitset::*pf) arg_list = &Bitset::name; \
256 _RWSTD_UNUSED (pf); \
259 MEMFUN (Bitset&,
operator&=, (
const Bitset&));
260 MEMFUN (Bitset&,
operator|=, (
const Bitset&));
261 MEMFUN (Bitset&,
operator^=, (
const Bitset&));
262 MEMFUN (Bitset&,
operator<<=, (std::size_t));
263 MEMFUN (Bitset&,
operator>>=, (std::size_t));
265 MEMFUN (Bitset&, set, ());
266 MEMFUN (Bitset&, set, (std::size_t,
bool));
269 MEMFUN (Bitset&, reset, ());
270 MEMFUN (Bitset&, reset, (std::size_t));
272 MEMFUN (Bitset,
operator~, ()
const);
273 MEMFUN (Bitset&, flip, ());
274 MEMFUN (Bitset&, flip, (std::size_t));
276 MEMFUN (Bitset::reference,
operator[], (std::size_t));
277 MEMFUN (
bool,
operator[], (std::size_t)
const);
279 MEMFUN (
unsigned long, to_ulong, ()
const);
281#if !defined (__HP_aCC) || __HP_aCC >= 60000
285# define PARAMLIST_3(T) T, std::char_traits<T>, std::allocator<T>
286# define PARAMLIST_2(T) T, std::char_traits<T>
295# ifndef _RWSTD_NO_WCHAR_T
313 MEMFUN (
bool,
operator==, (
const Bitset&)
const);
314 MEMFUN (
bool,
operator!=, (
const Bitset&)
const);
317 MEMFUN (
bool, any, ()
const);
318 MEMFUN (
bool, none, ()
const);
320 MEMFUN (Bitset,
operator>>, (std::size_t)
const);
321 MEMFUN (Bitset,
operator<<, (std::size_t)
const);
323#define FUN(result, name, arg_list) do { \
324 result (*pf) arg_list = &name; \
325 _RWSTD_UNUSED (pf); \
328#if !defined (__IBMCPP__) || __IBMCPP__ > 502
329 FUN (Bitset, std::operator&, (
const Bitset&,
const Bitset&));
330 FUN (Bitset, std::operator|, (
const Bitset&,
const Bitset&));
331 FUN (Bitset, std::operator^, (
const Bitset&,
const Bitset&));
336 FUN (Bitset, std::operator&,(
const Bitset&,
const Bitset&)
_PTR_THROWS(()));
337 FUN (Bitset, std::operator|,(
const Bitset&,
const Bitset&)
_PTR_THROWS(()));
338 FUN (Bitset, std::operator^,(
const Bitset&,
const Bitset&)
_PTR_THROWS(()));
342#define PARAMLIST(T) T, std::char_traits<T>
344 FUN (std::basic_istream<
PARAMLIST (
char) >&, std::operator>>,
345 (std::basic_istream<
PARAMLIST (
char) >&, Bitset&));
346 FUN (std::basic_ostream<
PARAMLIST (
char) >&, std::operator<<,
347 (std::basic_ostream<
PARAMLIST (
char) >&,
const Bitset&));
349#ifndef _RWSTD_NO_WCHAR_T
351 FUN (std::basic_istream<
PARAMLIST (
wchar_t) >&, std::operator>>,
352 (std::basic_istream<
PARAMLIST (
wchar_t) >&, Bitset&));
353 FUN (std::basic_ostream<
PARAMLIST (
wchar_t) >&, std::operator<<,
354 (std::basic_ostream<
PARAMLIST (
wchar_t) >&,
const Bitset&));
358#if !defined (_MSC_VER) || _MSC_VER > 1300
362 FUN (std::basic_istream<
PARAMLIST (
int) >&, std::operator>>,
363 (std::basic_istream<
PARAMLIST (
int) >&, Bitset&));
364 FUN (std::basic_ostream<
PARAMLIST (
int) >&, std::operator<<,
365 (std::basic_ostream<
PARAMLIST (
int) >&,
const Bitset&));
375template <std::
size_t N>
378 typedef unsigned long ULong;
382 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::bitset()",
N);
384 const std::bitset<N>
b;
386 "bitset<%zu>::bitset ().to_ulong() == 0, got %#lx",
391 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::bitset (unsigned long)",
N);
395 "bitset<%zu>::bitset (%#lx).to_ulong() == 0, got %#lx",
400 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::bitset (string)",
N);
406 const std::bitset<N>
b = std::bitset<N>(std::string (ts.
bits ()));
408 if (
N <=
sizeof (
unsigned long) *
CHAR_BIT)
410 "bitset<%zu>::bitset(string(\"%s\").to_ulong()"
411 " == %#x, got %#x",
N, ts.
bits (), bmask,
415 "bitset<%zu>::bitset(string(\"111...111\")"
416 " == 111...111, got %s",
426 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::bitset (const bitset&)",
N);
428 const std::bitset<N>
b1 (12345);
429 const std::bitset<N>
b2 (
b1);
432 "bitset<%zu>::bitset (bitset<%1$zu>(%#lx)).to_ulong() "
433 "== %#2$lx, got %#lx",
N,
b1.to_ulong (),
b2.to_ulong ());
436 "std::bitset<%zu>::operator=(const bitset&)",
N);
441 rw_assert (
b1.to_ulong () == b3.to_ulong (), 0, __LINE__,
442 "bitset<%zu>::bitset (bitset<%1$zu>(%#lx)).to_ulong() "
443 "== %#1$lx, got %#lx",
N,
b1.to_ulong (), b3.to_ulong ());
449template <std::
size_t N>
452 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::bitset (string)",
N);
454 const std::size_t max_mask =
bitmax (
N);
456 for (std::size_t
i = 0;
i != 1000U;
i++) {
458 typedef unsigned long ULong;
462 const std::bitset<N>
b1 (
n);
465 "bitset<%zu>::bitset(%#lx).to_ulong() == %#lx, got %#lx",
466 N,
n,
n,
b1.to_ulong ());
472 std::bitset<N>
b2 = std::bitset<N>(std::string (ts.
bits ()));
474 "bitset<%zu>::bitset (\"%s\") got %s",
475 N, ts.
bits (),
b2.to_string ().c_str ());
481template <std::
size_t N>
484#define TEST_OP(op) do { \
485 rw_info (!i, 0, __LINE__, "std::bitset<%zu>::operator" #op \
486 "= (const bitset&)", N); \
488 test_set<N> lhs = test_set<N>().random (); \
489 const test_set<N> rhs = test_set<N>().random (); \
490 std::bitset<N> b_lhs = std::bitset<N>(std::string (lhs.bits ()));\
491 const std::bitset<N> b_rhs = std::bitset<N>(std::string (rhs.bits ()));\
492 const test_set<N> res = lhs op ## = rhs; \
493 const std::bitset<N> b_res = b_lhs op ## = b_rhs; \
495 rw_assert (res == test_set<N>(b_res), 0, __LINE__, \
496 "bitset<%zu>::operator" #op "= (const bitset<%zu>&):" \
497 " %s " #op " %s == %s, got %s", \
498 N, N, lhs.bits (), rhs.bits (), res.bits (), \
499 test_set<N>(b_res).bits ()); \
501 rw_info (!i, 0, __LINE__, "std::bitset<%zu>::operator" #op \
502 " (const bitset&)", N); \
504 b_lhs = std::bitset<N>(std::string (lhs.bits ())); \
506 const test_set<N> res2 = lhs op ## = rhs; \
507 const std::bitset<N> b_res2 = b_lhs op b_rhs; \
509 rw_assert (res2 == test_set<N>(b_res2), 0, __LINE__, \
510 "bitset<%zu>::operator" #op " (const bitset<%zu>&):" \
511 " %s " #op " %s == %s, got %s", \
512 N, N, lhs.bits (), rhs.bits (), res2.bits (), \
513 test_set<N>(b_res2).bits ()); \
522 const std::size_t
M =
N + 1;
533 rw_info (!
i, 0, __LINE__,
"std::bitset<%zu>::operator<<=(size_t)",
N);
538 std::bitset<N>
b1 = std::bitset<N> (std::string (ts1.
bits ()));
544 "bitset<%zu>::operator<<=(%lu): %s << %lu == %s, got %s",
548 rw_info (!
i, 0, __LINE__,
"std::bitset<%zu>::operator>>=(size_t)",
N);
551 std::bitset<N>
b2 = std::bitset<N>(std::string (ts1.
bits ()));
557 "bitset<%zu>::operator>>=(%lu): %s >> %lu == %s, got %s",
562 "std::bitset<%zu>::operator<<=(size_t) (unused bits)",
N);
566 std::size_t first =
b1.count ();
567 std::size_t second = (
b1 <<= 1).
count ();
568 rw_assert (!(first == second), 0, __LINE__,
569 "bitset<%zu>::operator<<=(1): "
570 "after <<= 1: expected %lu, got %lu",
571 N, first - 1, second);
575 "std::bitset<%zu>::operator>>=(size_t) (unused bits)",
N);
579 std::size_t first =
b2.count ();
580 std::size_t second = (
b2 >>= 1).
count ();
581 rw_assert (first - 1 == second, 0, __LINE__,
582 "bitset<%zu>::operator>>=(1): "
583 "after >>= 1: expected %lu, got %lu",
584 N, first - 1, second);
591template <std::
size_t N>
594 for (std::size_t
i = 0;
i !=
NLOOPS; ++
i) {
602 std::bitset<N>
b1 = std::bitset<N>(std::string (ts1.
bits ()));
603 std::bitset<N>
b2 = ~b1;
606 "bitset<%zu>::operator~(): ~%s == %s, got %s",
612 "bitset<%zu>::flip (): ~%s == %s, got %s",
616 for (std::size_t _j = 0; _j !=
N; ++_j)
620 "bitset<%zu>::flip () == %s, got %s",
625 "bitset<%zu>::count () == %zu, got %d [%s]",
631 "bitset<%zu>::operator== (const bitset&) [%s]",
637 "bitset<%zu>::operator!= (const bitset&) [%s]",
643 "bitset<%zu>::any () [%s]",
649 "bitset<%zu>::none () [%s]",
652 for (std::size_t
k = 0;
k !=
N; ++
k) {
654 std::bitset<N> b3 =
b1 <<
k;
657 "bitset<%zu>::operator<< (%zu)",
N,
k);
663 "bitset<%zu>::operator>> (%zu)",
N,
k);
670template <std::
size_t N>
673 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::count()",
N);
675 for (std::size_t
i = 0;
i !=
N;
i++) {
678 for (std::size_t
j = 0;
j !=
i;
j++)
682 "%lu. std::bitset<%zu>::count()",
i,
N);
688template <std::
size_t N>
691 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::test(size_t)",
N);
692 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::operator[](size_t)",
N);
693 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::operator[](size_t) const",
N);
695 for (std::size_t
i = 0;
i !=
NLOOPS; ++
i) {
698 std::bitset<N>
b = std::bitset<N>(std::string (ts.
bits ()));
700 for (std::size_t _j = 0; _j !=
N; ++_j) {
703 "bitset<%zu>::test (%lu): %s",
708 "bitset<%zu>::operator[](%lu): %s",
714 "bitset<%zu>::operator[](%lu) const: %s",
718 typename std::bitset<N>::reference
r =
b [_j];
723 "bitset<%zu>::reference::flip()",
N);
728 "bitset<%zu>::reference::operator~()",
N);
734 "bitset<%zu>::reference::operator=(bool)",
N);
752#ifndef _RWSTD_NO_WCHAR_T
761template <
class charT>
764 static char name [64];
774template <
class charT>
777template <
class charT>
780 static char name [64];
785template <
class charT>
788 static char name [64];
793template <
class charT>
808template <
class charT>
811 const char*
const beg =
s;
813 for ( ; *
s; ++
s, ++
str) {
815 if (*
str != bits [
'1' == *
s])
816 return int (
s - beg);
819 return *
str ? int (
s - beg) : -1;
826 const char*
const beg =
s;
828 for (; *
s; ++
s, ++
str) {
830 if (
char (
str->c) != bits [
'1' == *
s])
831 return int (
s - beg);
834 return str->c ? int (
s - beg) : -1;
841template <std::
size_t N,
class charT,
class Traits,
class Alloc>
842std::basic_string<charT, Traits, Alloc>
845 std::basic_string<charT, Traits, Alloc>*)
850 return bs.template to_string<charT, Traits, Alloc>(
zero);
852 return bs.template to_string<charT, Traits, Alloc>();
855 return bs.template to_string<charT, Traits, Alloc>(
zero,
one);
858template <std::
size_t N,
class Traits,
class Alloc>
859std::basic_string<UserChar, Traits, Alloc>
862 std::basic_string<UserChar, Traits, Alloc>*)
865 static const UserChar dig[] = { { 0,
'0' }, { 0,
'1' } };
870 return bs.template to_string<UserChar, Traits, Alloc>(
zero, dig [1]);
872 return bs.template to_string<UserChar, Traits, Alloc>(dig [0], dig [1]);
875 return bs.template to_string<UserChar, Traits, Alloc>(
zero,
one);
881template <std::
size_t N,
class charT,
class Traits>
882std::basic_string<charT, Traits, std::allocator<charT> >
886 std::allocator<charT> >*)
891 return bs.template to_string<charT, Traits>(
zero);
893 return bs.template to_string<charT, Traits>();
896 return bs.template to_string<charT, Traits>(
zero,
one);
899template <std::
size_t N,
class Traits>
900std::basic_string<UserChar, Traits, std::allocator<UserChar> >
904 std::allocator<UserChar> >*)
906 static const UserChar dig[] = { { 0,
'0' }, { 0,
'1' } };
911 return bs.template to_string<UserChar, Traits>(
zero, dig [1]);
913 return bs.template to_string<UserChar, Traits>(dig [0], dig [1]);
916 return bs.template to_string<UserChar, Traits>(
zero,
one);
922template <std::
size_t N,
class charT>
923std::basic_string<charT, std::char_traits<charT>, std::allocator<charT> >
926 std::basic_string<
charT,
927 std::char_traits<charT>,
928 std::allocator<charT> >*)
933 return bs.template to_string<charT>(
zero);
935 return bs.template to_string<charT>();
938 return bs.template to_string<charT>(
zero,
one);
941template <std::
size_t N>
942std::basic_string<UserChar, std::char_traits<UserChar>,
943 std::allocator<UserChar> >
947 std::char_traits<UserChar>,
948 std::allocator<UserChar> >*)
951 static const UserChar dig[] = { { 0,
'0' }, { 0,
'1' } };
956 return bs.template to_string<UserChar>(
zero, dig [1]);
958 return bs.template to_string<UserChar>(dig [0], dig [1]);
961 return bs.template to_string<UserChar>(
zero,
one);
968template <std::
size_t N>
969std::basic_string<char, std::char_traits<char>, std::allocator<char> >
972 std::basic_string<
char, std::char_traits<char>,
973 std::allocator<char> >*)
978 return bs.to_string (
zero);
980 return bs.to_string ();
983 return bs.to_string (
zero,
one);
990#ifndef _RWSTD_NO_WCHAR_T
991inline char to_char (
wchar_t ch) {
return char (ch); }
996template <
class charT,
class Traits,
class Alloc>
1001 for (std::size_t
i = 0;
i !=
str.size (); ++
i)
1007#define TO_STR(s) narrow_string (s).c_str ()
1018 for (
i = 0;
str [
i]; ++
i)
1025template <std::
size_t N,
class charT,
class Traits,
class Alloc>
1027 bool nontemplate_done)
1034 "std::bitset<%zu>::to_string<%s, %s, %s >()",
1035 N, cname, tname, aname);
1041 const std::bitset<N> bs = ts.
to_bitset ();
1056 typedef std::basic_string<charT, Traits, Alloc> String3;
1066 "bitset<%zu>::to_string () == \"%s\", got \"%s\": "
1067 "mismatch at bit %d",
1074 "std::bitset<%zu>::to_string<%s, %s, %s >(\"%s\")",
1075 N, cname, tname, aname, cname);
1081 "bitset<%zu>::to_string ('o') == %s, got %s: "
1082 "mismatch at bit %d",
N,
1089 "std::bitset<%zu>::to_string<%s, %s, %s >(%s, %s)",
1090 N, cname, tname, aname, cname, cname);
1096 "bitset<%zu>::to_string ('o', 'x') == %s, got %s: "
1097 "mismatch at bit %d",
N,
1106 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::to_string<%s, %s >()",
1109 typedef std::allocator<charT> CharTAlloc;
1110 typedef std::basic_string<charT, Traits, CharTAlloc> String2;
1120 "bitset<%zu>::to_string () == %s, got %s: mismatch at bit %d",
1127 "std::bitset<%zu>::to_string<%s, %s >(%s)",
1128 N, cname, tname, cname);
1134 "bitset<%zu>::to_string ('o') == %s, got %s: "
1135 "mismatch at bit %d",
N,
1142 "std::bitset<%zu>::to_string<%s, %s >(%s, %s)",
1143 N, cname, tname, cname, cname);
1149 "bitset<%zu>::to_string ('o', 'x') == %s, got %s: "
1150 "mismatch at bit %d",
N,
1158 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::to_string<%s>()",
1162 typedef std::basic_string<charT, CharTraits, CharTAlloc> String1;
1172 "bitset<%zu>::to_string () == %s, got %s: mismatch at bit %d",
1178 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::to_string<%s>(%s)",
1185 "bitset<%zu>::to_string ('o') == %s, got %s: "
1186 "mismatch at bit %d",
N,
1193 "std::bitset<%zu>::to_string<%s>(%s, %s)",
1194 N, cname, cname, cname);
1200 "bitset<%zu>::to_string ('o', 'x') == %s, got %s: "
1201 "mismatch at bit %d",
N,
1209 if (nontemplate_done)
1212 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::to_string ()",
N);
1214 typedef std::string String0;
1224 "bitset<%zu>::to_string () == %s, got %s: mismatch at bit %d",
1225 N, ts.
bits (), str0.c_str (),
pos);
1230 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::to_string (char)",
N);
1236 "bitset<%zu>::to_string ('o') == %s, got %s: "
1237 "mismatch at bit %d",
N,
1239 str0.c_str (),
pos);
1243 rw_info (0, 0, __LINE__,
"std::bitset<%zu>::to_string (char, char)",
N);
1249 "bitset<%zu>::to_string ('o', 'x') == %s, got %s: "
1250 "mismatch at bit %d",
N,
1252 str0.c_str (),
pos);
1256template <std::
size_t N>
1261 (std::char_traits<char>*)0,
1262 (std::allocator<char>*)0,
1265#ifndef _RWSTD_NO_WCHAR_T
1269 (std::char_traits<wchar_t>*)0,
1270 (std::allocator<wchar_t>*)0,
1278 (std::allocator<UserChar>*)0,
1284template <std::
size_t N>
1302 test_synopsis ((std::bitset<0>*)0);
1304#define DO_TEST(N) run_test ((std::bitset<N>*)0)
1327#if !defined(_MSC_VER) || _MSC_VER != 1300
1343 return rw_test (argc, argv, __FILE__,
void count(T, T, const U &,...)
#define _PTR_THROWS(spec)
void test_to_string(std::bitset< N > *, charT *, Traits *, Alloc *, bool nontemplate_done)
const char * traits_name(const std::char_traits< charT > *)
void stress_ctors(const std::bitset< N > *)
void test_elem_access(const std::bitset< N > *)
void stress_count(const std::bitset< N > *)
void test_operators(const std::bitset< N > *)
std::basic_string< charT, Traits, Alloc > bitset_to_string_3(const std::bitset< N > &bs, int nfargs, charT zero, charT one, std::basic_string< charT, Traits, Alloc > *)
void is_explicit(const std::bitset< 0 > &)
const char * alloc_name(const std::allocator< charT > &)
std::string narrow_string(const std::basic_string< charT, Traits, Alloc > &str)
#define FUN(result, name, arg_list)
#define MEMFUN(result, name, arg_list)
std::basic_string< char, std::char_traits< char >, std::allocator< char > > bitset_to_string_0(const std::bitset< N > &bs, int nfargs, char zero, char one, std::basic_string< char, std::char_traits< char >, std::allocator< char > > *)
std::basic_string< charT, Traits, std::allocator< charT > > bitset_to_string_2(const std::bitset< N > &bs, int nfargs, charT zero, charT one, std::basic_string< charT, Traits, std::allocator< charT > > *)
void test_other(const std::bitset< N > *)
void run_test(const std::bitset< N > *)
std::basic_string< charT, std::char_traits< charT >, std::allocator< charT > > bitset_to_string_1(const std::bitset< N > &bs, int nfargs, charT zero, charT one, std::basic_string< charT, std::char_traits< charT >, std::allocator< charT > > *)
std::size_t bitmax(std::size_t n)
std::string to_string(const char *str, const char bits[2])
std::char_traits< S > Traits
#define _RWSTD_SPECIALIZED_CLASS
#define _RWSTD_UNUSED(arg)
#define _RWSTD_STATIC_CAST(T, x)
#define _RWSTD_NAMESPACE(name)
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
has_implicit_ctor(const std::string &)
const char * bits() const
bool test(std::size_t pos) const
test_set operator~() const
bool operator==(const test_set &rhs) const
std::bitset< N > to_bitset() const
test_set & set(std::size_t pos, bool val)
test_set & operator|=(const test_set &rhs)
test_set(unsigned long val)
test_set & operator^=(const test_set &rhs)
test_set & operator<<=(std::size_t n)
test_set & flip(std::size_t pos)
std::size_t count() const
test_set(const std::bitset< N > &rhs)
test_set & operator&=(const test_set &rhs)
test_set & operator>>=(std::size_t n)
test_set & reset(std::size_t pos)