Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
23.bitset.cpp
Go to the documentation of this file.
1
29#include <bitset>
30#include <istream>
31#include <ostream>
32
33#include <cstdio> // for sprintf()
34#include <climits>
35
36#include <rw_char.h> // for UserChar
37#include <rw_rand.h> // for rw_rand()
38#include <rw_driver.h> // for rw_test(), ...
39
40
41#define NLOOPS 128
42
43
45// sets the `n' least significant bits
46std::size_t
47bitmax (std::size_t n)
48{
49 std::size_t result = 0;
50 while (n--)
51 result = result << 1 | 1U;
52 return result;
53}
54
55
57// fake bitset class, bit pattern represented as a character string
58template <std::size_t N>
60{
61 char bits_ [N + 1];
62
64 reset ();
65 bits_ [N] = '\0'; // null-terminate
66 }
67
68 explicit test_set (unsigned long val) {
69 for (std::size_t i = 0; i != N; ++i)
70 set (i, !!(val & (1UL << i)));
71 bits_ [N] = '\0'; // NUL-terminate
72 }
73
74 explicit test_set (const std::bitset<N> &rhs) {
75 for (std::size_t i = 0; i != N; ++i)
76 set (i, rhs.test (i));
77 bits_ [N] = '\0'; // NUL-terminate
78 }
79
80 // accessor function provided to work around
81 // a MIPSpro 7.3.1.1 bug (PR #25682)
82 const char* bits () const {
83 return bits_;
84 }
85
87 for (std::size_t i = 0; i != N; ++i)
88 bits_ [i] = char ('0' + rw_rand (2U));
89 return *this;
90 }
91
92 std::bitset<N> to_bitset () const {
93 std::bitset<N> tmp;
94 for (std::size_t i = 0; i != N; ++i)
95 tmp.set (i, test (i));
96 return tmp;
97 }
98
100 for (std::size_t i = 0; i != N; ++i)
101 bits_ [i] = '0' + ('1' == bits_ [i] && '1' == rhs.bits_ [i]);
102 return *this;
103 }
104
106 for (std::size_t i = 0; i != N; ++i)
107 bits_ [i] = '0' + ('1' == bits_ [i] || '1' == rhs.bits_ [i]);
108 return *this;
109 }
110
112 for (std::size_t i = 0; i != N; ++i)
113 bits_ [i] = '0' + !!(bits_ [i] - rhs.bits_ [i]);
114 return *this;
115 }
116
117 test_set& operator<<= (std::size_t n) {
118 for (std::size_t i = 0; i < N - n && i + n + 1 < N + 1; ++i)
119 bits_ [i] = bits_ [i + n];
120 for (std::size_t j = N - n; j != N; ++j)
121 bits_ [j] = '0';
122 return *this;
123 }
124
125 test_set& operator>>= (std::size_t n) {
126 for (std::size_t i = N - 1; i != n - 1; --i)
127 bits_ [i] = bits_ [i - n];
128 for (std::size_t j = n; j != 0; )
129 bits_ [--j] = '0';
130 return *this;
131 }
132
134 for (std::size_t i = 0; i != N; ++i)
135 bits_ [i] = '1';
136 return *this;
137 }
138
139 test_set& set (std::size_t pos, bool val) {
140 bits_ [N - pos - 1] = '0' + val;
141 return *this;
142 }
143
145 for (std::size_t i = 0; i != N; ++i)
146 bits_ [i] = '0';
147 return *this;
148 }
149
150 test_set& reset (std::size_t pos) {
151 return bits_ [N - pos - 1] = '0', *this;
152 }
153
155 return test_set (*this).flip ();
156 }
157
159 for (std::size_t i = 0; i != N; ++i)
160 bits_ [i] = '0' + ('0' == bits_ [i]);
161 return *this;
162 }
163
164 test_set& flip (std::size_t pos) {
165 bits_ [N - pos - 1] = '0' + ('0' == bits_ [N - pos - 1]);
166 return *this;
167 }
168
169 std::size_t count () const {
170 std::size_t n = 0;
171 for (std::size_t i = 0; i != N; ++i)
172 n += bits_ [i] != '0';
173 return n;
174 }
175
176 bool operator== (const test_set &rhs) const {
177 for (std::size_t i = 0; i != N; ++i)
178 if (bits_ [i] != rhs.bits_ [i])
179 return false;
180 return true;
181 }
182
183 bool test (std::size_t pos) const {
184 return '0' != bits_ [N - pos - 1];
185 }
186};
187
188
190// helper to verify that bitset ctor is explicit
191// not defined since it must not be referenced if test is successful
192// static commented out to prevent gcc warning: function declared
193// 'static' but never defined
194/* static */ void
195is_explicit (const std::bitset<0>&);
196
198{
199 // NOT explicit
200 has_implicit_ctor (const std::string&) { }
201};
202
203// calls to the overloaded is_explicit() resolve to the function below
204static void
206
207
208static void
209test_synopsis (std::bitset<0>*)
210{
211 // prevent warnings about unreachable code
212 volatile bool dummy = false;
213
214 if (!dummy)
215 return;
216
217 typedef std::bitset<0> Bitset;
218 typedef Bitset::reference Reference;
219
220 Bitset::reference *pr = (Bitset::reference*)0;
221 _RWSTD_UNUSED (pr);
222
223// verify that a member function is accessible and has the appropriate
224// signature, including return type and exception specification
225#define MEMFUN(result, name, arg_list) do { \
226 result (Bitset::reference::*pf) arg_list = &Bitset::reference::name; \
227 _RWSTD_UNUSED (pf); \
228 } while (0)
229
230 // exercise bitset::reference members
231 MEMFUN (Reference&, operator=, (bool));
232 MEMFUN (Reference&, operator=, (const Reference&));
233 MEMFUN (bool, operator~, () const);
234 MEMFUN (bool, operator bool, () const);
235 MEMFUN (Reference&, flip, ());
236
237 // 23.3.5.1 - verify bitset ctors
238#if (!defined (__SUNPRO_CC) || __SUNPRO_CC > 0x530) \
239 && (!defined (__GNUG__) || __GNUG__ >= 3)
240 // working around a SunPro 5.2 bug (see PR #25959)
241
242 // verify that bitset ctor is declared explicit
243 is_explicit (std::string ());
244
245#endif // SunPro > 5.3
246
247 // verify default arguments
248 (void)Bitset (std::string ());
249 (void)Bitset (std::string (), std::string::size_type ());
250
251// verify that a member function is accessible and has the appropriate
252// signature, including return type and exception specification
253#undef MEMFUN
254#define MEMFUN(result, name, arg_list) do { \
255 result (Bitset::*pf) arg_list = &Bitset::name; \
256 _RWSTD_UNUSED (pf); \
257 } while (0)
258
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));
264
265 MEMFUN (Bitset&, set, ());
266 MEMFUN (Bitset&, set, (std::size_t, bool)); // lwg issue 186
267 Bitset ().set (0); // verify default argument
268
269 MEMFUN (Bitset&, reset, ());
270 MEMFUN (Bitset&, reset, (std::size_t));
271
272 MEMFUN (Bitset, operator~, () const);
273 MEMFUN (Bitset&, flip, ());
274 MEMFUN (Bitset&, flip, (std::size_t));
275
276 MEMFUN (Bitset::reference, operator[], (std::size_t));
277 MEMFUN (bool, operator[], (std::size_t) const);
278
279 MEMFUN (unsigned long, to_ulong, () const);
280
281#if !defined (__HP_aCC) || __HP_aCC >= 60000
282
283 // working around HP aCC bugs PR #23312 and bug #503
284
285# define PARAMLIST_3(T) T, std::char_traits<T>, std::allocator<T>
286# define PARAMLIST_2(T) T, std::char_traits<T>
287
288 // exercise the overloaded member template function and ordinary
289 // member function to_string()
290 MEMFUN (std::basic_string<PARAMLIST_3 (char) >,
291 to_string<PARAMLIST_3 (char) >, (char, char) const);
292 MEMFUN (std::basic_string<PARAMLIST_3 (char) >,
293 to_string, (char, char) const);
294
295# ifndef _RWSTD_NO_WCHAR_T
296
297 MEMFUN (std::basic_string<PARAMLIST_3 (wchar_t) >,
298 to_string<PARAMLIST_3 (wchar_t) >, (wchar_t, wchar_t) const);
299
300# endif // _RWSTD_NO_WCHAR_T
301
302 MEMFUN (std::basic_string<PARAMLIST_3 (int) >,
303 to_string<PARAMLIST_3 (int) >, (int, int) const);
304
305# undef PARAMLIST_3
306# undef PARAMLIST_2
307
308#endif // !__HP_aCC || __HP_aCC >= 60000
309
310 MEMFUN (std::size_t, size, () const);
311 MEMFUN (std::size_t, count, () const);
312
313 MEMFUN (bool, operator==, (const Bitset&) const);
314 MEMFUN (bool, operator!=, (const Bitset&) const);
315
316 MEMFUN (bool, test, (std::size_t) const);
317 MEMFUN (bool, any, () const);
318 MEMFUN (bool, none, () const);
319
320 MEMFUN (Bitset, operator>>, (std::size_t) const);
321 MEMFUN (Bitset, operator<<, (std::size_t) const);
322
323#define FUN(result, name, arg_list) do { \
324 result (*pf) arg_list = &name; \
325 _RWSTD_UNUSED (pf); \
326 } while (0)
327
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&));
332
333#else
334 // working around xlC 5.0.2.0 bug: PR #26561
335
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(()));
339#endif
340
341
342#define PARAMLIST(T) T, std::char_traits<T>
343
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&));
348
349#ifndef _RWSTD_NO_WCHAR_T
350
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&));
355
356#endif // _RWSTD_NO_WCHAR_T
357
358#if !defined (_MSC_VER) || _MSC_VER > 1300
359
360 // MSVC is too dumb to handle bitset inserters and extractors
361 // parametrized on multiple template paramenters
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&));
366
367#endif // !defined (_MSC_VER) || _MSC_VER > 1300
368
369#undef PARAMLIST
370
371}
372
373
375template <std::size_t N>
376void test_ctors (const std::bitset<N>*)
377{
378 typedef unsigned long ULong;
379 const ULong bmask = ULong (::bitmax (N));
380
381 { // bitset::bitset()
382 rw_info (0, 0, __LINE__, "std::bitset<%zu>::bitset()", N);
383
384 const std::bitset<N> b;
385 rw_assert (0 == b.to_ulong (), 0, __LINE__,
386 "bitset<%zu>::bitset ().to_ulong() == 0, got %#lx",
387 b.to_ulong ());
388 }
389
390 { // bitset::bitset (unsigned long)
391 rw_info (0, 0, __LINE__, "std::bitset<%zu>::bitset (unsigned long)", N);
392
393 const std::bitset<N> b (ULONG_MAX & bmask);
394 rw_assert ((ULONG_MAX & bmask) == b.to_ulong (), 0, __LINE__,
395 "bitset<%zu>::bitset (%#lx).to_ulong() == 0, got %#lx",
396 N, ULONG_MAX & bmask, b.to_ulong ());
397 }
398
399 { // bitset (const string& str, size_t pos = 0, size_t n = (size_t)-1);
400 rw_info (0, 0, __LINE__, "std::bitset<%zu>::bitset (string)", N);
401
402 test_set<N> ts;
403 ts.set ();
404
405 _TRY {
406 const std::bitset<N> b = std::bitset<N>(std::string (ts.bits ()));
407
408 if (N <= sizeof (unsigned long) * CHAR_BIT)
409 rw_assert (b == bmask, 0, __LINE__,
410 "bitset<%zu>::bitset(string(\"%s\").to_ulong()"
411 " == %#x, got %#x", N, ts.bits (), bmask,
412 b.to_ulong ());
413 else
414 rw_assert (test_set<N>(b) == ts, 0, __LINE__,
415 "bitset<%zu>::bitset(string(\"111...111\")"
416 " == 111...111, got %s",
417 N, test_set<N>(b).bits ());
418
419 }
420 _CATCH (...) {
421 rw_assert (false, 0, __LINE__, (""));
422 }
423 }
424
425 { // bitset (const bitset<N>& rhs)
426 rw_info (0, 0, __LINE__, "std::bitset<%zu>::bitset (const bitset&)", N);
427
428 const std::bitset<N> b1 (12345);
429 const std::bitset<N> b2 (b1);
430
431 rw_assert (b1.to_ulong () == b2.to_ulong (), 0, __LINE__,
432 "bitset<%zu>::bitset (bitset<%1$zu>(%#lx)).to_ulong() "
433 "== %#2$lx, got %#lx", N, b1.to_ulong (), b2.to_ulong ());
434
435 rw_info (0, 0, __LINE__,
436 "std::bitset<%zu>::operator=(const bitset&)", N);
437
438 std::bitset<N> b3;
439 b3 = b1;
440
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 ());
444 }
445}
446
447
449template <std::size_t N>
450void stress_ctors (const std::bitset<N>*)
451{
452 rw_info (0, 0, __LINE__, "std::bitset<%zu>::bitset (string)", N);
453
454 const std::size_t max_mask = bitmax (N);
455
456 for (std::size_t i = 0; i != 1000U; i++) {
457
458 typedef unsigned long ULong;
459
460 // exercise 23.3.5.1, p2
461 const ULong n = ULong (rw_rand (0) & max_mask);
462 const std::bitset<N> b1 (n);
463
464 rw_assert (n == b1.to_ulong (), 0, __LINE__,
465 "bitset<%zu>::bitset(%#lx).to_ulong() == %#lx, got %#lx",
466 N, n, n, b1.to_ulong ());
467
468 test_set<N> ts;
469 ts.random ();
470
471 // exercise 23.3.5.1, p3
472 std::bitset<N> b2 = std::bitset<N>(std::string (ts.bits ()));
473 rw_assert (test_set<N>(b2) == ts, 0, __LINE__,
474 "bitset<%zu>::bitset (\"%s\") got %s",
475 N, ts.bits (), b2.to_string ().c_str ());
476 }
477}
478
479
481template <std::size_t N>
482void test_operators (const std::bitset<N>*)
483{
484#define TEST_OP(op) do { \
485 rw_info (!i, 0, __LINE__, "std::bitset<%zu>::operator" #op \
486 "= (const bitset&)", N); \
487 \
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; \
494 \
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 ()); \
500 \
501 rw_info (!i, 0, __LINE__, "std::bitset<%zu>::operator" #op \
502 " (const bitset&)", N); \
503 lhs.random (); \
504 b_lhs = std::bitset<N>(std::string (lhs.bits ())); \
505 \
506 const test_set<N> res2 = lhs op ## = rhs; \
507 const std::bitset<N> b_res2 = b_lhs op b_rhs; \
508 \
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 ()); \
514 } while (0)
515
516 // prevent division by zero errors, also exercise shifting by
517 // N bits (operation must zero out the first operand)
518 // especially important is shifting bitset<N> by N bits where
519 // N >= sizeof (unsigned long) * CHAR_BIT, since this operation
520 // is undefined for unsigned longs but defined for bitset
521
522 const std::size_t M = N + 1;
523
524 for (int i = 0; i != NLOOPS; ++i) {
525
526 // 23.3.5.2, p1 and 23.3.5.3, p1
527 TEST_OP (&);
528 // 23.3.5.2, p3 and 23.3.5.3, p2
529 TEST_OP (|);
530 // 23.3.5.2, p5 and 23.3.5.3, p3
531 TEST_OP (^);
532
533 rw_info (!i, 0, __LINE__, "std::bitset<%zu>::operator<<=(size_t)", N);
534
535 const test_set<N> ts1 = test_set<N>().random ();
536 const test_set<N> ts2 = test_set<N>(ts1) <<= i % M;
537
538 std::bitset<N> b1 = std::bitset<N> (std::string (ts1.bits ()));
539
540 // 23.3.5.2, p7
541 b1 <<= i % M;
542
543 rw_assert (test_set<N>(b1) == ts2, 0, __LINE__,
544 "bitset<%zu>::operator<<=(%lu): %s << %lu == %s, got %s",
545 N, i % M, ts1.bits (), i % M, ts2.bits (),
546 test_set<N>(b1).bits ());
547
548 rw_info (!i, 0, __LINE__, "std::bitset<%zu>::operator>>=(size_t)", N);
549
550 const test_set<N> ts3 = test_set<N>(ts1) >>= i % M;
551 std::bitset<N> b2 = std::bitset<N>(std::string (ts1.bits ()));
552
553 // 23.3.5.2, p9
554 b2 >>= i % M;
555
556 rw_assert (test_set<N>(b2) == ts3, 0, __LINE__,
557 "bitset<%zu>::operator>>=(%lu): %s >> %lu == %s, got %s",
558 N, i % M, ts1.bits (), i % M, ts3.bits (),
559 test_set<N>(b2).bits ());
560
561 rw_info (!i, 0, __LINE__,
562 "std::bitset<%zu>::operator<<=(size_t) (unused bits)", N);
563
564 if (N) {
565 b1.set (N - 1);
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);
572 }
573
574 rw_info (!i, 0, __LINE__,
575 "std::bitset<%zu>::operator>>=(size_t) (unused bits)", N);
576
577 if (N) {
578 b2.set ();
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);
585 }
586 }
587}
588
589
591template <std::size_t N>
592void test_other (const std::bitset<N>*)
593{
594 for (std::size_t i = 0; i != NLOOPS; ++i) {
595
596 // 23.3.5.2, p23
597 test_set<N> ts1;
598 ts1.random ();
599
600 test_set<N> ts2 = ~ts1;
601
602 std::bitset<N> b1 = std::bitset<N>(std::string (ts1.bits ()));
603 std::bitset<N> b2 = ~b1;
604
605 rw_assert (ts2 == test_set<N>(b2), 0, __LINE__,
606 "bitset<%zu>::operator~(): ~%s == %s, got %s",
607 N, ts1.bits (), ts2.bits (), test_set<N>(b2).bits ());
608
609 // 23.3.5.2, p25
610 b2.flip ();
611 rw_assert (ts1 == test_set<N>(b2), 0, __LINE__,
612 "bitset<%zu>::flip (): ~%s == %s, got %s",
613 N, ts1.bits (), ts2.bits (), test_set<N>(b2).bits ());
614
615 // 23.3.5.2, p27
616 for (std::size_t _j = 0; _j != N; ++_j)
617 b2.flip (_j);
618
619 rw_assert (ts2 == test_set<N>(b2), 0, __LINE__,
620 "bitset<%zu>::flip () == %s, got %s",
621 N, ts2.bits (), test_set<N>(b2).bits ());
622
623 // 23.3.5.3, p35
624 rw_assert (ts2.count () == b2.count (), 0, __LINE__,
625 "bitset<%zu>::count () == %zu, got %d [%s]",
626 N, ts2.count (), b2.count (), test_set<N>(b2).bits());
627
628 // 23.3.5.3, p37
629 rw_assert (b2 == b2 && ((N && !(b1 == b2)) || (!N && b1 == b2)),
630 0, __LINE__,
631 "bitset<%zu>::operator== (const bitset&) [%s]",
632 N, N ? test_set<N>(b2).bits () : "<empty>");
633
634 // 23.3.5.3, p38
635 rw_assert ((N && b1 != b2) || (!N && !(b1 != b2) && !(b2 != b2)),
636 0, __LINE__,
637 "bitset<%zu>::operator!= (const bitset&) [%s]",
638 N, N ? test_set<N>(b2).bits () : "<empty>");
639
640 // 23.3.5.3, p42
641 rw_assert ((b2.count () && b2.any ()) || (!b2.count () && !b2.any ()),
642 0, __LINE__,
643 "bitset<%zu>::any () [%s]",
644 N, test_set<N>(b2).bits ());
645
646 // 23.3.5.3, p43
647 rw_assert ((b2.count () && !b2.none ()) || (!b2.count () && b2.none ()),
648 0, __LINE__,
649 "bitset<%zu>::none () [%s]",
650 N, test_set<N>(b2).bits ());
651
652 for (std::size_t k = 0; k != N; ++k) {
653 test_set<N> ts3 = test_set<N>(ts1) <<= k;
654 std::bitset<N> b3 = b1 << k;
655
656 rw_assert (test_set<N>(b3) == ts3, 0, __LINE__,
657 "bitset<%zu>::operator<< (%zu)", N, k);
658
659 ts3 = test_set<N>(ts1) >>= k;
660 b3 = b1 >> k;
661
662 rw_assert (test_set<N>(b3) == ts3, 0, __LINE__,
663 "bitset<%zu>::operator>> (%zu)", N, k);
664 }
665 }
666}
667
668
670template <std::size_t N>
671void stress_count (const std::bitset<N>*)
672{
673 rw_info (0, 0, __LINE__, "std::bitset<%zu>::count()", N);
674
675 for (std::size_t i = 0; i != N; i++) {
676 std::bitset<N> b;
677
678 for (std::size_t j = 0; j != i; j++)
679 b.set (j);
680
681 rw_assert (b.count () == i, 0, __LINE__,
682 "%lu. std::bitset<%zu>::count()", i, N);
683 }
684}
685
686
688template <std::size_t N>
689void test_elem_access (const std::bitset<N>*)
690{
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);
694
695 for (std::size_t i = 0; i != NLOOPS; ++i) {
696
697 const test_set<N> ts = test_set<N>().random ();
698 std::bitset<N> b = std::bitset<N>(std::string (ts.bits ()));
699
700 for (std::size_t _j = 0; _j != N; ++_j) {
701 // 23.3.5.2, p39
702 rw_assert (b.test (_j) == ts.test (_j), 0, __LINE__,
703 "bitset<%zu>::test (%lu): %s",
704 N, _j, test_set<N>(b).bits ());
705
706 // 23.3.5.2, p??: see lwg issue 11
707 rw_assert (b [_j] == ts.test (_j), 0, __LINE__,
708 "bitset<%zu>::operator[](%lu): %s",
709 N, _j, test_set<N>(b).bits ());
710
711 // 23.3.5.2, p??: see lwg issue 11
712 rw_assert (((const std::bitset<N>&)b) [_j] == ts.test (_j),
713 0, __LINE__,
714 "bitset<%zu>::operator[](%lu) const: %s",
715 N, _j, test_set<N>(b).bits ());
716
717 // exercise std::bitset<N>::reference
718 typename std::bitset<N>::reference r = b [_j];
719
720 // std::bitset<N>::reference::flip()
721 r.flip ();
722 rw_assert (r == !ts.test (_j), 0, __LINE__,
723 "bitset<%zu>::reference::flip()", N);
724
725 // std::bitset<N>::reference::operator~()
726 bool toggled = ~r;
727 rw_assert (toggled == ts.test (_j), 0, __LINE__,
728 "bitset<%zu>::reference::operator~()", N);
729
730 // std::bitset<N>::reference::operator=(bool)
731 r = toggled;
732 rw_assert (r == ts.test (_j) && b.test (_j) == ts.test (_j),
733 0, __LINE__,
734 "bitset<%zu>::reference::operator=(bool)", N);
735 }
736 }
737}
738
739
740
743
745struct char_traits<UserChar>: UserTraits<UserChar> { };
746
747} // namespace std
748
749
750const char* type_name (char) { return "char"; }
751
752#ifndef _RWSTD_NO_WCHAR_T
753const char* type_name (wchar_t) { return "wchar_t"; }
754#endif // _RWSTD_NO_WCHAR_T
755
756const char* type_name (const UserChar&)
757{
758 return "UserChar";
759}
760
761template <class charT>
762const char* traits_name (const std::char_traits<charT>*)
763{
764 static char name [64];
765 std::sprintf (name, "std::char_traits<%s>", type_name (charT ()));
766 return name;
767}
768
770{
771 return "UserTraits";
772}
773
774template <class charT>
775struct MyAlloc: std::allocator<charT> { };
776
777template <class charT>
778const char* alloc_name (const std::allocator<charT>&)
779{
780 static char name [64];
781 std::sprintf (name, "std::allocator<%s>", type_name (charT ()));
782 return name;
783}
784
785template <class charT>
786const char* alloc_name (const MyAlloc<charT>&)
787{
788 static char name [64];
789 std::sprintf (name, "MyAlloc<%s>", type_name (charT ()));
790 return name;
791}
792
793template <class charT>
795{
796 return lhs = rhs;
797}
798
800{
801 lhs.c = _RWSTD_STATIC_CAST (unsigned char, rhs);
802
803 return lhs;
804}
805
806// compare two strings, return the offset of the first mismatch
807// or -1 when the strings are equal
808template <class charT>
809int compare (const charT str[], const char s[], const char bits [2])
810{
811 const char* const beg = s;
812
813 for ( ; *s; ++s, ++str) {
814
815 if (*str != bits ['1' == *s])
816 return int (s - beg);
817 }
818
819 return *str ? int (s - beg) : -1;
820}
821
822// compare two strings, return the offset of the first mismatch
823// or -1 when the strings are equal
824int compare (const UserChar str[], const char s[], const char bits [2])
825{
826 const char* const beg = s;
827
828 for (; *s; ++s, ++str) {
829
830 if (char (str->c) != bits ['1' == *s])
831 return int (s - beg);
832 }
833
834 return str->c ? int (s - beg) : -1;
835}
836
837
838// call the bitset<N>::to_string() member function template,
839// explicitly specifying all three template arguments,
840// and 2, 1, or 0 of the two default function arguments
841template <std::size_t N, class charT, class Traits, class Alloc>
842std::basic_string<charT, Traits, Alloc>
843bitset_to_string_3 (const std::bitset<N> &bs, int nfargs,
845 std::basic_string<charT, Traits, Alloc>*)
846{
847 // invoke to_string with the number of function arguments specified
848 switch (nfargs) {
849 case 1:
850 return bs.template to_string<charT, Traits, Alloc>(zero);
851 case 0:
852 return bs.template to_string<charT, Traits, Alloc>();
853 }
854
855 return bs.template to_string<charT, Traits, Alloc>(zero, one);
856}
857
858template <std::size_t N, class Traits, class Alloc>
859std::basic_string<UserChar, Traits, Alloc>
860bitset_to_string_3 (const std::bitset<N> &bs, int nfargs,
862 std::basic_string<UserChar, Traits, Alloc>*)
863{
864 // UserChar digits zero and one
865 static const UserChar dig[] = { { 0, '0' }, { 0, '1' } };
866
867 // invoke to_string with the number of function arguments specified
868 switch (nfargs) {
869 case 1:
870 return bs.template to_string<UserChar, Traits, Alloc>(zero, dig [1]);
871 case 0:
872 return bs.template to_string<UserChar, Traits, Alloc>(dig [0], dig [1]);
873 }
874
875 return bs.template to_string<UserChar, Traits, Alloc>(zero, one);
876}
877
878// call the bitset<N>::to_string() member function template,
879// explicitly specifying two of the three template arguments,
880// and 2, 1, or 0 of the two default function arguments
881template <std::size_t N, class charT, class Traits>
882std::basic_string<charT, Traits, std::allocator<charT> >
883bitset_to_string_2 (const std::bitset<N> &bs, int nfargs,
885 std::basic_string<charT, Traits,
886 std::allocator<charT> >*)
887{
888 // invoke to_string with the number of function arguments specified
889 switch (nfargs) {
890 case 1:
891 return bs.template to_string<charT, Traits>(zero);
892 case 0:
893 return bs.template to_string<charT, Traits>();
894 }
895
896 return bs.template to_string<charT, Traits>(zero, one);
897}
898
899template <std::size_t N, class Traits>
900std::basic_string<UserChar, Traits, std::allocator<UserChar> >
901bitset_to_string_2 (const std::bitset<N> &bs, int nfargs,
903 std::basic_string<UserChar, Traits,
904 std::allocator<UserChar> >*)
905{
906 static const UserChar dig[] = { { 0, '0' }, { 0, '1' } };
907
908 // invoke to_string with the number of function arguments specified
909 switch (nfargs) {
910 case 1:
911 return bs.template to_string<UserChar, Traits>(zero, dig [1]);
912 case 0:
913 return bs.template to_string<UserChar, Traits>(dig [0], dig [1]);
914 }
915
916 return bs.template to_string<UserChar, Traits>(zero, one);
917}
918
919// call the bitset<N>::to_string() member function template,
920// explicitly specifying one of the three template arguments,
921// and 2, 1, or 0 of the two default function arguments
922template <std::size_t N, class charT>
923std::basic_string<charT, std::char_traits<charT>, std::allocator<charT> >
924bitset_to_string_1 (const std::bitset<N> &bs, int nfargs,
926 std::basic_string<charT,
927 std::char_traits<charT>,
928 std::allocator<charT> >*)
929{
930 // invoke to_string with the number of function arguments specified
931 switch (nfargs) {
932 case 1:
933 return bs.template to_string<charT>(zero);
934 case 0:
935 return bs.template to_string<charT>();
936 }
937
938 return bs.template to_string<charT>(zero, one);
939}
940
941template <std::size_t N>
942std::basic_string<UserChar, std::char_traits<UserChar>,
943 std::allocator<UserChar> >
944bitset_to_string_1 (const std::bitset<N> &bs, int nfargs,
946 std::basic_string<UserChar,
947 std::char_traits<UserChar>,
948 std::allocator<UserChar> >*)
949{
950 // UserChar digits zero and one
951 static const UserChar dig[] = { { 0, '0' }, { 0, '1' } };
952
953 // invoke to_string with the number of function arguments specified
954 switch (nfargs) {
955 case 1:
956 return bs.template to_string<UserChar>(zero, dig [1]);
957 case 0:
958 return bs.template to_string<UserChar>(dig [0], dig [1]);
959 }
960
961 return bs.template to_string<UserChar>(zero, one);
962}
963
964
965// call the bitset<N>::to_string() ordinary member function,
966// explicitly specifying none of the three template arguments,
967// and 2, 1, or 0 of the two default function arguments
968template <std::size_t N>
969std::basic_string<char, std::char_traits<char>, std::allocator<char> >
970bitset_to_string_0 (const std::bitset<N> &bs, int nfargs,
971 char zero, char one,
972 std::basic_string<char, std::char_traits<char>,
973 std::allocator<char> >*)
974{
975 // invoke to_string with the number of function arguments specified
976 switch (nfargs) {
977 case 1:
978 return bs.to_string (zero);
979 case 0:
980 return bs.to_string ();
981 }
982
983 return bs.to_string (zero, one);
984}
985
986
987inline char to_char (char ch) { return ch; }
988inline char to_char (UserChar ch) { return ch.c; }
989
990#ifndef _RWSTD_NO_WCHAR_T
991inline char to_char (wchar_t ch) { return char (ch); }
992#endif // _RWSTD_NO_WCHAR_T
993
994
995// convert a basic_string object to a tempstr object for diagnostics
996template <class charT, class Traits, class Alloc>
997std::string narrow_string (const std::basic_string<charT, Traits, Alloc> &str)
998{
999 std::string res;
1000
1001 for (std::size_t i = 0; i != str.size (); ++i)
1002 res += to_char (str [i]);
1003
1004 return res;
1005}
1006
1007#define TO_STR(s) narrow_string (s).c_str ()
1008
1009
1010// convert an ordinary string to a tempstr object for diagnostics
1011// using the binary digits specified by `bits'
1012std::string to_string (const char *str, const char bits [2])
1013{
1014 std::string res;
1015
1016 std::size_t i;
1017
1018 for (i = 0; str [i]; ++i)
1019 res += bits ['1' == str [i]];
1020
1021 return res;
1022}
1023
1024
1025template <std::size_t N, class charT, class Traits, class Alloc>
1026void test_to_string (std::bitset<N>*, charT*, Traits*, Alloc*,
1027 bool nontemplate_done)
1028{
1029 static const char* const cname = type_name (charT ());
1030 static const char* const tname = traits_name ((Traits*)0);
1031 static const char* const aname = alloc_name (Alloc ());
1032
1033 rw_info (0, 0, __LINE__,
1034 "std::bitset<%zu>::to_string<%s, %s, %s >()",
1035 N, cname, tname, aname);
1036
1037 test_set<N> ts;
1038
1039 ts.random ();
1040
1041 const std::bitset<N> bs = ts.to_bitset ();
1042
1043 charT zero;
1044 charT one;
1045
1046 assign (zero, 'o');
1047 assign (one, 'x');
1048
1049 int pos;
1050
1052 // exercise the overload of the to_string() member function template
1053 // that takes all three template parameters different from char,
1054 // char_traits<char>, and allocator<char>
1055
1056 typedef std::basic_string<charT, Traits, Alloc> String3;
1057
1058 String3 str3;
1059
1060 // specify none of the two function arguments (exercise defaults
1061 // or the respective overloads)
1062 str3 = bitset_to_string_3 (bs, 0, zero, one, (String3*)0);
1063 pos = compare (str3.data (), ts.bits (), "01");
1064
1065 rw_assert (-1 == pos, 0, __LINE__,
1066 "bitset<%zu>::to_string () == \"%s\", got \"%s\": "
1067 "mismatch at bit %d",
1068 N, ts.bits (), TO_STR (str3), pos);
1069
1070
1071 // specify one of the two function arguments (exercise the default
1072 // or the respective overload)
1073 rw_info (0, 0, __LINE__,
1074 "std::bitset<%zu>::to_string<%s, %s, %s >(\"%s\")",
1075 N, cname, tname, aname, cname);
1076
1077 str3 = bitset_to_string_3 (bs, 1, zero, one, (String3*)0);
1078 pos = compare (str3.data (), ts.bits (), "o1");
1079
1080 rw_assert (-1 == pos, 0, __LINE__,
1081 "bitset<%zu>::to_string ('o') == %s, got %s: "
1082 "mismatch at bit %d", N,
1083 to_string (ts.bits (), "o1").c_str (),
1084 TO_STR (str3), pos);
1085
1086
1087 // specify both of the two function arguments
1088 rw_info (0, 0, __LINE__,
1089 "std::bitset<%zu>::to_string<%s, %s, %s >(%s, %s)",
1090 N, cname, tname, aname, cname, cname);
1091
1092 str3 = bitset_to_string_3 (bs, 2, zero, one, (String3*)0);
1093 pos = compare (str3.data (), ts.bits (), "ox");
1094
1095 rw_assert (-1 == pos, 0, __LINE__,
1096 "bitset<%zu>::to_string ('o', 'x') == %s, got %s: "
1097 "mismatch at bit %d", N,
1098 to_string (ts.bits (), "ox").c_str (),
1099 TO_STR (str3), pos);
1100
1101
1103 // exercise the overload of the to_string() member function template
1104 // that takes the first two template parameters different from char,
1105 // and char_traits<char>
1106 rw_info (0, 0, __LINE__, "std::bitset<%zu>::to_string<%s, %s >()",
1107 N, cname, tname);
1108
1109 typedef std::allocator<charT> CharTAlloc;
1110 typedef std::basic_string<charT, Traits, CharTAlloc> String2;
1111
1112 String2 str2;
1113
1114 // specify none of the two function arguments (exercise defaults
1115 // or the respective overloads)
1116 str2 = bitset_to_string_2 (bs, 0, zero, one, (String2*)0);
1117 pos = compare (str2.data (), ts.bits (), "01");
1118
1119 rw_assert (-1 == pos, 0, __LINE__,
1120 "bitset<%zu>::to_string () == %s, got %s: mismatch at bit %d",
1121 N, ts.bits (), TO_STR (str2), pos);
1122
1123
1124 // specify one of the two function arguments (exercise the default
1125 // or the respective overload)
1126 rw_info (0, 0, __LINE__,
1127 "std::bitset<%zu>::to_string<%s, %s >(%s)",
1128 N, cname, tname, cname);
1129
1130 str2 = bitset_to_string_2 (bs, 1, zero, one, (String2*)0);
1131 pos = compare (str2.data (), ts.bits (), "o1");
1132
1133 rw_assert (-1 == pos, 0, __LINE__,
1134 "bitset<%zu>::to_string ('o') == %s, got %s: "
1135 "mismatch at bit %d", N,
1136 to_string (ts.bits (), "o1").c_str (),
1137 TO_STR (str2), pos);
1138
1139
1140 // specify both of the two function arguments
1141 rw_info (0, 0, __LINE__,
1142 "std::bitset<%zu>::to_string<%s, %s >(%s, %s)",
1143 N, cname, tname, cname, cname);
1144
1145 str2 = bitset_to_string_2 (bs, 2, zero, one, (String2*)0);
1146 pos = compare (str2.data (), ts.bits (), "ox");
1147
1148 rw_assert (-1 == pos, 0, __LINE__,
1149 "bitset<%zu>::to_string ('o', 'x') == %s, got %s: "
1150 "mismatch at bit %d", N,
1151 to_string (ts.bits (), "ox").c_str (),
1152 TO_STR (str2), pos);
1153
1154
1156 // exercise the overload of the to_string() member function template
1157 // that takes the first template parameter different from char
1158 rw_info (0, 0, __LINE__, "std::bitset<%zu>::to_string<%s>()",
1159 N, cname);
1160
1161 typedef std::char_traits<charT> CharTraits;
1162 typedef std::basic_string<charT, CharTraits, CharTAlloc> String1;
1163
1164 String1 str1;
1165
1166 // specify none of the two function arguments (exercise defaults
1167 // or the respective overloads)
1168 str1 = bitset_to_string_1 (bs, 0, zero, one, (String1*)0);
1169 pos = compare (str1.data (), ts.bits (), "01");
1170
1171 rw_assert (-1 == pos, 0, __LINE__,
1172 "bitset<%zu>::to_string () == %s, got %s: mismatch at bit %d",
1173 N, ts.bits (), TO_STR (str1), pos);
1174
1175
1176 // specify one of the two function arguments (exercise the default
1177 // or the respective overload)
1178 rw_info (0, 0, __LINE__, "std::bitset<%zu>::to_string<%s>(%s)",
1179 N, cname, cname);
1180
1181 str1 = bitset_to_string_1 (bs, 1, zero, one, (String1*)0);
1182 pos = compare (str1.data (), ts.bits (), "o1");
1183
1184 rw_assert (-1 == pos, 0, __LINE__,
1185 "bitset<%zu>::to_string ('o') == %s, got %s: "
1186 "mismatch at bit %d", N,
1187 to_string (ts.bits (), "o1").c_str (),
1188 TO_STR (str1), pos);
1189
1190
1191 // specify both of the two function arguments
1192 rw_info (0, 0, __LINE__,
1193 "std::bitset<%zu>::to_string<%s>(%s, %s)",
1194 N, cname, cname, cname);
1195
1196 str1 = bitset_to_string_1 (bs, 2, zero, one, (String1*)0);
1197 pos = compare (str1.data (), ts.bits (), "ox");
1198
1199 rw_assert (-1 == pos, 0, __LINE__,
1200 "bitset<%zu>::to_string ('o', 'x') == %s, got %s: "
1201 "mismatch at bit %d", N,
1202 to_string (ts.bits (), "ox").c_str (),
1203 TO_STR (str1), pos);
1204
1205
1207 // exercise the non-template overload of the to_string() member
1208
1209 if (nontemplate_done)
1210 return;
1211
1212 rw_info (0, 0, __LINE__, "std::bitset<%zu>::to_string ()", N);
1213
1214 typedef std::string String0;
1215
1216 String0 str0;
1217
1218 // specify none of the two function arguments (exercise defaults
1219 // or the respective overloads)
1220 str0 = bitset_to_string_0 (bs, 0, 'o', 'x', (String0*)0);
1221 pos = compare (str0.data (), ts.bits (), "01");
1222
1223 rw_assert (-1 == pos, 0, __LINE__,
1224 "bitset<%zu>::to_string () == %s, got %s: mismatch at bit %d",
1225 N, ts.bits (), str0.c_str (), pos);
1226
1227
1228 // specify one of the two function arguments (exercise the default
1229 // or the respective overload)
1230 rw_info (0, 0, __LINE__, "std::bitset<%zu>::to_string (char)", N);
1231
1232 str0 = bitset_to_string_0 (bs, 1, 'o', 'x', (String0*)0);
1233 pos = compare (str0.data (), ts.bits (), "o1");
1234
1235 rw_assert (-1 == pos, 0, __LINE__,
1236 "bitset<%zu>::to_string ('o') == %s, got %s: "
1237 "mismatch at bit %d", N,
1238 to_string (ts.bits (), "o1").c_str (),
1239 str0.c_str (), pos);
1240
1241
1242 // specify both of the two function arguments
1243 rw_info (0, 0, __LINE__, "std::bitset<%zu>::to_string (char, char)", N);
1244
1245 str0 = bitset_to_string_0 (bs, 2, 'o', 'x', (String0*)0);
1246 pos = compare (str0.data (), ts.bits (), "ox");
1247
1248 rw_assert (-1 == pos, 0, __LINE__,
1249 "bitset<%zu>::to_string ('o', 'x') == %s, got %s: "
1250 "mismatch at bit %d", N,
1251 to_string (ts.bits (), "ox").c_str (),
1252 str0.c_str (), pos);
1253}
1254
1255
1256template <std::size_t N>
1257void test_to_string (const std::bitset<N>*)
1258{
1259 test_to_string ((std::bitset<N>*)0,
1260 (char*)0,
1261 (std::char_traits<char>*)0,
1262 (std::allocator<char>*)0,
1263 false);
1264
1265#ifndef _RWSTD_NO_WCHAR_T
1266
1267 test_to_string ((std::bitset<N>*)0,
1268 (wchar_t*)0,
1269 (std::char_traits<wchar_t>*)0,
1270 (std::allocator<wchar_t>*)0,
1271 true);
1272
1273#endif // _RWSTD_NO_WCHAR_T
1274
1275 test_to_string ((std::bitset<N>*)0,
1276 (UserChar*)0,
1278 (std::allocator<UserChar>*)0,
1279 true);
1280}
1281
1282
1284template <std::size_t N>
1285void run_test (const std::bitset<N>*)
1286{
1287 test_ctors ((std::bitset<N>*)0);
1288 stress_ctors ((std::bitset<N>*)0);
1289 test_elem_access ((std::bitset<N>*)0);
1290 test_operators ((std::bitset<N>*)0);
1291 test_other ((std::bitset<N>*)0);
1292 stress_count ((std::bitset<N>*)0);
1293
1294 test_to_string ((std::bitset<N>*)0);
1295}
1296
1297
1299static int
1300run_test (int, char**)
1301{
1302 test_synopsis ((std::bitset<0>*)0);
1303
1304#define DO_TEST(N) run_test ((std::bitset<N>*)0)
1305
1306 DO_TEST ( 0); // interesting case
1307 DO_TEST ( 1); // interesting case
1308 DO_TEST ( 2);
1309 DO_TEST ( 31);
1310 DO_TEST ( 32); // interesting case
1311 DO_TEST ( 33); // interesting case
1312 DO_TEST ( 34);
1313 DO_TEST ( 63);
1314 DO_TEST ( 64); // interesting case
1315 DO_TEST ( 65); // interesting case
1316 DO_TEST ( 66);
1317
1318 DO_TEST ( 123);
1319
1320 DO_TEST ( 127); // interesting case
1321 DO_TEST ( 128); // interesting case
1322 DO_TEST ( 129);
1323 DO_TEST ( 130);
1324 DO_TEST ( 255);
1325 DO_TEST ( 256); // interesting case
1326
1327#if !defined(_MSC_VER) || _MSC_VER != 1300
1328 // FIXME: MSVC 514 can't compile bitset<257>!
1329 DO_TEST ( 257); // interesting case
1330#endif
1331
1332 DO_TEST ( 258); // interesting case
1333 DO_TEST ( 333);
1334
1335 return 0;
1336}
1337
1338
1340int main (int argc, char *argv[])
1341{
1342 // TODO: add command line options to control tested functionality
1343 return rw_test (argc, argv, __FILE__,
1344 "lib.bitset",
1345 0 /* no comment */,
1346 run_test,
1347 "",
1348 (void*)0 /* sentinel */);
1349}
void count(T, T, const U &,...)
#define N
Definition 17.names.cpp:157
#define i
Definition 17.names.cpp:126
#define k
Definition 17.names.cpp:128
#define rhs
Definition 17.names.cpp:536
#define b1
Definition 17.names.cpp:226
#define M
Definition 17.names.cpp:156
#define res
Definition 17.names.cpp:531
#define r
Definition 17.names.cpp:134
#define lhs
Definition 17.names.cpp:489
#define j
Definition 17.names.cpp:127
#define Reference
Definition 17.names.cpp:529
#define b
Definition 17.names.cpp:110
#define charT
Definition 17.names.cpp:456
#define tmp
Definition 17.names.cpp:553
#define s
#define b2
Definition 17.names.cpp:252
#define n
Definition 17.names.cpp:130
#define val
Definition 17.names.cpp:570
#define pos
Definition 17.names.cpp:518
volatile int result
#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 > *)
char to_char(char ch)
#define TO_STR(s)
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 PARAMLIST_3(T)
#define MEMFUN(result, name, arg_list)
#define DO_TEST(N)
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 > > *)
#define NLOOPS
Definition 23.bitset.cpp:41
std::size_t bitmax(std::size_t n)
Definition 23.bitset.cpp:47
std::string to_string(const char *str, const char bits[2])
#define TEST_OP(op)
#define PARAMLIST(T)
void test_ctors()
std::char_traits< S > Traits
const char * type_name()
#define main
#define _RWSTD_SPECIALIZED_CLASS
volatile int one
Definition LIMITS.cpp:61
volatile int zero
Definition LIMITS.cpp:60
#define _RWSTD_UNUSED(arg)
Definition _defs.h:972
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
#define _TRY
Definition _defs.h:850
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _CATCH(ex)
Definition _defs.h:851
const char * name
Definition codecvt1.cpp:72
const char * str
Definition exec.cpp:170
unsigned long ULong
Definition fmt_defs.h:43
#define CHAR_BIT
Definition limits.h:40
#define ULONG_MAX
Definition limits.h:96
Definition json.h:5363
_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 *,...)
Definition driver.cpp:1681
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
#define rw_rand(limit)
Definition rw_rand.h:69
unsigned char c
Definition rw_char.h:50
has_implicit_ctor(const std::string &)
const char * bits() const
Definition 23.bitset.cpp:82
bool test(std::size_t pos) const
test_set operator~() const
bool operator==(const test_set &rhs) const
std::bitset< N > to_bitset() const
Definition 23.bitset.cpp:92
test_set & set(std::size_t pos, bool val)
test_set & reset()
test_set & operator|=(const test_set &rhs)
test_set(unsigned long val)
Definition 23.bitset.cpp:68
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 & random()
Definition 23.bitset.cpp:86
test_set & flip()
char bits_[N+1]
Definition 23.bitset.cpp:61
test_set(const std::bitset< N > &rhs)
Definition 23.bitset.cpp:74
test_set & set()
test_set & operator&=(const test_set &rhs)
Definition 23.bitset.cpp:99
test_set & operator>>=(std::size_t n)
test_set & reset(std::size_t pos)