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