BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslstl_bitset.h
Go to the documentation of this file.
1/// @file bslstl_bitset.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_bitset.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_BITSET
9#define INCLUDED_BSLSTL_BITSET
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_bitset bslstl_bitset
15/// @brief Provide an STL-compliant bitset class.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_bitset
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_bitset-purpose"> Purpose</a>
25/// * <a href="#bslstl_bitset-classes"> Classes </a>
26/// * <a href="#bslstl_bitset-description"> Description </a>
27/// * <a href="#bslstl_bitset-usage"> Usage </a>
28/// * <a href="#bslstl_bitset-example-1-determining-if-a-number-is-prime"> Example 1: Determining if a Number is Prime (Sieve of Eratosthenes) </a>
29///
30/// # Purpose {#bslstl_bitset-purpose}
31/// Provide an STL-compliant bitset class.
32///
33/// # Classes {#bslstl_bitset-classes}
34///
35/// - bsl::bitset: STL-compatible bitset template
36///
37/// **Canonical header:** bsl_bitset.h
38///
39/// @see package bos+stdhdrs in the bos package group
40///
41/// # Description {#bslstl_bitset-description}
42/// This component is for internal use only. Please include
43/// `<bsl_bitset.h>` instead and use `bsl::bitset` directly. This component
44/// implements a static bitset class that is suitable for use as an
45/// implementation of the `std::bitset` class template.
46///
47/// ## Usage {#bslstl_bitset-usage}
48///
49///
50/// This section illustrates intended use of this component.
51///
52/// ### Example 1: Determining if a Number is Prime (Sieve of Eratosthenes) {#bslstl_bitset-example-1-determining-if-a-number-is-prime}
53///
54///
55/// Suppose we want to write a function to determine whether or not a given
56/// number is prime. One way to implement this function is by using what's
57/// called the Sieve of Eratosthenes. The basic idea of this algorithm is to
58/// repeatedly walk the sequence of integer values and mark any numbers up to
59/// and including the particular value of interest that are integer multiples of
60/// first 2, then 3, then 5, etc. (skipping 4 because it was previously marked
61/// when we walked the sequence by 2's). Once we have walked the sequence with
62/// all primes up to and including the square root of the number of interest, we
63/// check to see if that number has been marked: If it has, it's composite;
64/// otherwise it's prime.
65///
66/// When implementing this classic algorithm, we need an efficient way of
67/// representing a flag for each potential prime number. The following
68/// illustrates how we can use `bsl::bitset` to accomplish this result, provided
69/// we know an upper bound on supplied candidate values at compile time.
70///
71/// First, we begin to define a function template that will determine whether or
72/// not a given candidate value is prime:
73/// @code
74/// /// Return `true` if the specified `candidate` value is a prime number,
75/// /// and `false` otherwise. The behavior is undefined unless
76/// /// `2 <= candidate <= MAX_VALUE`
77/// template <unsigned int MAX_VALUE>
78/// bool isPrime(int candidate)
79/// {
80/// BSLMF_ASSERT(2 <= MAX_VALUE);
81/// BSLS_ASSERT(2 <= candidate); BSLS_ASSERT(candidate <= MAX_VALUE);
82/// @endcode
83/// Then, we declare a `bsl::bitset`, `compositeFlags`, that will contain flags
84/// indicating whether a value corresponding to a given index is known to be
85/// composite (`true`) or is still potentially prime (`false`) up to and
86/// including the compile-time constant template parameter, `MAX_VALUE`.
87/// @code
88/// // Candidate primes in the '[2 .. MAX_VALUE]' range.
89///
90/// bsl::bitset<MAX_VALUE + 1> compositeFlags;
91/// @endcode
92/// Next, we observe that a default-constructed `bsl::bitset` has no flags set,
93/// We can check this by asserting that the `none` method returns true, by
94/// asserting that the `any` method returns false, or by asserting that the
95/// `count` of set bits is 0:
96/// @code
97/// assert(true == compositeFlags.none());
98/// assert(false == compositeFlags.any());
99/// assert(0 == compositeFlags.count());
100/// @endcode
101/// Then, we note that a `bsl::bitset` has a fixed `size` (the set can't be
102/// grown or shrunk) and verify that `size` is the same as the template argument
103/// used to create the `bsl::bitset`:
104/// @code
105/// assert(MAX_VALUE + 1 == compositeFlags.size());
106/// @endcode
107/// Next, we compute `sqrt(candidate)`, which is as far as we need to look:
108/// @code
109/// // We need to cast the `sqrt` argument to avoid an overload ambiguity.
110/// const int sqrtOfCandidate = static_cast<int>(
111/// std::sqrt(static_cast<double>(candidate))
112/// + 0.01); // fudge factor
113/// @endcode
114/// Now, we loop from 2 to `sqrtOfCandidate`, and use the sieve algorithm to
115/// eliminate non-primes:
116/// @code
117/// // Note that we treat `false` values as potential primes,
118/// // since that is how `bsl::bitset` is default-initialized.
119///
120/// for (std::size_t i = 2; i <= sqrtOfCandidate; ++i) {
121/// if (compositeFlags[i]) {
122/// continue; // Skip this value: it's flagged as composite, so all
123/// // of its multiples are already flagged as composite
124/// // as well.
125/// }
126///
127/// for (std::size_t flagValue = i;
128/// flagValue <= candidate;
129/// flagValue += i) {
130/// compositeFlags[flagValue] = true;
131/// }
132///
133/// if (true == compositeFlags[candidate]) {
134/// return false; // RETURN
135/// }
136/// }
137///
138/// BSLS_ASSERT(false == compositeFlags[candidate]);
139///
140/// return true;
141/// }
142/// @endcode
143/// Notice that if we don't return `false` from the loop, none of the lower
144/// numbers evenly divided the candidate value; hence, it is a prime number.
145///
146/// Finally, we can exercise our `isPrime` function with an upper bound of
147/// 10,000:
148/// @code
149/// enum { UPPER_BOUND = 10000 };
150///
151/// assert(1 == isPrime<UPPER_BOUND>(2));
152/// assert(1 == isPrime<UPPER_BOUND>(3));
153/// assert(0 == isPrime<UPPER_BOUND>(4));
154/// assert(1 == isPrime<UPPER_BOUND>(5));
155/// assert(0 == isPrime<UPPER_BOUND>(6));
156/// assert(1 == isPrime<UPPER_BOUND>(7));
157/// assert(0 == isPrime<UPPER_BOUND>(8));
158/// assert(0 == isPrime<UPPER_BOUND>(9));
159/// assert(0 == isPrime<UPPER_BOUND>(10));
160/// // ...
161/// assert(1 == isPrime<UPPER_BOUND>(9973));
162/// assert(0 == isPrime<UPPER_BOUND>(9975));
163/// assert(0 == isPrime<UPPER_BOUND>(10000));
164/// @endcode
165/// @}
166/** @} */
167/** @} */
168
169/** @addtogroup bsl
170 * @{
171 */
172/** @addtogroup bslstl
173 * @{
174 */
175/** @addtogroup bslstl_bitset
176 * @{
177 */
178
179#include <bslscm_version.h>
180
181#include <bslstl_stdexceptutil.h>
182#include <bslstl_string.h>
183
184#include <bslma_bslallocator.h>
185
186#include <bslmf_assert.h>
187
188#include <bsls_assert.h>
190#include <bsls_keyword.h>
191#include <bsls_performancehint.h>
192#include <bsls_platform.h>
193
194#include <algorithm> // 'min'
195
196#include <cstddef>
197
198#include <iosfwd>
199
200#include <string>
201#include <limits.h>
202#include <string.h>
203
204#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
205#include <bsls_nativestd.h>
206#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
207
208#if defined(BSLS_PLATFORM_CMP_MSVC) || \
209 (defined(BSLS_PLATFORM_CMP_GNU) && BSLS_PLATFORM_CMP_VERSION < 40400)
210 // Last tested against MSVC 2013. The Microsoft compiler cannot parse the
211 // nested typenames for function parameters with default arguments, where
212 // the function parameter type is a dependent type within a template, such
213 // as 'typename std::basic_string<C,T,A>::size_type'. The error message
214 // complains about invalid identiefiers on the right of the '::', and this
215 // feature macro is named accordingly. Older version of g++ also have this
216 // problem.
217# define BSLSTL_BITSET_MSVC_CANNOT_PARSE_DEFAULTS_WITH_COLONS
218#endif
219
220namespace bsl {
221
222template <std::size_t N>
223class bitset;
224
225 // ====================
226 // class Bitset_ImpUtil
227 // ====================
229 enum {
230 k_BYTES_PER_INT = sizeof(int),
231 k_BITS_PER_INT = CHAR_BIT * sizeof(int),
232 k_INTS_IN_LONG = sizeof(long) / sizeof(int),
233 k_INTS_IN_LLONG = sizeof(long long) / sizeof(int)
234 };
235
237
238 /// Initialize the memory at the address specified by `data` so that the
239 /// the first `M` bit positions correspond to the bit values in the
240 /// specified `val` where `M` is the smaller of `size * k_BITS_PER_INT`
241 /// and `CHAR_BIT * sizeof(unsigned long long)`. The remaining bits are
242 /// initialized to zero `0`.
243 static void defaultInit(unsigned int *data,
244 std::size_t size,
245 unsigned long long val = 0);
246};
247
248 // ====================
249 // class Bitset_ImpBase
250 // ====================
251
252/// This component private `class` template describes the basic data and
253/// initialization semantics needed in order to implement a C++11 `bitset`
254/// class. The `BITSETSIZE` template parameter specifies the size of the
255/// underlying data array, `d_data`. The `NUM_INIT` template parameter
256/// specifies the number of elements in `d_data` needed to use when storing
257/// a value of type `unsigned long long`. Partial class template
258/// specializations of `Bitset_ImpBase` are provided for `NUM_INIT == 1` and
259/// `NUM_INIT == 2`. No other values of `NUM_INIT` are supported.
260template <std::size_t BITSETSIZE,
261 std::size_t NUM_INIT =
262 (BITSETSIZE < (std::size_t)Bitset_ImpUtil::k_INTS_IN_LLONG
263 ? BITSETSIZE
264 : (std::size_t)Bitset_ImpUtil::k_INTS_IN_LLONG)>
266
267template <std::size_t BITSETSIZE>
269 public:
270 // PUBLIC DATA
271 unsigned int d_data[BITSETSIZE];
272
273 // CREATORS
274
275 /// Create a `Bitset_ImpBase` with each bit in `d_data` initialized to
276 /// zero. In C++11 this constructor can be used in a constant
277 /// expression.
279
280 /// Create a `Bitset_ImpBase` with the first `N` bit positions of
281 /// `d_data` corresponding to the first `N` bit positions of the
282 /// specified `val` after conversion to `unsigned int` and the remaining
283 /// bits in `d_data` initialized to zero, where `N` is
284 /// `CHAR_BIT * sizeof(int)`. The behavior is undefined unless
285 /// `BITSETSIZE == 1`. In C++11 this constructor can be used in a
286 /// constant expression.
287 BSLS_KEYWORD_CONSTEXPR Bitset_ImpBase(unsigned long long val);
288};
289
290template <std::size_t BITSETSIZE>
292 public:
293 // PUBLIC DATA
294 unsigned int d_data[BITSETSIZE];
295
296 // CREATORS
297
298 /// Create a Bitset_ImpBase with each bit in `d_data` initialized to
299 /// zero. In C++11 this constructor can be used in a constant
300 /// expression.
302
303 /// Create a `Bitset_ImpBase` with the first `N` bit positions of
304 /// `d_data` corresponding to the first `N` bit positions of the
305 /// specified `val` after conversion to `unsigned int` and the remaining
306 /// bits in `d_data` initialized to zero, where `N` is
307 /// `CHAR_BIT * sizeof(int) * 2`. In C++11 this constructor can be used
308 /// in a constant expression.
309 BSLS_KEYWORD_CONSTEXPR Bitset_ImpBase(unsigned long long val);
310};
311
312 // =================
313 // class bsl::bitset
314 // =================
315
316/// This class template provides an STL-compliant `bitset`. For the
317/// requirements of a `bitset` class, consult the second revision of the
318/// ISO/IEC 14882 Programming Language c++ (2011).
319///
320/// In addition to the methods defined in the standard, this class also
321/// provides an extra constructor that takes a `bsl::basic_string`. This
322/// extra constructor provides the capability to construct a `bitset` from a
323/// `bsl::basic_string`, in addition to a `std::basic_string`.
324template <std::size_t N>
325class bitset :
326 private Bitset_ImpBase<N ? (N - 1) / (CHAR_BIT * sizeof(int)) + 1 : 1> {
327
328 // PRIVATE TYPES
329 enum {
330 k_BYTES_PER_INT = sizeof(int),
331 k_BITS_PER_INT = CHAR_BIT * k_BYTES_PER_INT,
332 k_BITSETSIZE = N ? (N - 1) / k_BITS_PER_INT + 1 : 1
333 };
334
335 // @ref static_cast is needed here to avoid warning with '-Wextra' and 'gcc'.
336 typedef Bitset_ImpBase<static_cast<std::size_t>(k_BITSETSIZE)> Base;
337
338 using Base::d_data;
339
340 // FRIENDS
341 friend class reference;
342
343 public:
344 // PUBLIC TYPES
345
346 /// This class represents a reference to a modifiable bit inside a
347 /// `bsl::bitset`.
348 ///
349 /// See @ref bslstl_bitset
350 class reference {
351
352 // FRIENDS
353 friend class bitset;
354
355 // DATA
356 unsigned int *d_int_p; // pointer to the 'int' inside the 'bitset'.
357 unsigned int d_offset; // bit offset to 'd_int'.
358
359 // PRIVATE CREATORS
360
361 /// Create a `reference` object that refers to the bit at the
362 /// specified `offset` of the `int` pointed to by the specified `i`.
363 /// The behavior is undefined unless `i` points to an `int` inside a
364 /// `bsl::bitset`.
365 reference(unsigned int *i, unsigned int offset);
366
367 public:
368#ifdef BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS
369 // CREATORS
370
371 /// Create a `reference` object having the same value as the
372 /// specified `original` object. Note that this copy constructor is
373 /// generated by the compiler.
374 reference(const reference& original) BSLS_KEYWORD_NOEXCEPT = default;
375#endif
376
377 // MANIPULATORS
378
379 /// Assign to the bit referenced by this object the specified value
380 /// `x` and return a reference offering modifiable access to this
381 /// object.
382 reference& operator=(bool x) BSLS_KEYWORD_NOEXCEPT;
383
384 /// Assign this object to refer to the same bit as the specified `x`
385 /// and return a reference offering modifiable access to this
386 /// object.
387 reference& operator=(const reference& x) BSLS_KEYWORD_NOEXCEPT;
388
389 /// Invert the value of the bit referenced by this object and return
390 /// a reference offering modifiable access to this object.
392
393 // ACCESSORS
394
395 /// Return the value of the bit referenced by this object.
396 operator bool() const BSLS_KEYWORD_NOEXCEPT;
397
398 /// Return the inverted value of the bit referenced by this object.
399 /// Note that the value of the referenced bit remains unchanged.
400 bool operator~() const BSLS_KEYWORD_NOEXCEPT;
401 };
402
403 private:
404 // PRIVATE MANIPULATORS
405
406 /// Clear the bits unused by the bitset in `d_data`, namely, bits
407 /// `k_BITSETSIZE * k_BITS_PER_INT - 1` to `N` (where the bit count
408 /// starts at 0).
409 void clearUnusedBits();
410
411 void clearUnusedBits(bsl::false_type);
412 /// Implementations of `clearUnusedBits`, overloaded by whether there
413 /// are any unused bits.
414 void clearUnusedBits(bsl::true_type);
415
416 /// Assign to the first `M` bit of this object a value corresponding to
417 /// the characters in the specified `pos` of the specified `str`. `M`
418 /// is the smaller of the specified `N` and `str.length()`. If `M < N`
419 /// the remaining bit positions are left unchanged. Characters with the
420 /// value `zeroChar` correspond to an unset bit and characters with the
421 /// value `oneChar` correspond to a set bit. The behavior is undefined
422 /// if any characters in `str` is neither the specified `zeroChar` nor
423 /// the specified `oneChar`.
424 template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
425 void copyString(const std::basic_string<CHAR_TYPE,
426 TRAITS,
427 ALLOCATOR>& str,
428 typename std::basic_string<CHAR_TYPE,
429 TRAITS,
430 ALLOCATOR>::size_type pos,
431 typename std::basic_string<CHAR_TYPE,
432 TRAITS,
433 ALLOCATOR>::size_type n,
434 CHAR_TYPE zeroChar,
435 CHAR_TYPE oneChar);
436 template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
437 void copyString(
438 const bsl::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>& str,
439 typename bsl::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>::size_type pos,
440 typename bsl::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>::size_type n,
441 CHAR_TYPE zeroChar,
442 CHAR_TYPE oneChar);
443
444 // PRIVATE ACCESSORS
445
446 /// Return the number of 1 bits in the specified `src`.
447 std::size_t numOneSet(unsigned int src) const;
448
449 public:
450 // CREATORS
451
452 /// Create a `bitset` with all bits initialized to `0`.
454
455 /// Create a bitset with its first `M` bit positions correspond to bit
456 /// values in the specified `val`. `M` is the smaller of the
457 /// parameterized `N` and `8 * sizeof(unsigned long long)`. If `M < N`,
458 /// the remaining bit positions are initialized to 0.
460 bitset(unsigned long long val) BSLS_KEYWORD_NOEXCEPT; // IMPLICIT
461
462 /// Create a bitset with its first `M` bit positions corresponding to
463 /// the characters in the specified `pos` of the specified `str`. `M`
464 /// is the smaller of the parameterized `N` and `str.length()`. If
465 /// `M < N`, the remaining bit positions are initialized to 0.
466 /// Characters with the value `zeroChar` correspond to an unset bit and
467 /// characters with the value `oneChar` correspond to a set bit. The
468 /// behavior is undefined if any characters in `str` is neither the
469 /// specified `zeroChar` nor the specified `oneChar`.
470#if !defined(BSLSTL_BITSET_MSVC_CANNOT_PARSE_DEFAULTS_WITH_COLONS)
471 template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
472 explicit bitset(
473 const std::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>& str,
474 typename
475 std::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>::size_type pos = 0,
476 typename
477 std::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>::size_type n =
478 std::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>::npos,
479 CHAR_TYPE zeroChar = CHAR_TYPE('0'),
480 CHAR_TYPE oneChar = CHAR_TYPE('1'));
481#else
482 template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
483 explicit
484 bitset(const std::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>& str,
487 CHAR_TYPE zeroChar = CHAR_TYPE('0'),
488 CHAR_TYPE oneChar = CHAR_TYPE('1'));
489#endif
490
491 /// Create a bitset with its first `M` bit positions corresponding to 0
492 /// the characters in the specified `pos` of the specified `str`. `M`
493 /// is the smaller of the parameterized `N` and `str.length()`. If
494 /// `M < N`, the remaining bit positions are initialized to 0.
495 /// Characters with the value `zeroChar` correspond to an unset bit and
496 /// characters with the value `oneChar` correspond to a set bit. The
497 /// behavior is undefined if the characters in the specified `str` is
498 /// not the specified `zeroChar` and not the specified `oneChar`
499#if !defined(BSLSTL_BITSET_MSVC_CANNOT_PARSE_DEFAULTS_WITH_COLONS)
500 template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
501 explicit bitset(
504 0,
507 CHAR_TYPE zeroChar = CHAR_TYPE('0'),
508 CHAR_TYPE oneChar = CHAR_TYPE('1'));
509#else
510 template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
514 CHAR_TYPE zeroChar = CHAR_TYPE('0'),
515 CHAR_TYPE oneChar = CHAR_TYPE('1'));
516#endif
517
518 // MANIPULATORS
519
520 /// Clear each bit of this bitset for each corresponding bit that is 0
521 /// in the specified `rhs`, and leaves all other bits unchanged. Return
522 /// a reference to this modifiable bitset. Note that this is equivalent
523 /// to a bitwise OR.
524 bitset& operator&=(const bitset& rhs) BSLS_KEYWORD_NOEXCEPT;
525
526 /// Set each bit of this bitset for each corresponding bit that is 1 in
527 /// the specified `rhs`, and leaves all other bits unchanged. Return a
528 /// reference to this modifiable bitset. Note that this is equivalent
529 /// to a bitwise AND.
530 bitset& operator|=(const bitset& rhs) BSLS_KEYWORD_NOEXCEPT;
531
532 /// Toggle each bit of this bitset for each corresponding bit that is 1
533 /// in the specified `rhs`, and leaves all other bits unchanged. Return
534 /// a reference to this modifiable bitset. Note that this is equivalent
535 /// to a bitwise XOR.
536 bitset& operator^=(const bitset& rhs) BSLS_KEYWORD_NOEXCEPT;
537
538 /// Shift the bits of this bitset left (towards the most significant
539 /// bit) by the specified `pos` and return a reference to this
540 /// modifiable bitset. For all bits with position I where `I <= pos`,
541 /// the new value is 0. The behavior is undefined unless `pos <= N`.
542 bitset& operator<<=(std::size_t pos) BSLS_KEYWORD_NOEXCEPT;
543
544 /// Shift the bits of this bitset right (towards the least significant
545 /// bit) by the specified `pos` and return a reference to this
546 /// modifiable bitset. For all bits with position I where
547 /// `I > N - pos`, the new value is 0. The behavior is undefined unless
548 /// `pos <= N`.
549 bitset& operator>>=(std::size_t pos) BSLS_KEYWORD_NOEXCEPT;
550
551 /// Toggle all bits of this bitset and return a reference to this
552 /// modifiable bitset.
554
555 /// Toggle the bit at the specified `pos` of this bitset and return a
556 /// reference to this modifiable bitset.
557 bitset& flip(std::size_t pos);
558
559 /// Set all bits of this bitset to 0 and return a reference to this
560 /// modifiable bitset.
562
563 /// Set the bit at the specified `pos` of this bitset to 0 and return a
564 /// reference to this modifiable bitset.
565 bitset& reset(std::size_t pos);
566
567 /// Set all bits of this bitset to 1 and return a reference to this
568 /// modifiable bitset.
570
571 /// Set the bit at the specified `pos` of this bitset to 1 and return a
572 /// reference to this modifiable bitset. Optionally specify `val` as
573 /// the value to set the bit. If `val` is non-zero, the bit is set to
574 /// 1, otherwise the bit is set to 0.
575 bitset& set(std::size_t pos, int val = true);
576
577 /// Return a `reference` to the modifiable bit position at the specified
578 /// `pos`.
579 reference operator[](std::size_t pos);
580
581 // ACCESSORS
582
583 /// Return a bitset constructed from shifting this bitset left by the
584 /// specified `pos`.
585 bitset operator<<(std::size_t pos) const BSLS_KEYWORD_NOEXCEPT;
586
587 /// Return a bitset constructed from shifting this bitset right by the
588 /// specified `pos`.
589 bitset operator>>(std::size_t pos) const BSLS_KEYWORD_NOEXCEPT;
590
591 /// Toggle all bits of this bitset and return a reference to this
592 /// modifiable bitset.
593 bitset operator~() const BSLS_KEYWORD_NOEXCEPT;
594
595 /// Return the value of the bit position at the specified `pos`.
596 BSLS_KEYWORD_CONSTEXPR bool operator[](std::size_t pos) const;
597
598 /// Return `true` if the specified `rhs` has the same value as this
599 /// bitset and `false` otherwise. Two bitsets have the same value when
600 /// the sequence and value of bits they hold are the same.
601 bool operator==(const bitset& rhs) const BSLS_KEYWORD_NOEXCEPT;
602
603 /// Return `true` if the specified `rhs` do not have the same value as
604 /// this bitset and `false` otherwise. Two bitset do not have the same
605 /// value when either the sequence or the value of bits they hold are
606 /// not the same.
607 bool operator!=(const bitset& rhs) const BSLS_KEYWORD_NOEXCEPT;
608
609 /// Return `true` if all of the bits in this bitset have the value of 1
610 /// and `false` otherwise. Note that `all()` and `none()` are both true
611 /// for bitsets of size 0.
612 bool all() const BSLS_KEYWORD_NOEXCEPT;
613
614 /// Return `true` if one or more of the bits in this bitset has the
615 /// value of 1 and `false` otherwise.
616 bool any() const BSLS_KEYWORD_NOEXCEPT;
617
618 /// Return `true` if all the bits in this bitset has the value of 0 and
619 /// `false` otherwise. Note that `all()` and `none()` are both true
620 /// for bitsets of size 0.
621 bool none() const BSLS_KEYWORD_NOEXCEPT;
622
623 /// Return the number of bits in this bitset that have the value of 1.
624 std::size_t count() const BSLS_KEYWORD_NOEXCEPT;
625
626 /// Return the number of bits this bitset holds.
628
629 /// Return `true` if the bit at the specified `pos` has the value of 1
630 /// and `false` otherwise.
631 bool test(size_t pos) const;
632
633#if __cplusplus >= 201103L
634 /// Return a @ref basic_string representation of this bitset, where the
635 /// zero-bits are represented by the specified `zero` character and the
636 /// one-bits are represented by the specified `one` character. The
637 /// most-significant bit is placed at the beginning of the string, and
638 /// the least-significant bit is placed at the end of the string.
639 template <class CHAR_TYPE = char,
640 class TRAITS = char_traits<CHAR_TYPE>,
641 class ALLOCATOR = allocator<CHAR_TYPE> >
642#else
643 template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
644#endif
646 CHAR_TYPE zero = CHAR_TYPE('0'),
647 CHAR_TYPE one = CHAR_TYPE('1')) const;
648
649 /// Return an `unsigned` `long` value that has the same bit value as the
650 /// bitset. Note that the behavior is undefined if the bitset cannot be
651 /// represented as an `unsigned` `long`.
652 unsigned long to_ulong() const;
653};
654
655// FREE OPERATORS
656
657/// Return a `bitset` that results from a bitwise AND of the specified `lhs`
658/// and `rhs`.
659template <std::size_t N>
660bitset<N> operator&(const bitset<N>& lhs, const bitset<N>& rhs)
662
663/// Return a `bitset` that results from a bitwise OR of the specified `lhs`
664/// and `rhs`.
665template <std::size_t N>
666bitset<N> operator|(const bitset<N>& lhs, const bitset<N>& rhs)
668
669/// Return a `bitset` that results from a bitwise XOR of the specified `lhs`
670/// and `rhs`.
671template <std::size_t N>
672bitset<N> operator^(const bitset<N>& lhs, const bitset<N>& rhs)
674
675template <class CHAR_TYPE, class TRAITS, std::size_t N>
676std::basic_istream<CHAR_TYPE, TRAITS>&
677operator>>(std::basic_istream<CHAR_TYPE, TRAITS>& is, bitset<N>& x);
678
679template <class CHAR_TYPE, class TRAITS, std::size_t N>
680std::basic_ostream<CHAR_TYPE, TRAITS>&
681operator<<(std::basic_ostream<CHAR_TYPE, TRAITS>& os, const bitset<N>& x);
682
683// ============================================================================
684// INLINE AND TEMPLATE FUNCTION DEFINITIONS
685// ============================================================================
686
687
688 // --------------------------
689 // class Bitset_ImpBase<N, 1>
690 // --------------------------
691
692template <std::size_t BITSETSIZE>
698
699template <std::size_t BITSETSIZE>
702#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS) \
703 &&!(defined(BSLS_PLATFORM_CMP_MSVC) && BSLS_PLATFORM_CMP_VERSION < 1900)
704 : d_data{static_cast<unsigned int>(val)}
705{
706}
707#else
708{
709 Bitset_ImpUtil::defaultInit(d_data, BITSETSIZE, val);
710}
711#endif
712
713 // --------------------------
714 // class Bitset_ImpBase<N, 2>
715 // --------------------------
716
717template <std::size_t BITSETSIZE>
723
724template <std::size_t BITSETSIZE>
727#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS) \
728 &&!(defined(BSLS_PLATFORM_CMP_MSVC) && BSLS_PLATFORM_CMP_VERSION < 1900)
729 : d_data{static_cast<unsigned int>(val),
730 static_cast<unsigned int>(val >> (sizeof(int) * CHAR_BIT))}
731{
732}
733#else
734{
735 Bitset_ImpUtil::defaultInit(d_data, BITSETSIZE, val);
736}
737#endif
738
739 // -----------------------
740 // class bitset::reference
741 // -----------------------
742
743// PRIVATE CREATORS
744template <std::size_t N>
745inline
746bitset<N>::reference::reference(unsigned int *i, unsigned int offset)
747: d_int_p(i)
748, d_offset(offset)
749{
750 BSLS_ASSERT_SAFE(d_int_p);
751}
752
753// MANIPULATORS
754template <std::size_t N>
755inline
756typename bitset<N>::reference&
758{
759 if (x) {
760 *d_int_p |= (1 << d_offset);
761 }
762 else {
763 *d_int_p &= ~(1 << d_offset);
764 }
765 return *this;
766}
767
768template <std::size_t N>
769inline
770typename bitset<N>::reference&
772{
773 if (x) {
774 *d_int_p |= (1 << d_offset);
775 }
776 else {
777 *d_int_p &= ~(1 << d_offset);
778 }
779 return *this;
780}
781
782template <std::size_t N>
783inline
784typename bitset<N>::reference&
786{
787 *d_int_p ^= (1 << d_offset);
788 return *this;
789}
790
791// ACCESSORS
792template <std::size_t N>
793inline
795{
796 return ((*d_int_p & (1 << d_offset)) != 0);
797}
798
799template <std::size_t N>
800inline
802{
803 return ((*d_int_p & (1 << d_offset)) == 0);
804}
805
806 // ------------
807 // class bitset
808 // ------------
809
810// PRIVATE MANIPULATORS
811template <std::size_t N>
812inline
814{
815 enum { k_VALUE = N % k_BITS_PER_INT ? 1 : 0 };
816
817 clearUnusedBits(bsl::integral_constant<bool, k_VALUE>());
818}
819
820template <std::size_t N>
821inline
822void bitset<N>::clearUnusedBits(bsl::false_type)
823{
824}
825
826template <std::size_t N>
827inline
828void bitset<N>::clearUnusedBits(bsl::true_type)
829{
830 const unsigned int offset = N % k_BITS_PER_INT; // never 0
831
832 d_data[k_BITSETSIZE - 1] &= ~(~((unsigned int)0) << offset);
833}
834
835template <std::size_t N>
836std::size_t bitset<N>::numOneSet(unsigned int src) const
837{
838 // The following code was taken from @ref bdes_bitutil .
839 unsigned input = src;
840
841 // First we use a tricky way of getting every 2-bit half-nibble to
842 // represent the number of bits that were set in those two bits.
843
844 input -= (input >> 1) & 0x55555555;
845
846 // Henceforth, we just accumulate the sum down into lower and lower bits.
847
848 {
849 const int mask = 0x33333333;
850 input = ((input >> 2) & mask) + (input & mask);
851 }
852
853 // Any 4-bit nibble is now guaranteed to be less than or equal to 8, so we
854 // do not have to mask both sides of the addition. We must mask after the
855 // addition, so 8-bit bytes are the sum of bits in those 8 bits.
856
857 input = ((input >> 4) + input) & 0x0f0f0f0f;
858
859 // It is no longer necessary to mask the additions, because it is
860 // impossible for any bit groups to add up to more than 256 and carry, thus
861 // interfering with adjacent groups. Each 8-bit byte is independent from
862 // now on.
863
864 input = (input >> 8) + input;
865 input = (input >> 16) + input;
866
867 return input & 0x000000ff;
868}
869
870template <std::size_t N>
871template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
872void bitset<N>::copyString(
873const std::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>& str,
874typename std::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>::size_type pos,
875typename std::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>::size_type n,
876CHAR_TYPE zeroChar,
877CHAR_TYPE oneChar)
878{
879 typedef typename std::basic_string<CHAR_TYPE,
880 TRAITS,
881 ALLOCATOR>::size_type size_type;
882 n = std::min(N, std::min(n, str.size() - pos));
883 for (size_type i = 0; i < n; ++i) {
884 typename TRAITS::int_type bit = TRAITS::to_int_type(
885 str[pos + n - i - 1]);
886
887 if (bit == oneChar) {
888 set(i);
889 }
890 else if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(bit != zeroChar)) {
892 BloombergLP::bslstl::StdExceptUtil::throwInvalidArgument(
893 "string for bitset constructor "
894 "must be '0' or '1'");
895 }
896 }
897}
898
899template <std::size_t N>
900template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
901void bitset<N>::copyString(
905 CHAR_TYPE zeroChar,
906 CHAR_TYPE oneChar)
907{
908 typedef typename bsl::basic_string<CHAR_TYPE,
909 TRAITS,
910 ALLOCATOR>::size_type size_type;
911 n = std::min(N, std::min(n, str.size() - pos));
912 for (size_type i = 0; i < n; ++i) {
913 typename TRAITS::int_type bit = TRAITS::to_int_type(
914 str[pos + n - i - 1]);
915
916 if (bit == oneChar) {
917 set(i);
918 }
919 else if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(bit != zeroChar)) {
921 BloombergLP::bslstl::StdExceptUtil::throwInvalidArgument(
922 "string for bitset constructor "
923 "must be '0' or '1'");
924 }
925 }
926}
927
928// CREATORS
929template <std::size_t N>
934
935template <std::size_t N>
937bitset<N>::bitset(unsigned long long val) BSLS_KEYWORD_NOEXCEPT : Base(val)
938{
939}
940
941#if !defined(BSLSTL_BITSET_MSVC_CANNOT_PARSE_DEFAULTS_WITH_COLONS)
942template <std::size_t N>
943template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
944inline
946bitset(const std::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>& str,
947 typename std::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>::size_type pos,
948 typename std::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>::size_type n,
949 CHAR_TYPE zeroChar,
950 CHAR_TYPE oneChar)
951#else
952template <std::size_t N>
953template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
954inline
956bitset(const std::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>& str,
959 CHAR_TYPE zeroChar,
960 CHAR_TYPE oneChar)
961#endif
962{
963 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(pos > str.size())) {
965 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
966 "'pos > str.size()' for bitset constructor");
967 }
968 memset(d_data, 0, k_BITSETSIZE * k_BYTES_PER_INT);
969 copyString(str, pos, n, zeroChar, oneChar);
970}
971
972
973#if !defined(BSLSTL_BITSET_MSVC_CANNOT_PARSE_DEFAULTS_WITH_COLONS)
974template <std::size_t N>
975template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
976inline
981 CHAR_TYPE zeroChar,
982 CHAR_TYPE oneChar)
983#else
984template <std::size_t N>
985template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
986inline
991 CHAR_TYPE zeroChar,
992 CHAR_TYPE oneChar)
993#endif
994{
997 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
998 "'pos > str.size()' for bitset constructor");
999 }
1000 memset(d_data, 0, k_BITSETSIZE * k_BYTES_PER_INT);
1001 copyString(str, pos, n, zeroChar, oneChar);
1002}
1003
1004// MANIPULATORS
1005template <std::size_t N>
1007{
1008 for (std::size_t i = 0; i < k_BITSETSIZE; ++i) {
1009 d_data[i] &= rhs.d_data[i];
1010 }
1011 return *this;
1012}
1013
1014template <std::size_t N>
1016{
1017 for (std::size_t i = 0; i < k_BITSETSIZE; ++i) {
1018 d_data[i] |= rhs.d_data[i];
1019 }
1020 return *this;
1021}
1022
1023template <std::size_t N>
1025{
1026 for (std::size_t i = 0; i < k_BITSETSIZE; ++i) {
1027 d_data[i] ^= rhs.d_data[i];
1028 }
1029 return *this;
1030}
1031
1032template <std::size_t N>
1034{
1035 BSLS_ASSERT_SAFE(pos <= N);
1036
1037 if (pos) {
1038 const std::size_t shift = pos / k_BITS_PER_INT;
1039 const std::size_t offset = pos % k_BITS_PER_INT;
1040
1041 if (shift) {
1042 memmove(d_data + shift,
1043 d_data,
1044 (k_BITSETSIZE - shift) * k_BYTES_PER_INT);
1045 memset(d_data, 0, shift * k_BYTES_PER_INT);
1046 }
1047
1048 if (offset) {
1049 for (std::size_t i = k_BITSETSIZE - 1; i > shift; --i) {
1050 d_data[i] = (d_data[i] << offset)
1051 | (d_data[i-1] >> (k_BITS_PER_INT - offset));
1052 }
1053 d_data[shift] <<= offset;
1054 }
1055
1056 clearUnusedBits();
1057 }
1058 return *this;
1059}
1060
1061template <std::size_t N>
1063{
1064 BSLS_ASSERT_SAFE(pos <= N);
1065
1066 if (pos) {
1067 const std::size_t shift = pos / k_BITS_PER_INT;
1068 const std::size_t offset = pos % k_BITS_PER_INT;
1069
1070 if (shift) {
1071 memmove(d_data,
1072 d_data + shift,
1073 (k_BITSETSIZE - shift) * k_BYTES_PER_INT);
1074 memset(d_data + k_BITSETSIZE - shift, 0, shift * k_BYTES_PER_INT);
1075 }
1076
1077 if (offset) {
1078 for (std::size_t i = 0; i < k_BITSETSIZE - shift - 1; ++i) {
1079 d_data[i] = (d_data[i] >> offset)
1080 | (d_data[i+1] << (k_BITS_PER_INT - offset));
1081 }
1082 d_data[k_BITSETSIZE - shift - 1] >>= offset;
1083 }
1084
1085 clearUnusedBits();
1086 }
1087 return *this;
1088}
1089
1090template <std::size_t N>
1092{
1093 for (std::size_t i = 0; i < k_BITSETSIZE; ++i) {
1094 d_data[i] = ~d_data[i];
1095 }
1096 clearUnusedBits();
1097 return *this;
1098}
1099
1100template <std::size_t N>
1101inline
1103{
1104 BSLS_ASSERT_SAFE(pos < N);
1105
1106 const std::size_t shift = pos / k_BITS_PER_INT;
1107 const std::size_t offset = pos % k_BITS_PER_INT;
1108 d_data[shift] ^= (1 << offset);
1109 return *this;
1110}
1111
1112template <std::size_t N>
1113inline
1115{
1116 memset(d_data, 0, k_BITSETSIZE * k_BYTES_PER_INT);
1117 return *this;
1118}
1119
1120template <std::size_t N>
1121inline
1123{
1124 BSLS_ASSERT_SAFE(pos < N);
1125
1126 const std::size_t shift = pos / k_BITS_PER_INT;
1127 const std::size_t offset = pos % k_BITS_PER_INT;
1128 d_data[shift] &= ~(1 << offset);
1129 return *this;
1130}
1131
1132template <std::size_t N>
1133inline
1135{
1136 memset(d_data, 0xFF, k_BITSETSIZE * k_BYTES_PER_INT);
1137 clearUnusedBits();
1138 return *this;
1139}
1140
1141template <std::size_t N>
1142bitset<N>& bitset<N>::set(std::size_t pos, int val)
1143{
1144 BSLS_ASSERT_SAFE(pos < N);
1145
1146 const std::size_t shift = pos / k_BITS_PER_INT;
1147 const std::size_t offset = pos % k_BITS_PER_INT;
1148 if (val) {
1149 d_data[shift] |= (1 << offset);
1150 }
1151 else {
1152 d_data[shift] &= ~(1 << offset);
1153 }
1154 return *this;
1155}
1156
1157template <std::size_t N>
1158inline
1160{
1161 BSLS_ASSERT_SAFE(pos < N);
1162
1163 const std::size_t shift = pos / k_BITS_PER_INT;
1164 const std::size_t offset = pos % k_BITS_PER_INT;
1165 return typename bitset<N>::reference(&d_data[shift],
1166 static_cast<unsigned int>(offset));
1167}
1168
1169// ACCESSORS
1170template <std::size_t N>
1171inline
1173{
1174 BSLS_ASSERT_SAFE(pos <= N);
1175
1176 bitset<N> tmp(*this);
1177 return tmp <<= pos;
1178}
1179
1180template <std::size_t N>
1181inline
1183{
1184 BSLS_ASSERT_SAFE(pos <= N);
1185
1186 bitset<N> tmp(*this);
1187 return tmp >>= pos;
1188}
1189
1190template <std::size_t N>
1191inline
1193{
1194 bitset<N> tmp(*this);
1195 return tmp.flip();
1196}
1197
1198template <std::size_t N>
1200bool bitset<N>::operator[](std::size_t pos) const
1201{
1202#if defined(BSLSTL_BITSET_ALLOW_ASSERT_IN_CONSTEXPR)
1203 BSLS_ASSERT_SAFE(pos < N);
1204#endif
1205
1206 return 0 != (d_data[pos / k_BITS_PER_INT] & (1 << (pos % k_BITS_PER_INT)));
1207}
1208
1209template <std::size_t N>
1210inline
1212{
1213 return memcmp(d_data, rhs.d_data, k_BITSETSIZE * k_BYTES_PER_INT) == 0;
1214}
1215
1216template <std::size_t N>
1217inline
1219{
1220 return !operator==(rhs);
1221}
1222
1223template <std::size_t N>
1225{
1226 for (std::size_t i = 0; i < N / k_BITS_PER_INT; ++i) {
1227 if (d_data[i] != ~0u) {
1228 return false;
1229 }
1230 }
1231
1232 const std::size_t modulo = N % k_BITS_PER_INT;
1233
1234 if (modulo) {
1235 const std::size_t mask = ((1u << modulo) - 1);
1236 return d_data[k_BITSETSIZE - 1] == mask;
1237 }
1238
1239 return true;
1240}
1241
1242template <std::size_t N>
1244{
1245 for (std::size_t i = 0; i < k_BITSETSIZE; ++i) {
1246 if (d_data[i] != 0) {
1247 return true; // RETURN
1248 }
1249 }
1250 return false;
1251}
1252
1253template <std::size_t N>
1255{
1256 std::size_t sum = 0;
1257 for (std::size_t i = 0; i < k_BITSETSIZE; ++i) {
1258 sum += numOneSet(d_data[i]);
1259 }
1260 return sum;
1261}
1262
1263template <std::size_t N>
1264inline
1266{
1267 return !any();
1268}
1269
1270template <std::size_t N>
1271inline
1273{
1274 return N;
1275}
1276
1277template <std::size_t N>
1278inline
1279bool bitset<N>::test(size_t pos) const
1280{
1283 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1284 "out_of_range in bsl::bitset<>::test");
1285 }
1286 return operator[](pos);
1287}
1288
1289template <std::size_t N>
1290template <class CHAR_TYPE, class TRAITS, class ALLOCATOR>
1292 CHAR_TYPE zero,
1293 CHAR_TYPE one) const
1294{
1296 for (std::size_t i = 0; i < N; ++i) {
1297 if (this->operator[](i)) {
1298 str[N - i - 1] = one;
1299 }
1300 }
1301 return str;
1302}
1303
1304template <std::size_t N>
1305unsigned long bitset<N>::to_ulong() const
1306{
1307 enum {
1308 k_INTS_IN_LONG = sizeof(unsigned long) / sizeof(int)
1309 };
1310
1311 for (std::size_t i = k_INTS_IN_LONG; i < k_BITSETSIZE; ++i) {
1314 BloombergLP::bslstl::StdExceptUtil::throwOverflowError(
1315 "overflow in bsl::bitset<>::to_ulong");
1316 }
1317 }
1318
1319 unsigned long value = 0;
1320 const unsigned int numInts = (unsigned int) k_INTS_IN_LONG
1321 < (unsigned int) k_BITSETSIZE
1322 ? (unsigned int) k_INTS_IN_LONG
1323 : (unsigned int) k_BITSETSIZE;
1324
1325 for (unsigned int i = 0; i < numInts; ++i) {
1326 value |= (unsigned long) d_data[i] << (k_BITS_PER_INT * i);
1327 }
1328 return value;
1329}
1330
1331// FREE OPERATORS
1332template <std::size_t N>
1335{
1336 bitset<N> tmp(lhs);
1337 return tmp &= rhs;
1338}
1339
1340template <std::size_t N>
1343{
1344 bitset<N> tmp(lhs);
1345 return tmp |= rhs;
1346}
1347
1348template <std::size_t N>
1351{
1352 bitset<N> tmp(lhs);
1353 return tmp ^= rhs;
1354}
1355
1356template <class CHAR_TYPE, class TRAITS, std::size_t N>
1357std::basic_istream<CHAR_TYPE, TRAITS>&
1358operator>>(std::basic_istream<CHAR_TYPE, TRAITS>& is, bitset<N>& x)
1359{
1360 typedef typename TRAITS::int_type int_type;
1361
1363 tmp.reserve(N);
1364
1365 typename std::basic_istream<CHAR_TYPE, TRAITS>::sentry sen(is);
1366 if (sen) {
1367 std::basic_streambuf<CHAR_TYPE, TRAITS> *buffer = is.rdbuf();
1368 for (std::size_t i = 0; i < N; ++i) {
1369 static int_type eof = TRAITS::eof();
1370 int_type cint = buffer->sbumpc();
1371 if (TRAITS::eq_int_type(cint, eof)) {
1372 is.setstate(std::ios_base::eofbit);
1373 break;
1374 }
1375 else {
1376 CHAR_TYPE cchar = TRAITS::to_char_type(cint);
1377 char c = is.narrow(cchar, '*');
1378
1379 if (c == '0' || c == '1') {
1380 tmp.push_back(c);
1381 }
1382 else if (TRAITS::eq_int_type(buffer->sputbackc(cchar), eof)) {
1383 is.setstate(std::ios_base::failbit);
1384 break;
1385 }
1386 }
1387 }
1388
1389 if (tmp.empty()) {
1390 is.setstate(std::ios_base::failbit);
1391 }
1392 else {
1393 x = bitset<N>(tmp);
1394 }
1395 }
1396 return is;
1397}
1398
1399template <class CHAR_TYPE, class TRAITS, std::size_t N>
1400inline
1401std::basic_ostream<CHAR_TYPE, TRAITS>&
1402operator<<(std::basic_ostream<CHAR_TYPE, TRAITS>& os, const bitset<N>& x)
1403{
1404 basic_string<CHAR_TYPE, TRAITS, allocator<CHAR_TYPE> > tmp (
1405 x.template to_string<CHAR_TYPE, TRAITS, allocator<CHAR_TYPE> >());
1406 return os << tmp;
1407}
1408
1409} // close namespace bsl
1410
1411#if defined(BSLSTL_BITSET_MSVC_CANNOT_PARSE_DEFAULTS_WITH_COLONS)
1412# undef BSLSTL_BITSET_MSVC_CANNOT_PARSE_DEFAULTS_WITH_COLONS
1413#endif
1414
1415#endif
1416
1417// ----------------------------------------------------------------------------
1418// Copyright 2016 Bloomberg Finance L.P.
1419//
1420// Licensed under the Apache License, Version 2.0 (the "License");
1421// you may not use this file except in compliance with the License.
1422// You may obtain a copy of the License at
1423//
1424// http://www.apache.org/licenses/LICENSE-2.0
1425//
1426// Unless required by applicable law or agreed to in writing, software
1427// distributed under the License is distributed on an "AS IS" BASIS,
1428// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1429// See the License for the specific language governing permissions and
1430// limitations under the License.
1431// ----------------------------- END-OF-FILE ----------------------------------
1432
1433/** @} */
1434/** @} */
1435/** @} */
Definition bslstl_bitset.h:265
Definition bslma_bslallocator.h:580
Definition bslstl_string.h:1281
void reserve(size_type newCapacity=0)
Definition bslstl_string.h:5407
size_type size() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:6592
AllocatorTraits::size_type size_type
Definition bslstl_string.h:1303
void push_back(CHAR_TYPE character)
Append the specified character to this string.
Definition bslstl_string.h:5699
static const size_type npos
Definition bslstl_string.h:1676
bool empty() const BSLS_KEYWORD_NOEXCEPT
Return true if this string has length 0, and false otherwise.
Definition bslstl_string.h:6631
Definition bslstl_bitset.h:350
reference & flip() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:785
bool operator~() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:801
reference & operator=(bool x) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:757
Definition bslstl_bitset.h:326
bitset operator>>(std::size_t pos) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1182
basic_string< CHAR_TYPE, TRAITS, ALLOCATOR > to_string(CHAR_TYPE zero=CHAR_TYPE('0'), CHAR_TYPE one=CHAR_TYPE('1')) const
Definition bslstl_bitset.h:1291
bool all() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1224
bool operator==(const bitset &rhs) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1211
bitset & set() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1134
bitset & operator^=(const bitset &rhs) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1024
bitset & flip() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1091
bitset & operator>>=(std::size_t pos) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1062
bool test(size_t pos) const
Definition bslstl_bitset.h:1279
unsigned long to_ulong() const
Definition bslstl_bitset.h:1305
BSLS_KEYWORD_CONSTEXPR bitset() BSLS_KEYWORD_NOEXCEPT
Create a bitset with all bits initialized to 0.
Definition bslstl_bitset.h:931
bool any() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1243
bitset & operator&=(const bitset &rhs) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1006
bitset operator~() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1192
bitset operator<<(std::size_t pos) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1172
reference operator[](std::size_t pos)
Definition bslstl_bitset.h:1159
bitset & operator|=(const bitset &rhs) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1015
std::size_t count() const BSLS_KEYWORD_NOEXCEPT
Return the number of bits in this bitset that have the value of 1.
Definition bslstl_bitset.h:1254
BSLS_KEYWORD_CONSTEXPR std::size_t size() const BSLS_KEYWORD_NOEXCEPT
Return the number of bits this bitset holds.
Definition bslstl_bitset.h:1272
bitset & operator<<=(std::size_t pos) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1033
bool operator!=(const bitset &rhs) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1218
bool none() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1265
bitset & reset() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1114
Definition bslstl_set.h:657
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:588
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
#define BSLS_PERFORMANCEHINT_UNLIKELY_HINT
Definition bsls_performancehint.h:484
#define BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(expr)
Definition bsls_performancehint.h:452
Definition bdlb_printmethods.h:283
bitset< N > operator|(const bitset< N > &lhs, const bitset< N > &rhs) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1341
bitset< N > operator^(const bitset< N > &lhs, const bitset< N > &rhs) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1349
std::basic_istream< CHAR_TYPE, TRAITS > & operator>>(std::basic_istream< CHAR_TYPE, TRAITS > &is, bitset< N > &x)
Definition bslstl_bitset.h:1358
std::basic_ostream< CHAR_TYPE, TRAITS > & operator<<(std::basic_ostream< CHAR_TYPE, TRAITS > &os, const bitset< N > &x)
Definition bslstl_bitset.h:1402
BSLS_KEYWORD_CONSTEXPR size_t size(const TYPE(&)[DIMENSION]) BSLS_KEYWORD_NOEXCEPT
Return the dimension of the specified array argument.
Definition bslstl_iterator.h:1331
string to_string(int value)
bitset< N > operator&(const bitset< N > &lhs, const bitset< N > &rhs) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_bitset.h:1333
BSLS_KEYWORD_CONSTEXPR CONTAINER::value_type * data(CONTAINER &container)
Definition bslstl_iterator.h:1231
Definition bdldfp_decimal.h:5188
Definition bslstl_bitset.h:228
static void defaultInit(unsigned int *data, std::size_t size, unsigned long long val=0)
@ k_BITS_PER_INT
Definition bslstl_bitset.h:231
@ k_BYTES_PER_INT
Definition bslstl_bitset.h:230
@ k_INTS_IN_LLONG
Definition bslstl_bitset.h:233
@ k_INTS_IN_LONG
Definition bslstl_bitset.h:232
BSLMF_ASSERT(k_INTS_IN_LLONG==2)
Definition bslmf_integralconstant.h:244