Embedded Template Library 1.0
Loading...
Searching...
No Matches
bitset_new.h
Go to the documentation of this file.
1
2/******************************************************************************
3The MIT License(MIT)
4
5Embedded Template Library.
6https://github.com/ETLCPP/etl
7https://www.etlcpp.com
8
9Copyright(c) 2022 John Wellbelove
10
11Permission is hereby granted, free of charge, to any person obtaining a copy
12of this software and associated documentation files(the "Software"), to deal
13in the Software without restriction, including without limitation the rights
14to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
15copies of the Software, and to permit persons to whom the Software is
16furnished to do so, subject to the following conditions :
17
18The above copyright notice and this permission notice shall be included in all
19copies or substantial portions of the Software.
20
21THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
24AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27SOFTWARE.
28******************************************************************************/
29
30#ifndef ETL_BITSET_NEW_INCLUDED
31#define ETL_BITSET_NEW_INCLUDED
32
33#include "../platform.h"
34#include "../algorithm.h"
35#include "../binary.h"
36#include "../char_traits.h"
37#include "../enum_type.h"
38#include "../error_handler.h"
39#include "../exception.h"
40#include "../integral_limits.h"
41#include "../iterator.h"
42#include "../largest.h"
43#include "../log.h"
44#include "../nullptr.h"
45#include "../smallest.h"
46#include "../span.h"
47#include "../static_assert.h"
48#include "../string.h"
49
50#include <stddef.h>
51#include <stdint.h>
52#include <string.h>
53
54#if ETL_USING_STL
55 #include <algorithm>
56#endif
57
58#include "minmax_push.h"
59
60#if defined(ETL_COMPILER_KEIL)
61 #pragma diag_suppress 1300
62#endif
63
64#if ETL_USING_CPP11
65 #define ETL_STR(x) x
66 #define ETL_STRL(x) L##x
67 #define ETL_STRu(x) u##x
68 #define ETL_STRU(x) U##x
69#else
70 #define ETL_STR(x) x
71 #define ETL_STRL(x) x
72 #define ETL_STRu(x) x
73 #define ETL_STRU(x) x
74#endif
75
76//*****************************************************************************
80//*****************************************************************************
81
82namespace etl
83{
84 //***************************************************************************
88 //***************************************************************************
90 {
91 enum enum_type
92 {
93 Undefined = 0,
94 Single = 1,
95 Multi = 2
96 };
97
99 ETL_ENUM_TYPE(Undefined, "Undefined")
100 ETL_ENUM_TYPE(Single, "Single")
101 ETL_ENUM_TYPE(Multi, "Multi")
102 ETL_END_ENUM_TYPE
103 };
104
105 //***************************************************************************
108 //***************************************************************************
109 class bitset_exception : public etl::exception
110 {
111 public:
112
113 bitset_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
114 : exception(reason_, file_name_, line_number_)
115 {
116 }
117 };
118
119 //***************************************************************************
122 //***************************************************************************
123 class bitset_string_too_small : public bitset_exception
124 {
125 public:
126
127 bitset_string_too_small(string_type file_name_, numeric_type line_number_)
128 : bitset_exception(ETL_ERROR_TEXT("bitset:type_too_small", ETL_BITSET_FILE_ID"A"), file_name_, line_number_)
129 {
130 }
131 };
132
133 //***************************************************************************
136 //***************************************************************************
137 class bitset_overflow : public bitset_exception
138 {
139 public:
140
141 bitset_overflow(string_type file_name_, numeric_type line_number_)
142 : bitset_exception(ETL_ERROR_TEXT("bitset:overflow", ETL_BITSET_FILE_ID"B"), file_name_, line_number_)
143 {
144 }
145 };
146
147 //***************************************************************************
150 //***************************************************************************
151 class bitset_invalid_buffer : public bitset_exception
152 {
153 public:
154
155 bitset_invalid_buffer(string_type file_name_, numeric_type line_number_)
156 : bitset_exception(ETL_ERROR_TEXT("bitset:invalid buffer", ETL_BITSET_FILE_ID"C"), file_name_, line_number_)
157 {
158 }
159 };
160
161 //***************************************************************************
162 namespace private_bitset
163 {
164 template <typename TElement>
166 {
167 public:
168
169 typedef TElement element_type;
170 typedef TElement* pointer;
171 typedef const TElement* const_pointer;
172 typedef size_t size_type;
173
174 static ETL_CONSTANT size_t npos = etl::integral_limits<size_t>::max;
175 static ETL_CONSTANT size_t Bits_Per_Element = etl::integral_limits<TElement>::bits;
176 static ETL_CONSTANT TElement All_Set_Element = etl::integral_limits<TElement>::max;
177 static ETL_CONSTANT TElement All_Clear_Element = element_type(0);
178 };
179
180 template <typename TElement>
181 ETL_CONSTANT size_t bitset_impl_common<TElement>::npos;
182
183 template <typename TElement>
184 ETL_CONSTANT size_t bitset_impl_common<TElement>::Bits_Per_Element;
185
186 template <typename TElement>
187 ETL_CONSTANT TElement bitset_impl_common<TElement>::All_Set_Element;
188
189 template <typename TElement>
190 ETL_CONSTANT TElement bitset_impl_common<TElement>::All_Clear_Element;
191 } // namespace private_bitset
192
193 //*************************************************************************
196 //*************************************************************************
197 template <typename TElement, char Bitset_Layout>
199
200 //*************************************************************************
203 //*************************************************************************
204 template <typename TElement>
205 class bitset_impl<TElement, etl::bitset_storage_model::Single> : public etl::private_bitset::bitset_impl_common<TElement>
206 {
207 public:
208
209 using typename etl::private_bitset::bitset_impl_common<TElement>::element_type;
210 using typename etl::private_bitset::bitset_impl_common<TElement>::pointer;
211 using typename etl::private_bitset::bitset_impl_common<TElement>::const_pointer;
212
213 using etl::private_bitset::bitset_impl_common<TElement>::Bits_Per_Element;
214 using etl::private_bitset::bitset_impl_common<TElement>::All_Set_Element;
215 using etl::private_bitset::bitset_impl_common<TElement>::All_Clear_Element;
216
217 using etl::private_bitset::bitset_impl_common<TElement>::npos;
218
219 //*************************************************************************
221 //*************************************************************************
222 static ETL_CONSTEXPR14 void set_all(pointer pbuffer, size_t /*number_of_elements*/, element_type top_mask) ETL_NOEXCEPT
223 {
224 *pbuffer = All_Set_Element & top_mask;
225 }
226
227 //*************************************************************************
229 //*************************************************************************
230 static ETL_CONSTEXPR14 void set_position(pointer pbuffer, size_t position, bool value = true)
231 {
232 const element_type mask = element_type(element_type(1) << position);
233
234 if (value == true)
235 {
236 *pbuffer |= mask;
237 }
238 else
239 {
240 *pbuffer &= ~mask;
241 }
242 }
243
244 //*************************************************************************
246 //*************************************************************************
247 template <size_t Position>
248 static ETL_CONSTEXPR14 void set_position(pointer pbuffer, bool value = true)
249 {
250 const element_type mask = element_type(element_type(1) << Position);
251
252 if (value == true)
253 {
254 *pbuffer |= mask;
255 }
256 else
257 {
258 *pbuffer &= ~mask;
259 }
260 }
261
262 //*************************************************************************
264 //*************************************************************************
265 template <size_t Position, bool Value>
266 static ETL_CONSTEXPR14 void set_position(pointer pbuffer)
267 {
268 const element_type mask = element_type(element_type(1) << Position);
269
270 if (Value == true)
271 {
272 *pbuffer |= mask;
273 }
274 else
275 {
276 *pbuffer &= ~mask;
277 }
278 }
279
280 //*************************************************************************
282 //*************************************************************************
283 static ETL_CONSTEXPR14 void reset_all(pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
284 {
285 *pbuffer = All_Clear_Element;
286 }
287
288 //*************************************************************************
290 //*************************************************************************
291 static ETL_CONSTEXPR14
292
293 void
294 reset_position(pointer pbuffer, size_t position)
295 {
296 const element_type mask = element_type(element_type(1) << position);
297 *pbuffer &= ~mask;
298 }
299
300 //*************************************************************************
302 //*************************************************************************
303 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, const char* text) ETL_NOEXCEPT
304 {
305 reset_all(pbuffer, 1U);
306
307 if (text != ETL_NULLPTR)
308 {
309 size_t string_length = etl::strlen(text);
310
311 // Build from the string.
312 string_length = etl::min(active_bits, string_length);
313
314 if (string_length == 0U)
315 {
316 return;
317 }
318
319 element_type mask = element_type(element_type(1) << (string_length - 1U));
320
321 for (size_t i = 0U; i < string_length; ++i)
322 {
323 if (text[i] == ETL_STR('1'))
324 {
325 *pbuffer |= mask;
326 }
327
328 mask >>= 1U;
329 }
330 }
331 }
332
333 //*************************************************************************
335 //*************************************************************************
336 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, const wchar_t* text) ETL_NOEXCEPT
337 {
338 reset_all(pbuffer, 1U);
339
340 if (text != ETL_NULLPTR)
341 {
342 size_t string_length = etl::strlen(text);
343
344 // Build from the string.
345 string_length = etl::min(active_bits, string_length);
346
347 if (string_length == 0U)
348 {
349 return;
350 }
351
352 element_type mask = element_type(element_type(1) << (string_length - 1U));
353
354 for (size_t i = 0U; i < string_length; ++i)
355 {
356 if (text[i] == ETL_STRL('1'))
357 {
358 *pbuffer |= mask;
359 }
360
361 mask >>= 1U;
362 }
363 }
364 }
365
366 //*************************************************************************
368 //*************************************************************************
369 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, const char16_t* text) ETL_NOEXCEPT
370 {
371 reset_all(pbuffer, 1U);
372
373 if (text != ETL_NULLPTR)
374 {
375 size_t string_length = etl::strlen(text);
376
377 // Build from the string.
378 string_length = etl::min(active_bits, string_length);
379
380 if (string_length == 0U)
381 {
382 return;
383 }
384
385 element_type mask = element_type(element_type(1) << (string_length - 1U));
386
387 for (size_t i = 0U; i < string_length; ++i)
388 {
389 if (text[i] == ETL_STRu('1'))
390 {
391 *pbuffer |= mask;
392 }
393
394 mask >>= 1U;
395 }
396 }
397 }
398
399 //*************************************************************************
401 //*************************************************************************
402 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, const char32_t* text) ETL_NOEXCEPT
403 {
404 reset_all(pbuffer, 1U);
405
406 if (text != ETL_NULLPTR)
407 {
408 size_t string_length = etl::strlen(text);
409
410 // Build from the string.
411 string_length = etl::min(active_bits, string_length);
412
413 if (string_length == 0U)
414 {
415 return;
416 }
417
418 element_type mask = element_type(element_type(1) << (string_length - 1U));
419
420 for (size_t i = 0U; i < string_length; ++i)
421 {
422 if (text[i] == ETL_STRU('1'))
423 {
424 *pbuffer |= mask;
425 }
426
427 mask >>= 1U;
428 }
429 }
430 }
431
432 //*************************************************************************
434 //*************************************************************************
435 template <typename T>
436 static ETL_CONSTEXPR14 T value(const_pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
437 {
438 return T(*pbuffer);
439 }
440
441 //*************************************************************************
443 //*************************************************************************
444 template <typename T>
445 static ETL_CONSTEXPR14 T extract(const_pointer pbuffer, size_t position, size_t length = etl::integral_limits<T>::bits)
446 {
447 typedef typename etl::make_unsigned<T>::type unsigned_t;
448
449 const unsigned_t Mask = etl::make_lsb_mask<unsigned_t>(length);
450 const unsigned_t Shift = position % Bits_Per_Element;
451
452 unsigned_t value = static_cast<unsigned_t>(*pbuffer >> Shift) & Mask;
453
455 {
456 value = static_cast<unsigned_t>(etl::sign_extend<T>(static_cast<T>(value), length));
457 }
458
459 return static_cast<T>(value);
460 }
461
462 //*************************************************************************
464 //*************************************************************************
465#if ETL_USING_CPP11
466 template <typename T, size_t Position, size_t Length = etl::integral_limits<T>::bits>
467#else
468 template <typename T, size_t Position, size_t Length>
469#endif
470 static ETL_CONSTEXPR14 T extract(const_pointer pbuffer)
471 {
472 typedef typename etl::make_unsigned<T>::type unsigned_t;
473
474 const unsigned_t Mask = etl::make_lsb_mask<unsigned_t>(Length);
475 const unsigned_t Shift = Position % Bits_Per_Element;
476
477 unsigned_t value = static_cast<unsigned_t>(*pbuffer >> Shift) & Mask;
478
480 {
481 value = static_cast<unsigned_t>(etl::sign_extend<T>(static_cast<T>(value), Length));
482 }
483
484 return static_cast<T>(value);
485 }
486
487 //*************************************************************************
491 //*************************************************************************
492 static ETL_CONSTEXPR14 bool test(const_pointer pbuffer, size_t position)
493 {
494 const element_type mask = element_type(element_type(1) << position);
495 return (*pbuffer & mask) != 0U;
496 }
497
498 //*************************************************************************
500 //*************************************************************************
501 static ETL_CONSTEXPR14 size_t count(const_pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
502 {
503 return etl::count_bits(*pbuffer);
504 }
505
506 //*************************************************************************
507 // Are all the bits sets?
508 //*************************************************************************
509 static ETL_CONSTEXPR14 bool all(const_pointer pbuffer, size_t /*number_of_elements*/, element_type top_mask) ETL_NOEXCEPT
510 {
511 return (*pbuffer & top_mask) == top_mask;
512 }
513
514 //*************************************************************************
515 // Are all the mask bits sets?
516 //*************************************************************************
517 static ETL_CONSTEXPR14 bool all(const_pointer pbuffer, size_t /*number_of_elements*/, element_type top_mask, element_type mask) ETL_NOEXCEPT
518 {
519 return (*pbuffer & top_mask & mask) == mask;
520 }
521
522 //*************************************************************************
524 //*************************************************************************
525 static ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
526 {
527 return *pbuffer == All_Clear_Element;
528 }
529
530 //*************************************************************************
532 //*************************************************************************
533 static ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t /*number_of_elements*/, element_type mask) ETL_NOEXCEPT
534 {
535 return (*pbuffer & mask) == All_Clear_Element;
536 }
537
538 //*************************************************************************
540 //*************************************************************************
541 static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
542 {
543 return *pbuffer != All_Clear_Element;
544 }
545
546 //*************************************************************************
548 //*************************************************************************
549 static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t /*number_of_elements*/, element_type mask) ETL_NOEXCEPT
550 {
551 return (*pbuffer & mask) != All_Clear_Element;
552 }
553
554 //*************************************************************************
556 //*************************************************************************
557 static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
558 {
559 *pbuffer = ~*pbuffer;
560 }
561
562 //*************************************************************************
564 //*************************************************************************
565 static ETL_CONSTEXPR14 void flip_bits(pointer pbuffer, element_type mask = etl::integral_limits<element_type>::max) ETL_NOEXCEPT
566 {
567 *pbuffer ^= mask;
568 }
569
570 //*************************************************************************
572 //*************************************************************************
573 static ETL_CONSTEXPR14 void flip_position(pointer pbuffer, size_t position)
574 {
575 const element_type mask = element_type(element_type(1) << position);
576 *pbuffer ^= mask;
577 }
578
579 //*************************************************************************
581 //*************************************************************************
582 template <typename TString>
583 static ETL_CONSTEXPR14 TString to_string(const_pointer pbuffer, size_t active_bits,
584 typename TString::value_type zero = typename TString::value_type('0'),
585 typename TString::value_type one = typename TString::value_type('1'))
586 {
587 TString result;
588
589 result.resize(active_bits, '\0');
590
591 // Check that the string type can contain the digits.
592 ETL_ASSERT_OR_RETURN_VALUE(result.size() == active_bits, ETL_ERROR(etl::bitset_string_too_small), result);
593
594 for (size_t i = active_bits; i > 0; --i)
595 {
596 result[active_bits - i] = test(pbuffer, i - 1) ? one : zero;
597 }
598
599 return result;
600 }
601
602 //*************************************************************************
607 //*************************************************************************
608 static ETL_CONSTEXPR14 size_t find_next(const_pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, bool state, size_t position)
609 ETL_NOEXCEPT
610 {
611 if (position < active_bits)
612 {
613 // Where to start.
614 size_t bit = position;
615
616 element_type mask = 1U << position;
617
618 // Needs checking?
619 if ((state && (*pbuffer != All_Clear_Element)) || (!state && (*pbuffer != All_Set_Element)))
620 {
621 // For each bit in the element...
622 while (bit < active_bits)
623 {
624 // Equal to the required state?
625 if (((*pbuffer & mask) != 0) == state)
626 {
627 return bit;
628 }
629
630 // Move on to the next bit.
631 mask <<= 1;
632 ++bit;
633 }
634 }
635 }
636
637 return npos;
638 }
639
640 //*************************************************************************
643 //*************************************************************************
644 static ETL_CONSTEXPR14 void operator_assignment(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
645 {
646 *lhs_pbuffer = *rhs_pbuffer;
647 }
648
649 //*************************************************************************
652 //*************************************************************************
653 static ETL_CONSTEXPR14 void operator_and(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
654 {
655 *lhs_pbuffer &= *rhs_pbuffer;
656 }
657
658 //*************************************************************************
661 //*************************************************************************
662 static ETL_CONSTEXPR14 void operator_or(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
663 {
664 *lhs_pbuffer |= *rhs_pbuffer;
665 }
666
667 //*************************************************************************
670 //*************************************************************************
671 static ETL_CONSTEXPR14 void operator_xor(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
672 {
673 *lhs_pbuffer ^= *rhs_pbuffer;
674 }
675
676 //*************************************************************************
679 //*************************************************************************
680 static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
681 {
682 *pbuffer = ~*pbuffer;
683 }
684
685 //*************************************************************************
687 //*************************************************************************
688 static ETL_CONSTEXPR14 void operator_shift_left(pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, size_t shift) ETL_NOEXCEPT
689 {
690 if (shift >= active_bits)
691 {
692 reset_all(pbuffer, 1U);
693 }
694 else
695 {
696 *pbuffer <<= shift;
697 }
698 }
699
700 //*************************************************************************
702 //*************************************************************************
703 static ETL_CONSTEXPR14 void operator_shift_right(pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, size_t shift) ETL_NOEXCEPT
704 {
705 if (shift >= active_bits)
706 {
707 reset_all(pbuffer, 1U);
708 }
709 else
710 {
711 *pbuffer >>= shift;
712 }
713 }
714
715 //*************************************************************************
717 //*************************************************************************
718 static ETL_CONSTEXPR14 bool operator_equality(const_pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
719 {
720 return (*lhs_pbuffer == *rhs_pbuffer);
721 }
722
723 //*************************************************************************
725 //*************************************************************************
726 template <typename TElementType>
727 static ETL_CONSTEXPR14 void initialise(pointer pbuffer, size_t /*number_of_elements*/, unsigned long long value) ETL_NOEXCEPT
728 {
729 *pbuffer = static_cast<TElementType>(value);
730 }
731
732 //*************************************************************************
734 //*************************************************************************
735 static ETL_CONSTEXPR14 void swap(pointer lhs_pbuffer, pointer rhs_pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
736 {
737 element_type temp = *lhs_pbuffer;
738 *lhs_pbuffer = *rhs_pbuffer;
739 *rhs_pbuffer = temp;
740 }
741 };
742
743 //*************************************************************************
746 //*************************************************************************
747 template <typename TElement>
748 class bitset_impl<TElement, etl::bitset_storage_model::Multi> : public etl::private_bitset::bitset_impl_common<TElement>
749 {
750 private:
751
753
754 public:
755
756 using typename etl::private_bitset::bitset_impl_common<TElement>::element_type;
757 using typename etl::private_bitset::bitset_impl_common<TElement>::pointer;
758 using typename etl::private_bitset::bitset_impl_common<TElement>::const_pointer;
759
760 using etl::private_bitset::bitset_impl_common<TElement>::Bits_Per_Element;
761 using etl::private_bitset::bitset_impl_common<TElement>::All_Set_Element;
762 using etl::private_bitset::bitset_impl_common<TElement>::All_Clear_Element;
763
764 using etl::private_bitset::bitset_impl_common<TElement>::npos;
765
766 //*************************************************************************
768 //*************************************************************************
769 template <size_t Position, size_t Length, size_t Bits_Per_Element>
771 {
772 static
773 ETL_CONSTANT bool value = ((Position + Length - 1) >> etl::log2<Bits_Per_Element>::value) == (Position >> etl::log2<Bits_Per_Element>::value);
774 };
775
776 //*************************************************************************
780 //*************************************************************************
781 static ETL_CONSTEXPR14 bool test(const_pointer pbuffer, size_t position) ETL_NOEXCEPT
782 {
783 size_t index = position >> etl::log2<Bits_Per_Element>::value;
784 element_type mask = element_type(1) << (position & (Bits_Per_Element - 1));
785
786 return (pbuffer[index] & mask) != 0;
787 }
788
789 //*************************************************************************
791 //*************************************************************************
792 static ETL_CONSTEXPR14 size_t count(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
793 {
794 size_t count = 0;
795
796 while (number_of_elements-- != 0)
797 {
798 count += etl::count_bits(*pbuffer++);
799 }
800
801 return count;
802 }
803
804 //*************************************************************************
805 // Are all the bits sets?
806 //*************************************************************************
807 static ETL_CONSTEXPR14 bool all(const_pointer pbuffer, size_t number_of_elements, element_type top_mask) ETL_NOEXCEPT
808 {
809 // All but the last.
810 while (number_of_elements-- != 1U)
811 {
812 if (*pbuffer++ != All_Set_Element)
813 {
814 return false;
815 }
816 }
817
818 // The last.
819 if ((*pbuffer & top_mask) != top_mask)
820 {
821 return false;
822 }
823
824 return true;
825 }
826
827 //*************************************************************************
829 //*************************************************************************
830 static ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
831 {
832 while (number_of_elements-- != 0)
833 {
834 if (*pbuffer++ != 0)
835 {
836 return false;
837 }
838 }
839
840 return true;
841 }
842
843 //*************************************************************************
845 //*************************************************************************
846 static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
847 {
848 bool any_set = false;
849
850 while (number_of_elements-- != 0)
851 {
852 if (*pbuffer++ != All_Clear_Element)
853 {
854 any_set = true;
855 break;
856 }
857 }
858
859 return any_set;
860 }
861
862 //*************************************************************************
864 //*************************************************************************
865 static ETL_CONSTEXPR14 void set_all(pointer pbuffer, size_t number_of_elements, element_type top_mask) ETL_NOEXCEPT
866 {
867 while (number_of_elements-- != 1U)
868 {
869 *pbuffer++ = All_Set_Element;
870 }
871
872 *pbuffer = (All_Set_Element & top_mask);
873 }
874
875 //*************************************************************************
877 //*************************************************************************
878 static ETL_CONSTEXPR14 void set_position(pointer pbuffer, size_t position, bool value = true) ETL_NOEXCEPT
879 {
880 size_t index = position >> etl::log2<Bits_Per_Element>::value;
881 element_type bit = element_type(1) << (position & (Bits_Per_Element - 1));
882
883 if (value == true)
884 {
885 pbuffer[index] |= bit;
886 }
887 else
888 {
889 pbuffer[index] &= ~bit;
890 }
891 }
892
893 //*************************************************************************
895 //*************************************************************************
896 template <size_t Position>
897 static ETL_CONSTEXPR14 void set_position(pointer pbuffer, bool value = true)
898 {
899 size_t index = Position >> etl::log2<Bits_Per_Element>::value;
900 element_type bit = element_type(1) << (Position & (Bits_Per_Element - 1));
901
902 if (value == true)
903 {
904 pbuffer[index] |= bit;
905 }
906 else
907 {
908 pbuffer[index] &= ~bit;
909 }
910 }
911
912 //*************************************************************************
914 //*************************************************************************
915 template <size_t Position, bool Value>
916 static ETL_CONSTEXPR14 void set_position(pointer pbuffer)
917 {
918 size_t index = Position >> etl::log2<Bits_Per_Element>::value;
919 element_type bit = element_type(1) << (Position & (Bits_Per_Element - 1));
920
921 if (Value == true)
922 {
923 pbuffer[index] |= bit;
924 }
925 else
926 {
927 pbuffer[index] &= ~bit;
928 }
929 }
930
931 //*************************************************************************
933 //*************************************************************************
934 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const char* text) ETL_NOEXCEPT
935 {
936 if (text == ETL_NULLPTR)
937 {
938 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
939 }
940 else
941 {
942 size_t string_length = etl::strlen(text);
943 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
944
945 // Only reset elements we need to.
946 while (index != number_of_elements)
947 {
948 pbuffer[index++] = All_Clear_Element;
949 }
950
951 // Build from the string.
952 size_t i = etl::min(total_bits, string_length);
953
954 while (i > 0)
955 {
956 set_position(pbuffer, --i, *text++ == ETL_STR('1'));
957 }
958 }
959 }
960
961 //*************************************************************************
963 //*************************************************************************
964 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const wchar_t* text) ETL_NOEXCEPT
965 {
966 if (text == ETL_NULLPTR)
967 {
968 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
969 }
970 else
971 {
972 size_t string_length = etl::strlen(text);
973 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
974
975 // Only reset elements we need to.
976 while (index != number_of_elements)
977 {
978 pbuffer[index++] = All_Clear_Element;
979 }
980
981 // Build from the string.
982 size_t i = etl::min(total_bits, string_length);
983
984 while (i > 0)
985 {
986 set_position(pbuffer, --i, *text++ == ETL_STRL('1'));
987 }
988 }
989 }
990
991 //*************************************************************************
993 //*************************************************************************
994 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const char16_t* text) ETL_NOEXCEPT
995 {
996 if (text == ETL_NULLPTR)
997 {
998 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
999 }
1000 else
1001 {
1002 size_t string_length = etl::strlen(text);
1003 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
1004
1005 // Only reset elements we need to.
1006 while (index != number_of_elements)
1007 {
1008 pbuffer[index++] = All_Clear_Element;
1009 }
1010
1011 // Build from the string.
1012 size_t i = etl::min(total_bits, string_length);
1013
1014 while (i > 0)
1015 {
1016 set_position(pbuffer, --i, *text++ == ETL_STRu('1'));
1017 }
1018 }
1019 }
1020
1021 //*************************************************************************
1023 //*************************************************************************
1024 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const char32_t* text) ETL_NOEXCEPT
1025 {
1026 if (text == ETL_NULLPTR)
1027 {
1028 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
1029 }
1030 else
1031 {
1032 size_t string_length = etl::strlen(text);
1033 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
1034
1035 // Only reset elements we need to.
1036 while (index != number_of_elements)
1037 {
1038 pbuffer[index++] = All_Clear_Element;
1039 }
1040
1041 // Build from the string.
1042 size_t i = etl::min(total_bits, string_length);
1043
1044 while (i > 0)
1045 {
1046 set_position(pbuffer, --i, *text++ == ETL_STRU('1'));
1047 }
1048 }
1049 }
1050
1051 //*************************************************************************
1053 //*************************************************************************
1054 static ETL_CONSTEXPR14 void reset_all(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1055 {
1056 while (number_of_elements-- != 0U)
1057 {
1058 *pbuffer++ = All_Clear_Element;
1059 }
1060 }
1061
1062 //*************************************************************************
1064 //*************************************************************************
1065 static ETL_CONSTEXPR14 void reset_position(pointer pbuffer, size_t position) ETL_NOEXCEPT
1066 {
1067 const size_t index = position >> etl::log2<Bits_Per_Element>::value;
1068 const element_type bit = element_type(1) << (position & (Bits_Per_Element - 1));
1069
1070 pbuffer[index] &= ~bit;
1071 }
1072
1073 //*************************************************************************
1075 //*************************************************************************
1076 template <typename T>
1077 static ETL_CONSTEXPR14 T value(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1078 {
1079 T v = T(0);
1080
1081 const bool OK = (sizeof(T) * CHAR_BIT) >= (number_of_elements * Bits_Per_Element);
1082
1083 if (OK)
1084 {
1085 uint_least8_t shift = 0U;
1086
1087 for (size_t i = 0UL; i < number_of_elements; ++i)
1088 {
1089 v |= T(typename etl::make_unsigned<T>::type(pbuffer[i]) << shift);
1090 shift += uint_least8_t(Bits_Per_Element);
1091 }
1092 }
1093
1094 return v;
1095 }
1096
1097 //*************************************************************************
1099 //*************************************************************************
1100 template <typename T>
1101 static ETL_CONSTEXPR14 typename etl::make_unsigned<T>::type extract_from_multiple_elements(const element_type* pbuffer, size_t element_index,
1102 size_t active_bits_in_msb, size_t length) ETL_NOEXCEPT
1103 {
1104 typedef typename etl::make_unsigned<T>::type unsigned_t;
1105
1106 unsigned_t value(0);
1107
1108 // Extract the first element, if partially filled.
1109 if (active_bits_in_msb < Bits_Per_Element)
1110 {
1111 element_type mask = etl::make_lsb_mask< element_type>(active_bits_in_msb);
1112 value = pbuffer[element_index] & mask;
1113 length -= active_bits_in_msb;
1114 if (length >= Bits_Per_Element)
1115 {
1116 value = value << Bits_Per_Element;
1117 }
1118 --element_index;
1119 }
1120
1121 // Loop through the fully filled elements
1122 while (length >= Bits_Per_Element)
1123 {
1124 value |= pbuffer[element_index];
1125 length -= Bits_Per_Element;
1126 if (length >= Bits_Per_Element)
1127 {
1128 value = value << Bits_Per_Element;
1129 }
1130 --element_index;
1131 }
1132
1133 // Extract the last element, if partially filled.
1134 if (length != 0)
1135 {
1136 value = value << length;
1137 element_type mask = etl::make_lsb_mask< element_type>(length);
1138 value |= (pbuffer[element_index] >> (Bits_Per_Element - length)) & mask;
1139 }
1140
1141 return value;
1142 }
1143
1144 //*************************************************************************
1147 //*************************************************************************
1148 template <typename T>
1149 static ETL_CONSTEXPR14 typename etl::make_unsigned<T>::type extract_from_buffer(const_pointer pbuffer, size_t position, size_t length)
1150 ETL_NOEXCEPT
1151 {
1152 typedef typename etl::make_unsigned<T>::type unsigned_t;
1153
1154 unsigned_t value(0);
1155
1156 const size_t Msb_Element_Index = (position + length - 1) >> etl::log2<Bits_Per_Element>::value;
1157 const size_t Lsb_Element_Index = position >> etl::log2<Bits_Per_Element>::value;
1158
1159 // Is the value contained within one element?
1160 if (Msb_Element_Index == Lsb_Element_Index)
1161 {
1162 const unsigned_t Mask = etl::make_lsb_mask< unsigned_t>(length);
1163 const unsigned_t Shift = position % Bits_Per_Element;
1164
1165 value = static_cast<unsigned_t>(pbuffer[Msb_Element_Index] >> Shift) & Mask;
1166 }
1167 else
1168 {
1169 // Get the number of active bits in the msb element
1170 size_t active_bits_in_msb = (position + length) - (static_cast<size_t>(Msb_Element_Index) * Bits_Per_Element);
1171
1172 // Start with index of the element containing the msb.
1173 size_t element_index = Msb_Element_Index;
1174
1175 value = extract_from_multiple_elements<T>(pbuffer, element_index, active_bits_in_msb, length);
1176 }
1177
1178 return value;
1179 }
1180
1181 //*************************************************************************
1184 //*************************************************************************
1185 template <typename T, size_t Position, size_t Length>
1186 static ETL_CONSTEXPR14
1187 typename etl::enable_if< value_is_in_one_element<Position, Length, Bits_Per_Element>::value, typename etl::make_unsigned<T>::type>::type
1188 extract_from_buffer(const_pointer pbuffer)
1189 {
1190 typedef typename etl::make_unsigned<T>::type unsigned_t;
1191
1192 const size_t Element_Index = (Position + Length - 1) >> etl::log2<Bits_Per_Element>::value;
1193 const unsigned_t Mask = etl::lsb_mask<unsigned_t, Length>::value;
1194 const unsigned_t Shift = Position % Bits_Per_Element;
1195
1196 return static_cast<unsigned_t>(pbuffer[Element_Index] >> Shift) & Mask;
1197 }
1198
1199 //*************************************************************************
1202 //*************************************************************************
1203 template <typename T, size_t Position, size_t Length>
1204 static ETL_CONSTEXPR14
1205 typename etl::enable_if< !value_is_in_one_element<Position, Length, Bits_Per_Element>::value, typename etl::make_unsigned<T>::type>::type
1206 extract_from_buffer(const_pointer pbuffer)
1207 {
1208 // Start with index of the element containing the msb.
1209 const size_t Msb_Element_Index = (Position + Length - 1) >> etl::log2<Bits_Per_Element>::value;
1210
1211 // Get the number of active bits in the first element
1212 const size_t Active_Bits_In_Msb = ((Position + Length - 1) % Bits_Per_Element) + 1;
1213
1214 return extract_from_multiple_elements<T>(pbuffer, Msb_Element_Index, Active_Bits_In_Msb, Length);
1215 }
1216
1217 //*************************************************************************
1219 //*************************************************************************
1220 template <typename T>
1221 static ETL_CONSTEXPR14 T extract(const_pointer pbuffer, size_t position, size_t length = etl::integral_limits<T>::bits)
1222 {
1223 typedef typename etl::make_unsigned<T>::type unsigned_t;
1224
1225 unsigned_t value = extract_from_buffer<unsigned_t>(pbuffer, position, length);
1226
1228 {
1229 value = static_cast<unsigned_t>(etl::sign_extend<T>(static_cast<T>(value), length));
1230 }
1231
1232 return static_cast<T>(value);
1233 }
1234
1235 //*************************************************************************
1237 //*************************************************************************
1238 template <typename T, size_t Position, size_t Length>
1239 static ETL_CONSTEXPR14 T extract(const_pointer pbuffer)
1240 {
1241 typedef typename etl::make_unsigned<T>::type unsigned_t;
1242
1244
1246 {
1247 value = static_cast<unsigned_t>(etl::sign_extend<T>(static_cast<T>(value), Length));
1248 }
1249
1250 return static_cast<T>(value);
1251 }
1252
1253 //*************************************************************************
1255 //*************************************************************************
1256 static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1257 {
1258 operator_not(pbuffer, number_of_elements);
1259 }
1260
1261 //*************************************************************************
1263 //*************************************************************************
1264 static ETL_CONSTEXPR14 void flip_position(pointer pbuffer, size_t position) ETL_NOEXCEPT
1265 {
1266 const size_t index = position >> etl::log2<Bits_Per_Element>::value;
1267 const element_type bit = element_type(1) << (position & (Bits_Per_Element - 1));
1268
1269 pbuffer[index] ^= bit;
1270 }
1271
1272 //*************************************************************************
1277 //*************************************************************************
1278 static ETL_CONSTEXPR14 size_t find_next(const_pointer pbuffer, size_t number_of_elements, size_t total_bits, bool state, size_t position)
1279 ETL_NOEXCEPT
1280 {
1281 // Where to start.
1282 size_t index = position >> log2<Bits_Per_Element>::value;
1283 size_t bit = position & (Bits_Per_Element - 1);
1284
1285 element_type mask = 1 << bit;
1286
1287 // For each element in the bitset...
1288 while (index < number_of_elements)
1289 {
1290 element_type value = pbuffer[index];
1291
1292 // Needs checking?
1293 if ((state && (value != All_Clear_Element)) || (!state && (value != All_Set_Element)))
1294 {
1295 // For each bit in the element...
1296 while ((bit < Bits_Per_Element) && (position < total_bits))
1297 {
1298 // Equal to the required state?
1299 if (((value & mask) != 0) == state)
1300 {
1301 return position;
1302 }
1303
1304 // Move on to the next bit.
1305 mask <<= 1;
1306 ++position;
1307 ++bit;
1308 }
1309 }
1310 else
1311 {
1312 position += (Bits_Per_Element - bit);
1313 }
1314
1315 // Start at the beginning for all other elements.
1316 bit = 0;
1317 mask = 1;
1318
1319 ++index;
1320 }
1321
1322 return npos;
1323 }
1324
1325 //*************************************************************************
1327 //*************************************************************************
1328 template <typename TString>
1329 static ETL_CONSTEXPR14 TString to_string(const_pointer pbuffer, size_t active_bits, typename TString::value_type zero, typename TString::value_type one)
1330 {
1331 TString result;
1332
1333 result.resize(active_bits, '\0');
1334
1335 // Check that the string type can contain the digits.
1336 ETL_ASSERT_OR_RETURN_VALUE(result.size() == active_bits, ETL_ERROR(etl::bitset_string_too_small), result);
1337
1338 for (size_t i = active_bits; i > 0; --i)
1339 {
1340 result[active_bits - i] = test(pbuffer, i - 1) ? one : zero;
1341 }
1342
1343 return result;
1344 }
1345
1346 //*************************************************************************
1348 //*************************************************************************
1349 static ETL_CONSTEXPR14 void operator_assignment(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1350 {
1351 while (number_of_elements-- != 0)
1352 {
1353 *lhs_pbuffer = *rhs_pbuffer;
1354 ++lhs_pbuffer;
1355 ++rhs_pbuffer;
1356 }
1357 }
1358
1359 //*************************************************************************
1361 //*************************************************************************
1362 static ETL_CONSTEXPR14 void operator_and(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1363 {
1364 while (number_of_elements-- != 0)
1365 {
1366 *lhs_pbuffer &= *rhs_pbuffer;
1367 ++lhs_pbuffer;
1368 ++rhs_pbuffer;
1369 }
1370 }
1371
1372 //*************************************************************************
1374 //*************************************************************************
1375 static ETL_CONSTEXPR14 void operator_or(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1376 {
1377 while (number_of_elements-- != 0)
1378 {
1379 *lhs_pbuffer |= *rhs_pbuffer;
1380 ++lhs_pbuffer;
1381 ++rhs_pbuffer;
1382 }
1383 }
1384
1385 //*************************************************************************
1387 //*************************************************************************
1388 static ETL_CONSTEXPR14 void operator_xor(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1389 {
1390 while (number_of_elements-- != 0)
1391 {
1392 *lhs_pbuffer ^= *rhs_pbuffer;
1393 ++lhs_pbuffer;
1394 ++rhs_pbuffer;
1395 }
1396 }
1397
1398 //*************************************************************************
1400 //*************************************************************************
1401 static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1402 {
1403 while (number_of_elements-- != 0)
1404 {
1405 *pbuffer = ~*pbuffer;
1406 ++pbuffer;
1407 }
1408 }
1409
1410 //*************************************************************************
1412 //*************************************************************************
1413 static ETL_CONSTEXPR14 void operator_shift_left(pointer pbuffer, size_t number_of_elements, size_t active_bits, size_t shift) ETL_NOEXCEPT
1414 {
1415 if (shift >= active_bits)
1416 {
1417 reset_all(pbuffer, number_of_elements);
1418 }
1419 else
1420 {
1421 // The place where the elements are split when shifting.
1422 const size_t split_position = Bits_Per_Element - (shift % Bits_Per_Element);
1423
1424 // Where we are shifting from.
1425 int src_index = int(number_of_elements - (shift / Bits_Per_Element) - 1U);
1426
1427 // Where we are shifting to.
1428 int dst_index = int(number_of_elements - 1U);
1429
1430 // Shift control constants.
1431 const size_t lsb_shift = Bits_Per_Element - split_position;
1432 const size_t msb_shift = split_position;
1433
1434 const element_type lsb_mask = element_type(etl::integral_limits<element_type>::max >> (Bits_Per_Element - split_position));
1436 const element_type lsb_shifted_mask = element_type(lsb_mask << lsb_shift);
1437
1438 // First lsb.
1439 element_type lsb = element_type((pbuffer[src_index] & lsb_mask) << lsb_shift);
1440 pbuffer[dst_index] = lsb;
1441 --src_index;
1442
1443 // Now do the shifting.
1444 while (src_index >= 0)
1445 {
1446 // Shift msb.
1447 element_type msb = element_type((pbuffer[src_index] & msb_mask) >> msb_shift);
1448 pbuffer[dst_index] = pbuffer[dst_index] | msb;
1449 --dst_index;
1450
1451 // Shift lsb.
1452 lsb = element_type((pbuffer[src_index] & lsb_mask) << lsb_shift);
1453 pbuffer[dst_index] = lsb;
1454 --src_index;
1455 }
1456
1457 // Clear the remaining bits.
1458 // First lsb.
1459 pbuffer[dst_index] &= lsb_shifted_mask;
1460
1461 // The other remaining bytes on the right.
1462 for (int i = 0; i < dst_index; ++i)
1463 {
1464 pbuffer[i] = 0;
1465 }
1466 }
1467 }
1468
1469 //*************************************************************************
1471 //*************************************************************************
1472 static ETL_CONSTEXPR14 void operator_shift_right(pointer pbuffer, size_t number_of_elements, size_t active_bits, size_t shift) ETL_NOEXCEPT
1473 {
1474 if (shift >= active_bits)
1475 {
1476 reset_all(pbuffer, number_of_elements);
1477 }
1478 else
1479 {
1480 // The place where the elements are split when shifting.
1481 const size_t split_position = shift % Bits_Per_Element;
1482
1483 // Where we are shifting from.
1484 int src_index = int(shift / Bits_Per_Element);
1485
1486 // Where we are shifting to.
1487 int dst_index = 0;
1488
1489 // Shift control constants.
1490 const size_t lsb_shift = Bits_Per_Element - split_position;
1491 const size_t msb_shift = split_position;
1492
1493 const element_type lsb_mask = element_type(etl::integral_limits<element_type>::max >> (Bits_Per_Element - split_position));
1495 const element_type msb_shifted_mask = element_type(msb_mask >> msb_shift);
1496
1497 // Now do the shifting.
1498 while (src_index < int(number_of_elements - 1))
1499 {
1500 // Shift msb.
1501 element_type msb = element_type((pbuffer[src_index] & msb_mask) >> msb_shift);
1502 ++src_index;
1503
1504 // Shift lsb.
1505 element_type lsb = element_type((pbuffer[src_index] & lsb_mask) << lsb_shift);
1506
1507 // Combine them.
1508 pbuffer[dst_index] = lsb | msb;
1509 ++dst_index;
1510 }
1511
1512 // Final msb.
1513 element_type msb = element_type((pbuffer[src_index] & msb_mask) >> msb_shift);
1514 pbuffer[dst_index] = msb;
1515
1516 // Clear the remaining bits.
1517 // First msb.
1518 pbuffer[dst_index] &= msb_shifted_mask;
1519 ++dst_index;
1520
1521 // The other remaining bytes.
1522 while (dst_index < int(number_of_elements))
1523 {
1524 pbuffer[dst_index] = 0;
1525 ++dst_index;
1526 }
1527 }
1528 }
1529
1530 //*************************************************************************
1532 //*************************************************************************
1533 static ETL_CONSTEXPR14 bool operator_equality(const_pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1534 {
1535 return etl::equal(lhs_pbuffer, lhs_pbuffer + number_of_elements, rhs_pbuffer);
1536 }
1537
1538 //*************************************************************************
1542 //*************************************************************************
1543 template <typename TElementType>
1544 static
1545 ETL_CONSTEXPR14 typename etl::enable_if< etl::integral_limits<TElementType>::bits == etl::integral_limits<unsigned long long>::bits, void>::type
1546 initialise(pointer pbuffer, size_t number_of_elements, unsigned long long value) ETL_NOEXCEPT
1547 {
1548 size_t i = 0UL;
1549
1550 // Set the non-zero elements.
1551 pbuffer[i++] = value;
1552
1553 // Clear the remaining elements.
1554 while (i != number_of_elements)
1555 {
1556 pbuffer[i++] = All_Clear_Element;
1557 }
1558 }
1559
1560 //*************************************************************************
1564 //*************************************************************************
1565 template <typename TElementType>
1566 static
1567 ETL_CONSTEXPR14 typename etl::enable_if< etl::integral_limits<TElementType>::bits != etl::integral_limits<unsigned long long>::bits, void>::type
1568 initialise(pointer pbuffer, size_t number_of_elements, unsigned long long value) ETL_NOEXCEPT
1569 {
1570 size_t i = 0UL;
1571
1572 // Set the non-zero elements.
1573 const unsigned long long Shift = etl::integral_limits<element_type>::bits;
1574
1575 while ((value != 0) && (i != number_of_elements))
1576 {
1577 pbuffer[i++] = value & All_Set_Element;
1578 value = value >> Shift;
1579 }
1580
1581 // Clear the remaining elements.
1582 while (i != number_of_elements)
1583 {
1584 pbuffer[i++] = All_Clear_Element;
1585 }
1586 }
1587
1588 //*************************************************************************
1590 //*************************************************************************
1591 static ETL_CONSTEXPR14 void swap(pointer pbuffer1, pointer pbuffer2, size_t number_of_elements)
1592 {
1593 etl::swap_ranges(pbuffer1, pbuffer1 + number_of_elements, pbuffer2);
1594 }
1595 };
1596
1597 namespace private_bitset
1598 {
1599 //***************************************************************************
1600 template <size_t Active_Bits, typename TElement>
1602 {
1603 public:
1604
1605 typedef typename etl::private_bitset::bitset_impl_common<TElement>::element_type element_type;
1606
1607 using etl::private_bitset::bitset_impl_common<TElement>::Bits_Per_Element;
1608 using etl::private_bitset::bitset_impl_common<TElement>::All_Set_Element;
1609 using etl::private_bitset::bitset_impl_common< TElement>::All_Clear_Element;
1610
1611 static ETL_CONSTANT size_t Number_Of_Elements =
1612 (Active_Bits % Bits_Per_Element == 0) ? Active_Bits / Bits_Per_Element : Active_Bits / Bits_Per_Element + 1;
1613 static ETL_CONSTANT size_t Size = Active_Bits;
1614 static ETL_CONSTANT size_t Allocated_Bits = Number_Of_Elements * Bits_Per_Element;
1615
1616#if ETL_USING_CPP11
1617 static ETL_CONSTANT etl::bitset_storage_model Storage_Model =
1618 (bitset_common<Active_Bits, TElement>::Number_Of_Elements == 1U) ? etl::bitset_storage_model::Single : etl::bitset_storage_model::Multi;
1619#else
1620 static ETL_CONSTANT etl::bitset_storage_model Storage_Model;
1621#endif
1622
1625
1626 private:
1627
1628 static ETL_CONSTANT size_t Top_Mask_Shift = ((Bits_Per_Element - ((Number_Of_Elements * Bits_Per_Element) - Active_Bits)) % Bits_Per_Element);
1629
1630 public:
1631
1632 static ETL_CONSTANT TElement Top_Mask = element_type(Top_Mask_Shift == 0 ? All_Set_Element : ~(All_Set_Element << Top_Mask_Shift));
1633 };
1634
1635 template <size_t Active_Bits, typename TElement>
1636 ETL_CONSTANT size_t bitset_common<Active_Bits, TElement>::Number_Of_Elements;
1637
1638 template <size_t Active_Bits, typename TElement>
1639 ETL_CONSTANT size_t bitset_common<Active_Bits, TElement>::Size;
1640
1641#if ETL_USING_CPP11
1642 template <size_t Active_Bits, typename TElement>
1643 ETL_CONSTANT etl::bitset_storage_model bitset_common<Active_Bits, TElement>::Storage_Model;
1644#else
1645 template <size_t Active_Bits, typename TElement>
1646 ETL_CONSTANT etl::bitset_storage_model bitset_common<Active_Bits, TElement>::Storage_Model =
1647 (bitset_common<Active_Bits, TElement>::Number_Of_Elements == 1U) ? etl::bitset_storage_model::Single : etl::bitset_storage_model::Multi;
1648#endif
1649
1650 template <size_t Active_Bits, typename TElement>
1651 ETL_CONSTANT size_t bitset_common<Active_Bits, TElement>::Top_Mask_Shift;
1652
1653 template <size_t Active_Bits, typename TElement>
1654 ETL_CONSTANT TElement bitset_common<Active_Bits, TElement>::Top_Mask;
1655 } // namespace private_bitset
1656
1657 //***************************************************************************
1659 //***************************************************************************
1660 template <size_t Active_Bits = 0U, typename TElement = unsigned char>
1661 class bitset;
1662
1663 //***************************************************************************
1665 //***************************************************************************
1666 template <>
1667 class bitset<0U, unsigned char> : public etl::private_bitset::bitset_common<0U, unsigned char>
1668 {
1669 public:
1670
1671 typedef etl::private_bitset::bitset_common<0U, unsigned char>::element_type element_type;
1672 typedef etl::private_bitset::bitset_common<0U, unsigned char>::span_type span_type;
1673 typedef etl::private_bitset::bitset_common< 0U, unsigned char>::const_span_type const_span_type;
1674
1675 using etl::private_bitset::bitset_common<0U, unsigned char>::Bits_Per_Element;
1676 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Set_Element;
1677 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Clear_Element;
1678 using etl::private_bitset::bitset_common<0U, unsigned char>::Number_Of_Elements;
1679 using etl::private_bitset::bitset_common<0U, unsigned char>::Size;
1680 using etl::private_bitset::bitset_common<0U, unsigned char>::Storage_Model;
1681 using etl::private_bitset::bitset_common<0U, unsigned char>::Top_Mask;
1682 using etl::private_bitset::bitset_common<0U, unsigned char>::Allocated_Bits;
1683 };
1684
1685 //*************************************************************************
1687 //*************************************************************************
1688 template <size_t Active_Bits, typename TElement>
1689 class bitset : public etl::private_bitset::bitset_common<Active_Bits, TElement>
1690 {
1691 public:
1692
1693 ETL_STATIC_ASSERT(etl::is_unsigned<TElement>::value, "The element type must be unsigned");
1694
1695 typedef typename etl::private_bitset::bitset_common< Active_Bits, TElement>::element_type element_type;
1696 typedef typename etl::private_bitset::bitset_common< Active_Bits, TElement>::span_type span_type;
1697 typedef typename etl::private_bitset::bitset_common< Active_Bits, TElement>::const_span_type const_span_type;
1698
1699 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Bits_Per_Element;
1700 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Set_Element;
1701 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Clear_Element;
1702 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Number_Of_Elements;
1703 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Size;
1704 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Storage_Model;
1705 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Top_Mask;
1706 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Allocated_Bits;
1707
1708 //*************************************************************************
1710 //*************************************************************************
1712 {
1713 public:
1714
1715 friend class bitset;
1716
1717 //*******************************
1719 //*******************************
1720 ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT
1721 : p_bitset(other.p_bitset)
1722 , position(other.position)
1723 {
1724 }
1725
1726 //*******************************
1728 //*******************************
1729 ETL_CONSTEXPR14 operator bool() const ETL_NOEXCEPT
1730 {
1731 return p_bitset->test(position);
1732 }
1733
1734 //*******************************
1736 //*******************************
1737 ETL_CONSTEXPR14 bit_reference& operator=(bool b) ETL_NOEXCEPT
1738 {
1739 p_bitset->set(position, b);
1740 return *this;
1741 }
1742
1743 //*******************************
1745 //*******************************
1746 ETL_CONSTEXPR14 bit_reference& operator=(const bit_reference& r) ETL_NOEXCEPT
1747 {
1748 p_bitset->set(position, bool(r));
1749 return *this;
1750 }
1751
1752 //*******************************
1754 //*******************************
1755 ETL_CONSTEXPR14 bit_reference& flip() ETL_NOEXCEPT
1756 {
1757 p_bitset->flip(position);
1758 return *this;
1759 }
1760
1761 //*******************************
1763 //*******************************
1764 ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
1765 {
1766 return !p_bitset->test(position);
1767 }
1768
1769 private:
1770
1771 //*******************************
1773 //*******************************
1774 ETL_CONSTEXPR14 bit_reference() ETL_NOEXCEPT
1775 : p_bitset(ETL_NULLPTR)
1776 , position(0)
1777 {
1778 }
1779
1780 //*******************************
1782 //*******************************
1783 ETL_CONSTEXPR14 bit_reference(bitset<Active_Bits, TElement>& r_bitset, size_t position_) ETL_NOEXCEPT
1784 : p_bitset(&r_bitset)
1785 , position(position_)
1786 {
1787 }
1788
1789 bitset<Active_Bits, TElement>* p_bitset;
1790 size_t position;
1791 };
1792
1793 //*************************************************************************
1795 //*************************************************************************
1796 ETL_CONSTEXPR14 bitset() ETL_NOEXCEPT
1797 : buffer()
1798 {
1799 implementation::reset_all(buffer, Number_Of_Elements);
1800 }
1801
1802 //*************************************************************************
1804 //*************************************************************************
1805 ETL_CONSTEXPR14 bitset(const bitset<Active_Bits, TElement>& other) ETL_NOEXCEPT
1806 : buffer()
1807 {
1808 implementation::operator_assignment(buffer, other.buffer, Number_Of_Elements);
1809 }
1810
1811 //*************************************************************************
1813 //*************************************************************************
1814 template <typename TValue>
1815 ETL_CONSTEXPR14 bitset(TValue value, typename etl::enable_if<is_integral<TValue>::value>::type* = 0) ETL_NOEXCEPT
1816 : buffer()
1817 {
1818 implementation::template initialise<element_type>(buffer, Number_Of_Elements, static_cast<unsigned long long>(value));
1819 }
1820
1821 //*************************************************************************
1823 //*************************************************************************
1824 template <typename TPString>
1825 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if<is_same<TPString, const char*>::value>::type* = 0) ETL_NOEXCEPT
1826 : buffer()
1827 {
1828 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1829 }
1830
1831 //*************************************************************************
1833 //*************************************************************************
1834 template <typename TPString>
1835 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if<is_same<TPString, const wchar_t*>::value>::type* = 0) ETL_NOEXCEPT
1836 : buffer()
1837 {
1838 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1839 }
1840
1841 //*************************************************************************
1843 //*************************************************************************
1844 template <typename TPString>
1845 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if< is_same<TPString, const char16_t*>::value>::type* = 0) ETL_NOEXCEPT
1846 : buffer()
1847 {
1848 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1849 }
1850
1851 //*************************************************************************
1853 //*************************************************************************
1854 template <typename TPString>
1855 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if< is_same<TPString, const char32_t*>::value>::type* = 0) ETL_NOEXCEPT
1856 : buffer()
1857 {
1858 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1859 }
1860
1861 //*************************************************************************
1863 //*************************************************************************
1864 ETL_CONSTEXPR14 bitset& operator=(const bitset<Active_Bits, TElement>& other) ETL_NOEXCEPT
1865 {
1866 implementation::operator_assignment(buffer, other.buffer, Number_Of_Elements);
1867
1868 return *this;
1869 }
1870
1871 //*************************************************************************
1873 //*************************************************************************
1874 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& set() ETL_NOEXCEPT
1875 {
1876 implementation::set_all(buffer, Number_Of_Elements, Top_Mask);
1877
1878 return *this;
1879 }
1880
1881 //*************************************************************************
1883 //*************************************************************************
1884 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& set(size_t position, bool value = true)
1885 {
1886 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
1887
1888 implementation::set_position(buffer, position, value);
1889
1890 return *this;
1891 }
1892
1893 //*************************************************************************
1895 //*************************************************************************
1896 template <size_t Position>
1897 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& set(bool value = true)
1898 {
1899 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
1900
1901 implementation::template set_position<Position>(buffer, value);
1902
1903 return *this;
1904 }
1905
1906 //*************************************************************************
1908 //*************************************************************************
1909 template <size_t Position, bool Value>
1911 {
1912 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
1913
1914 implementation::template set_position<Position, Value>(buffer);
1915
1916 return *this;
1917 }
1918
1919 //*************************************************************************
1921 //*************************************************************************
1922 template <typename TPString>
1923 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const char*>::value, bitset<Active_Bits, TElement>&>::type set(TPString text)
1924 ETL_NOEXCEPT
1925 {
1926 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1927
1928 return *this;
1929 }
1930
1931 //*************************************************************************
1933 //*************************************************************************
1934 template <typename TPString>
1935 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const wchar_t*>::value, bitset<Active_Bits, TElement>&>::type set(TPString text)
1936 ETL_NOEXCEPT
1937 {
1938 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1939
1940 return *this;
1941 }
1942
1943 //*************************************************************************
1945 //*************************************************************************
1946 template <typename TPString>
1947 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const char16_t*>::value, bitset<Active_Bits, TElement>&>::type set(TPString text)
1948 ETL_NOEXCEPT
1949 {
1950 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1951
1952 return *this;
1953 }
1954
1955 //*************************************************************************
1957 //*************************************************************************
1958 template <typename TPString>
1959 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const char32_t*>::value, bitset<Active_Bits, TElement>&>::type set(TPString text)
1960 ETL_NOEXCEPT
1961 {
1962 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1963
1964 return *this;
1965 }
1966
1967 //*************************************************************************
1969 //*************************************************************************
1970 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const char* text) ETL_NOEXCEPT
1971 {
1972 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1973
1974 return *this;
1975 }
1976
1977 //*************************************************************************
1979 //*************************************************************************
1980 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const wchar_t* text) ETL_NOEXCEPT
1981 {
1982 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1983
1984 return *this;
1985 }
1986
1987 //*************************************************************************
1989 //*************************************************************************
1990 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const char16_t* text) ETL_NOEXCEPT
1991 {
1992 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1993
1994 return *this;
1995 }
1996
1997 //*************************************************************************
1999 //*************************************************************************
2000 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const char32_t* text) ETL_NOEXCEPT
2001 {
2002 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
2003
2004 return *this;
2005 }
2006
2007 //*************************************************************************
2009 //*************************************************************************
2010 template <typename T>
2011 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_integral<T>::value, T>::type value() const ETL_NOEXCEPT
2012 {
2013 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
2014 ETL_STATIC_ASSERT(etl::integral_limits<T>::bits >= (Number_Of_Elements * Bits_Per_Element), "Type too small");
2015
2016 return implementation::template value<T>(buffer, Number_Of_Elements);
2017 }
2018
2019 //*************************************************************************
2022 //*************************************************************************
2023 template <typename T>
2024 ETL_CONSTEXPR14 T extract(size_t position, size_t length = etl::integral_limits<T>::bits) const
2025 {
2026 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
2027
2028 ETL_ASSERT_OR_RETURN_VALUE(length <= etl::integral_limits<T>::bits, ETL_ERROR(bitset_overflow), 0);
2029 ETL_ASSERT_OR_RETURN_VALUE((position + length) <= Active_Bits, ETL_ERROR(bitset_overflow), 0);
2030
2031 return implementation::template extract<T>(buffer, position, length);
2032 }
2033
2034 //*************************************************************************
2037 //*************************************************************************
2038#if ETL_USING_CPP11
2039 template <typename T, size_t Position, size_t Length = etl::integral_limits<T>::bits>
2040#else
2041 template <typename T, size_t Position, size_t Length>
2042#endif
2043 ETL_CONSTEXPR14 T extract() const
2044 {
2045 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
2046 ETL_STATIC_ASSERT(Length <= etl::integral_limits<T>::bits, "Length is larger that the required type");
2047 ETL_STATIC_ASSERT((Position + Length) <= Active_Bits, "Position/Length overflows bitset");
2048
2049 return implementation::template extract<T, Position, Length>(buffer);
2050 }
2051
2052 //*************************************************************************
2054 //*************************************************************************
2055 unsigned long to_ulong() const
2056 {
2058
2059 return implementation::template value<unsigned long>(buffer, Number_Of_Elements);
2060 }
2061
2062 //*************************************************************************
2064 //*************************************************************************
2065 unsigned long long to_ullong() const
2066 {
2068
2069 return implementation::template value<unsigned long long>(buffer, Number_Of_Elements);
2070 }
2071
2072 //*************************************************************************
2074 //*************************************************************************
2075 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& reset() ETL_NOEXCEPT
2076 {
2077 implementation::reset_all(buffer, Number_Of_Elements);
2078
2079 return *this;
2080 }
2081
2082 //*************************************************************************
2084 //*************************************************************************
2085 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& reset(size_t position)
2086 {
2087 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
2088
2089 implementation::reset_position(buffer, position);
2090
2091 return *this;
2092 }
2093
2094 //*************************************************************************
2098 //*************************************************************************
2099 ETL_CONSTEXPR14 bool test(size_t position) const
2100 {
2101 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), false);
2102
2103 return implementation::test(buffer, position);
2104 }
2105
2106 //*************************************************************************
2109 //*************************************************************************
2110 template <size_t Position>
2111 ETL_CONSTEXPR14 bool test() const
2112 {
2113 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
2114
2115 return implementation::test(buffer, Position);
2116 }
2117
2118 //*************************************************************************
2120 //*************************************************************************
2121 static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
2122 {
2123 return Active_Bits;
2124 }
2125
2126 //*************************************************************************
2128 //*************************************************************************
2129 static ETL_CONSTEXPR size_t number_of_elements() ETL_NOEXCEPT
2130 {
2131 return Number_Of_Elements;
2132 }
2133
2134 //*************************************************************************
2136 //*************************************************************************
2137 static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
2138 {
2139 return All_Set_Element;
2140 }
2141
2142 //*************************************************************************
2144 //*************************************************************************
2145 static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
2146 {
2147 return All_Clear_Element;
2148 }
2149
2150 //*************************************************************************
2152 //*************************************************************************
2153 static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
2154 {
2155 return Bits_Per_Element;
2156 }
2157
2158 //*************************************************************************
2160 //*************************************************************************
2161 static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
2162 {
2163 return Top_Mask;
2164 }
2165
2166 //*************************************************************************
2168 //*************************************************************************
2169 static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
2170 {
2171 return Number_Of_Elements * Bits_Per_Element;
2172 }
2173
2174 //*************************************************************************
2178 //*************************************************************************
2179 static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
2180 {
2181 return Storage_Model;
2182 }
2183
2184 //*************************************************************************
2186 //*************************************************************************
2187 ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
2188 {
2189 return implementation::count(buffer, Number_Of_Elements);
2190 }
2191
2192 //*************************************************************************
2193 // Are all the bits sets?
2194 //*************************************************************************
2195 ETL_CONSTEXPR14 bool all() const ETL_NOEXCEPT
2196 {
2197 return implementation::all(buffer, Number_Of_Elements, Top_Mask);
2198 }
2199
2200 //*************************************************************************
2201 // Are all the mask bits sets?
2202 //*************************************************************************
2203 ETL_CONSTEXPR14 bool all(element_type mask) const ETL_NOEXCEPT
2204 {
2205 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
2206
2207 return implementation::all(buffer, Number_Of_Elements, Top_Mask, mask);
2208 }
2209
2210 //*************************************************************************
2212 //*************************************************************************
2213 ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
2214 {
2215 return implementation::none(buffer, Number_Of_Elements);
2216 }
2217
2218 //*************************************************************************
2220 //*************************************************************************
2221 ETL_CONSTEXPR14 bool none(element_type mask) const ETL_NOEXCEPT
2222 {
2223 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
2224
2225 return implementation::none(buffer, Number_Of_Elements, mask);
2226 }
2227
2228 //*************************************************************************
2230 //*************************************************************************
2231 ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
2232 {
2233 return implementation::any(buffer, Number_Of_Elements);
2234 }
2235
2236 //*************************************************************************
2238 //*************************************************************************
2239 ETL_CONSTEXPR14 bool any(element_type mask) const ETL_NOEXCEPT
2240 {
2241 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
2242
2243 return implementation::any(buffer, Number_Of_Elements, mask);
2244 }
2245
2246 //*************************************************************************
2248 //*************************************************************************
2249 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& flip() ETL_NOEXCEPT
2250 {
2251 implementation::flip_all(buffer, Number_Of_Elements);
2252
2253 return *this;
2254 }
2255
2256 //*************************************************************************
2258 //*************************************************************************
2259 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& flip(size_t position)
2260 {
2261 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
2262
2263 implementation::flip_position(buffer, position);
2264
2265 return *this;
2266 }
2267
2268 //*************************************************************************
2270 //*************************************************************************
2271 ETL_CONSTEXPR14 bool operator[](size_t position) const ETL_NOEXCEPT
2272 {
2273 return implementation::test(buffer, position);
2274 }
2275
2276 //*************************************************************************
2278 //*************************************************************************
2279 ETL_CONSTEXPR14 bit_reference operator[](size_t position) ETL_NOEXCEPT
2280 {
2281 return bit_reference(*this, position);
2282 }
2283
2284 //*************************************************************************
2286 //*************************************************************************
2287#if ETL_USING_CPP11
2288 template <typename TString = etl::string<Active_Bits>>
2289#else
2290 template <typename TString>
2291#endif
2292 ETL_CONSTEXPR14 TString to_string(typename TString::value_type zero = typename TString::value_type('0'),
2293 typename TString::value_type one = typename TString::value_type('1')) const
2294 {
2295 return implementation::template to_string<TString>(buffer, Active_Bits, zero, one);
2296 }
2297
2298 //*************************************************************************
2302 //*************************************************************************
2303 ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
2304 {
2305 return implementation::find_next(buffer, Number_Of_Elements, Active_Bits, state, 0);
2306 }
2307
2308 //*************************************************************************
2313 //*************************************************************************
2314 ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
2315 {
2316 return implementation::find_next(buffer, Number_Of_Elements, Active_Bits, state, position);
2317 }
2318
2319 //*************************************************************************
2321 //*************************************************************************
2322 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator&(const bitset<Active_Bits, TElement>& other) const ETL_NOEXCEPT
2323 {
2325
2326 implementation::operator_and(temp.buffer, other.buffer, Number_Of_Elements);
2327
2328 return temp;
2329 }
2330
2331 //*************************************************************************
2333 //*************************************************************************
2335 {
2336 implementation::operator_and(buffer, other.buffer, Number_Of_Elements);
2337
2338 return *this;
2339 }
2340
2341 //*************************************************************************
2343 //*************************************************************************
2344 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator|(const bitset<Active_Bits, TElement>& other) const ETL_NOEXCEPT
2345 {
2347
2348 implementation::operator_or(temp.buffer, other.buffer, Number_Of_Elements);
2349
2350 return temp;
2351 }
2352
2353 //*************************************************************************
2355 //*************************************************************************
2357 {
2358 implementation::operator_or(&buffer[0], &other.buffer[0], Number_Of_Elements);
2359
2360 return *this;
2361 }
2362
2363 //*************************************************************************
2365 //*************************************************************************
2366 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator^(const bitset<Active_Bits, TElement>& other) const ETL_NOEXCEPT
2367 {
2369
2370 implementation::operator_xor(temp.buffer, other.buffer, Number_Of_Elements);
2371
2372 return temp;
2373 }
2374
2375 //*************************************************************************
2377 //*************************************************************************
2379 {
2380 implementation::operator_xor(buffer, other.buffer, Number_Of_Elements);
2381
2382 return *this;
2383 }
2384
2385 //*************************************************************************
2387 //*************************************************************************
2388 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator~() const ETL_NOEXCEPT
2389 {
2391
2392 implementation::flip_all(temp.buffer, Number_Of_Elements);
2393
2394 return temp;
2395 }
2396
2397 //*************************************************************************
2399 //*************************************************************************
2400 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator<<(size_t shift) const ETL_NOEXCEPT
2401 {
2403
2404 implementation::operator_shift_left(temp.buffer, Number_Of_Elements, Active_Bits, shift);
2405
2406 return temp;
2407 }
2408
2409 //*************************************************************************
2411 //*************************************************************************
2412 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& operator<<=(size_t shift) ETL_NOEXCEPT
2413 {
2414 if (shift >= Active_Bits)
2415 {
2416 implementation::reset_all(buffer, Number_Of_Elements);
2417 }
2418 else
2419 {
2420 implementation::operator_shift_left(buffer, Number_Of_Elements, Active_Bits, shift);
2421 }
2422
2423 return *this;
2424 }
2425
2426 //*************************************************************************
2428 //*************************************************************************
2429 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator>>(size_t shift) const ETL_NOEXCEPT
2430 {
2432
2433 implementation::operator_shift_right(temp.buffer, Number_Of_Elements, Active_Bits, shift);
2434
2435 return temp;
2436 }
2437
2438 //*************************************************************************
2440 //*************************************************************************
2441 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& operator>>=(size_t shift) ETL_NOEXCEPT
2442 {
2443 if (shift >= Active_Bits)
2444 {
2445 implementation::reset_all(buffer, Number_Of_Elements);
2446 }
2447 else
2448 {
2449 implementation::operator_shift_right(buffer, Number_Of_Elements, Active_Bits, shift);
2450 }
2451
2452 return *this;
2453 }
2454
2455 //*************************************************************************
2457 //*************************************************************************
2458 friend ETL_CONSTEXPR14 bool operator==(const bitset<Active_Bits, TElement>& lhs, const bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2459 {
2460 return implementation::operator_equality(lhs.buffer, rhs.buffer, lhs.Number_Of_Elements);
2461 }
2462
2463 //*************************************************************************
2465 //*************************************************************************
2466 friend ETL_CONSTEXPR14 bool operator!=(const bitset<Active_Bits, TElement>& lhs, const bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2467 {
2468 return !(lhs == rhs);
2469 }
2470
2471 //*************************************************************************
2473 //*************************************************************************
2474 ETL_CONSTEXPR14 void swap(etl::bitset<Active_Bits, TElement>& other) ETL_NOEXCEPT
2475 {
2476 implementation::swap(buffer, other.buffer, Number_Of_Elements);
2477 }
2478
2479 //*************************************************************************
2482 //*************************************************************************
2483 ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
2484 {
2485 return span_type(buffer, Number_Of_Elements);
2486 }
2487
2488 //*************************************************************************
2491 //*************************************************************************
2492 ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
2493 {
2494 return const_span_type(buffer, Number_Of_Elements);
2495 }
2496
2497 private:
2498
2499 // The implementation of the bitset functionality.
2500 typedef etl::bitset_impl<element_type, (Number_Of_Elements == 1U) ? etl::bitset_storage_model::Single : etl::bitset_storage_model::Multi>
2501 implementation;
2502
2503 // The storage for the bitset.
2504 element_type buffer[Number_Of_Elements];
2505 };
2506
2507 //***************************************************************************
2510 //***************************************************************************
2511 template <size_t Active_Bits, typename TElement>
2513 {
2514 bitset<Active_Bits> temp(lhs);
2515 temp &= rhs;
2516 return temp;
2517 }
2518
2519 //***************************************************************************
2522 //***************************************************************************
2523 template <size_t Active_Bits, typename TElement>
2525 {
2526 bitset<Active_Bits> temp(lhs);
2527 temp |= rhs;
2528 return temp;
2529 }
2530
2531 //***************************************************************************
2534 //***************************************************************************
2535 template <size_t Active_Bits, typename TElement>
2537 {
2538 bitset<Active_Bits> temp(lhs);
2539 temp ^= rhs;
2540 return temp;
2541 }
2542
2543 //***************************************************************************
2546 //***************************************************************************
2547 template <size_t Active_Bits, typename TElement>
2548 ETL_CONSTEXPR14 bool operator!=(const etl::bitset<Active_Bits, TElement>& lhs, const etl::bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2549 {
2550 return !(lhs == rhs);
2551 }
2552
2553 //*************************************************************************
2555 //*************************************************************************
2556 template <size_t Active_Bits, typename TElement>
2558 {
2559 lhs.swap(rhs);
2560 }
2561
2562 //***************************************************************************
2564 //***************************************************************************
2565
2566 //***************************************************************************
2567 template <size_t Active_Bits = 0U, typename TElement = unsigned char>
2568 class bitset_ext;
2569
2570 //***************************************************************************
2572 //***************************************************************************
2573 template <>
2574 class bitset_ext<0U, unsigned char> : public etl::private_bitset::bitset_common<0U, unsigned char>
2575 {
2576 public:
2577
2578 typedef size_t size_type;
2579
2580 typedef etl::private_bitset::bitset_common<0U, unsigned char>::element_type element_type;
2581 typedef etl::private_bitset::bitset_common<0U, unsigned char>::span_type span_type;
2582 typedef etl::private_bitset::bitset_common< 0U, unsigned char>::const_span_type const_span_type;
2583
2584 using etl::private_bitset::bitset_common<0U, unsigned char>::Bits_Per_Element;
2585 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Set_Element;
2586 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Clear_Element;
2587 using etl::private_bitset::bitset_common<0U, unsigned char>::Number_Of_Elements;
2588 using etl::private_bitset::bitset_common<0U, unsigned char>::Size;
2589 using etl::private_bitset::bitset_common<0U, unsigned char>::Storage_Model;
2590 using etl::private_bitset::bitset_common<0U, unsigned char>::Top_Mask;
2591 using etl::private_bitset::bitset_common<0U, unsigned char>::Allocated_Bits;
2592 };
2593
2594 //*************************************************************************
2596 //*************************************************************************
2597 template <size_t Active_Bits, typename TElement>
2598 class bitset_ext : public etl::private_bitset::bitset_common<Active_Bits, TElement>
2599 {
2600 public:
2601
2602 ETL_STATIC_ASSERT(etl::is_unsigned<TElement>::value, "The element type must be unsigned");
2603
2604 typedef size_t size_type;
2605
2606 typedef typename etl::private_bitset::bitset_common< Active_Bits, TElement>::element_type element_type;
2607 typedef typename etl::private_bitset::bitset_common< Active_Bits, TElement>::span_type span_type;
2608 typedef typename etl::private_bitset::bitset_common< Active_Bits, TElement>::const_span_type const_span_type;
2609
2610 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Bits_Per_Element;
2611 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Set_Element;
2612 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Clear_Element;
2613 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Number_Of_Elements;
2614 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Size;
2615 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Storage_Model;
2616 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Top_Mask;
2617 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Allocated_Bits;
2618
2619 typedef etl::array<TElement, Number_Of_Elements> buffer_type;
2620
2621 //*************************************************************************
2623 //*************************************************************************
2625 {
2626 public:
2627
2628 friend class bitset_ext;
2629
2630 //*******************************
2632 //*******************************
2633 ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT
2634 : p_bitset(other.p_bitset)
2635 , position(other.position)
2636 {
2637 }
2638
2639 //*******************************
2641 //*******************************
2642 ETL_CONSTEXPR14 operator bool() const ETL_NOEXCEPT
2643 {
2644 return p_bitset->test(position);
2645 }
2646
2647 //*******************************
2649 //*******************************
2650 ETL_CONSTEXPR14 bit_reference& operator=(bool b) ETL_NOEXCEPT
2651 {
2652 p_bitset->set(position, b);
2653 return *this;
2654 }
2655
2656 //*******************************
2658 //*******************************
2659 ETL_CONSTEXPR14 bit_reference& operator=(const bit_reference& r) ETL_NOEXCEPT
2660 {
2661 p_bitset->set(position, bool(r));
2662 return *this;
2663 }
2664
2665 //*******************************
2667 //*******************************
2668 ETL_CONSTEXPR14 bit_reference& flip() ETL_NOEXCEPT
2669 {
2670 p_bitset->flip(position);
2671 return *this;
2672 }
2673
2674 //*******************************
2676 //*******************************
2677 ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
2678 {
2679 return !p_bitset->test(position);
2680 }
2681
2682 private:
2683
2684 //*******************************
2686 //*******************************
2687 ETL_CONSTEXPR14 bit_reference() ETL_NOEXCEPT
2688 : p_bitset(ETL_NULLPTR)
2689 , position(0)
2690 {
2691 }
2692
2693 //*******************************
2695 //*******************************
2696 ETL_CONSTEXPR14 bit_reference(bitset_ext<Active_Bits, TElement>& r_bitset, size_t position_) ETL_NOEXCEPT
2697 : p_bitset(&r_bitset)
2698 , position(position_)
2699 {
2700 }
2701
2702 bitset_ext<Active_Bits, TElement>* p_bitset;
2703 size_t position;
2704 };
2705
2706 //*************************************************************************
2708 //*************************************************************************
2709 ETL_CONSTEXPR14 explicit bitset_ext(element_type* pbuffer_)
2710 : pbuffer(pbuffer_)
2711 {
2712 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2713 implementation::reset_all(pbuffer, Number_Of_Elements);
2714 }
2715
2716 //*************************************************************************
2718 //*************************************************************************
2719 ETL_CONSTEXPR14 explicit bitset_ext(buffer_type& buffer)
2720 : pbuffer(buffer.data())
2721 {
2722 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2723 implementation::reset_all(pbuffer, Number_Of_Elements);
2724 }
2725
2726 //*************************************************************************
2728 //*************************************************************************
2729 ETL_CONSTEXPR14 bitset_ext(const bitset_ext<Active_Bits, TElement>& other, element_type* pbuffer_)
2730 : pbuffer(pbuffer_)
2731 {
2732 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2733 implementation::operator_assignment(pbuffer, other.pbuffer, Number_Of_Elements);
2734 }
2735
2736 //*************************************************************************
2738 //*************************************************************************
2739 ETL_CONSTEXPR14 bitset_ext(const bitset_ext<Active_Bits, TElement>& other, buffer_type& buffer) ETL_NOEXCEPT
2740 : pbuffer(buffer.data())
2741 {
2742 implementation::operator_assignment(pbuffer, other.pbuffer, Number_Of_Elements);
2743 }
2744
2745 //*************************************************************************
2747 //*************************************************************************
2748 ETL_CONSTEXPR14 bitset_ext(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT ETL_DELETE;
2749
2750 //*************************************************************************
2752 //*************************************************************************
2753 ETL_CONSTEXPR14 bitset_ext(unsigned long long value, element_type* pbuffer_)
2754 : pbuffer(pbuffer_)
2755 {
2756 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2757 implementation::template initialise<element_type>(pbuffer, Number_Of_Elements, value);
2758 }
2759
2760 //*************************************************************************
2762 //*************************************************************************
2763 template <typename TValue>
2764 ETL_CONSTEXPR14 bitset_ext(TValue value, buffer_type& buffer, typename etl::enable_if<is_integral<TValue>::value>::type* = 0) ETL_NOEXCEPT
2765 : pbuffer(buffer.data())
2766 {
2767 implementation::template initialise<element_type>(pbuffer, Number_Of_Elements, static_cast<unsigned long long>(value));
2768 }
2769
2770 //*************************************************************************
2772 //*************************************************************************
2773 template <typename TPString>
2774 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if<is_same<TPString, const char*>::value>::type* = 0)
2775 : pbuffer(pbuffer_)
2776 {
2777 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2778 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2779 }
2780
2781 //*************************************************************************
2783 //*************************************************************************
2784 template <typename TPString>
2785 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if<is_same<TPString, const char*>::value>::type* = 0)
2786 ETL_NOEXCEPT
2787 : pbuffer(buffer.data())
2788 {
2789 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2790 }
2791
2792 //*************************************************************************
2794 //*************************************************************************
2795 template <typename TPString>
2796 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if<is_same<TPString, const wchar_t*>::value>::type* = 0)
2797 : pbuffer(pbuffer_)
2798 {
2799 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2800 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2801 }
2802
2803 //*************************************************************************
2805 //*************************************************************************
2806 template <typename TPString>
2807 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if<is_same<TPString, const wchar_t*>::value>::type* = 0)
2808 ETL_NOEXCEPT
2809 : pbuffer(buffer.data())
2810 {
2811 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2812 }
2813
2814 //*************************************************************************
2816 //*************************************************************************
2817 template <typename TPString>
2818 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if< is_same<TPString, const char16_t*>::value>::type* = 0)
2819 : pbuffer(pbuffer_)
2820 {
2821 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2822 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2823 }
2824
2825 //*************************************************************************
2827 //*************************************************************************
2828 template <typename TPString>
2829 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if< is_same<TPString, const char16_t*>::value>::type* = 0)
2830 ETL_NOEXCEPT
2831 : pbuffer(buffer.data())
2832 {
2833 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2834 }
2835
2836 //*************************************************************************
2838 //*************************************************************************
2839 template <typename TPString>
2840 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if< is_same<TPString, const char32_t*>::value>::type* = 0)
2841 : pbuffer(pbuffer_)
2842 {
2843 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2844 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2845 }
2846
2847 //*************************************************************************
2849 //*************************************************************************
2850 template <typename TPString>
2851 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if< is_same<TPString, const char32_t*>::value>::type* = 0)
2852 ETL_NOEXCEPT
2853 : pbuffer(buffer.data())
2854 {
2855 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2856 }
2857
2858 //*************************************************************************
2860 //*************************************************************************
2861 ETL_CONSTEXPR14 bitset_ext& operator=(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
2862 {
2863 implementation::operator_assignment(pbuffer, other.pbuffer, Number_Of_Elements);
2864
2865 return *this;
2866 }
2867
2868 //*************************************************************************
2870 //*************************************************************************
2871 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& set() ETL_NOEXCEPT
2872 {
2873 implementation::set_all(pbuffer, Number_Of_Elements, Top_Mask);
2874
2875 return *this;
2876 }
2877
2878 //*************************************************************************
2880 //*************************************************************************
2881 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& set(size_t position, bool value = true)
2882 {
2883 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
2884
2885 implementation::set_position(pbuffer, position, value);
2886
2887 return *this;
2888 }
2889
2890 //*************************************************************************
2892 //*************************************************************************
2893 template <size_t Position>
2894 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& set(bool value = true)
2895 {
2896 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
2897
2898 implementation::template set_position<Position>(pbuffer, value);
2899
2900 return *this;
2901 }
2902
2903 //*************************************************************************
2905 //*************************************************************************
2906 template <size_t Position, bool Value>
2908 {
2909 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
2910
2911 implementation::template set_position<Position, Value>(pbuffer);
2912
2913 return *this;
2914 }
2915
2916 //*************************************************************************
2918 //*************************************************************************
2919 template <typename TPString>
2920 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const char*>::value, bitset_ext<Active_Bits, TElement>&>::type set(TPString text)
2921 ETL_NOEXCEPT
2922 {
2923 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2924
2925 return *this;
2926 }
2927
2928 //*************************************************************************
2930 //*************************************************************************
2931 template <typename TPString>
2932 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const wchar_t*>::value, bitset_ext<Active_Bits, TElement>&>::type
2933 set(TPString text) ETL_NOEXCEPT
2934 {
2935 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2936
2937 return *this;
2938 }
2939
2940 //*************************************************************************
2942 //*************************************************************************
2943 template <typename TPString>
2944 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const char16_t*>::value, bitset_ext<Active_Bits, TElement>&>::type
2945 set(TPString text) ETL_NOEXCEPT
2946 {
2947 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2948
2949 return *this;
2950 }
2951
2952 //*************************************************************************
2954 //*************************************************************************
2955 template <typename TPString>
2956 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const char32_t*>::value, bitset_ext<Active_Bits, TElement>&>::type
2957 set(TPString text) ETL_NOEXCEPT
2958 {
2959 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2960
2961 return *this;
2962 }
2963
2964 //*************************************************************************
2966 //*************************************************************************
2967 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const char* text) ETL_NOEXCEPT
2968 {
2969 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2970
2971 return *this;
2972 }
2973
2974 //*************************************************************************
2976 //*************************************************************************
2977 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const wchar_t* text) ETL_NOEXCEPT
2978 {
2979 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2980
2981 return *this;
2982 }
2983
2984 //*************************************************************************
2986 //*************************************************************************
2987 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const char16_t* text) ETL_NOEXCEPT
2988 {
2989 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2990
2991 return *this;
2992 }
2993
2994 //*************************************************************************
2996 //*************************************************************************
2997 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const char32_t* text) ETL_NOEXCEPT
2998 {
2999 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
3000
3001 return *this;
3002 }
3003
3004 //*************************************************************************
3006 //*************************************************************************
3007 template <typename T>
3008 ETL_CONSTEXPR14 T value() const ETL_NOEXCEPT
3009 {
3010 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
3011 ETL_STATIC_ASSERT(etl::integral_limits<T>::bits >= (Number_Of_Elements * Bits_Per_Element), "Type too small");
3012
3013 return implementation::template value<T>(pbuffer, Number_Of_Elements);
3014 }
3015
3016 //*************************************************************************
3019 //*************************************************************************
3020 template <typename T>
3021 ETL_CONSTEXPR14 T extract(size_t position, size_t length = etl::integral_limits<T>::bits)
3022 {
3023 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
3024
3025 ETL_ASSERT_OR_RETURN_VALUE(length <= etl::integral_limits<T>::bits, ETL_ERROR(bitset_overflow), 0);
3026 ETL_ASSERT_OR_RETURN_VALUE((position + length) <= Active_Bits, ETL_ERROR(bitset_overflow), 0);
3027
3028 return implementation::template extract<T>(pbuffer, position, length);
3029 }
3030
3031 //*************************************************************************
3034 //*************************************************************************
3035#if ETL_USING_CPP11
3036 template <typename T, size_t Position, size_t Length = etl::integral_limits<T>::bits>
3037#else
3038 template <typename T, size_t Position, size_t Length>
3039#endif
3040 ETL_CONSTEXPR14 T extract() const
3041 {
3042 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
3043 ETL_STATIC_ASSERT(Length <= etl::integral_limits<T>::bits, "Length is larger that the required type");
3044 ETL_STATIC_ASSERT((Position + Length) <= Active_Bits, "Position/Length overflows bitset");
3045
3046 return implementation::template extract<T, Position, Length>(pbuffer);
3047 }
3048
3049 //*************************************************************************
3051 //*************************************************************************
3052 unsigned long to_ulong() const
3053 {
3055
3056 return implementation::template value<unsigned long>(pbuffer, Number_Of_Elements);
3057 }
3058
3059 //*************************************************************************
3061 //*************************************************************************
3062 unsigned long long to_ullong() const
3063 {
3065
3066 return implementation::template value<unsigned long long>(pbuffer, Number_Of_Elements);
3067 }
3068
3069 //*************************************************************************
3071 //*************************************************************************
3072 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& reset() ETL_NOEXCEPT
3073 {
3074 implementation::reset_all(pbuffer, Number_Of_Elements);
3075
3076 return *this;
3077 }
3078
3079 //*************************************************************************
3081 //*************************************************************************
3082 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& reset(size_t position)
3083 {
3084 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
3085
3086 implementation::reset_position(pbuffer, position);
3087
3088 return *this;
3089 }
3090
3091 //*************************************************************************
3095 //*************************************************************************
3096 ETL_CONSTEXPR14 bool test(size_t position) const
3097 {
3098 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), false);
3099
3100 return implementation::test(pbuffer, position);
3101 }
3102
3103 //*************************************************************************
3106 //*************************************************************************
3107 template <size_t Position>
3108 ETL_CONSTEXPR14 bool test() const
3109 {
3110 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
3111
3112 return implementation::test(pbuffer, Position);
3113 }
3114
3115 //*************************************************************************
3117 //*************************************************************************
3118 static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
3119 {
3120 return Active_Bits;
3121 }
3122
3123 //*************************************************************************
3125 //*************************************************************************
3126 static ETL_CONSTEXPR size_t number_of_elements() ETL_NOEXCEPT
3127 {
3128 return Number_Of_Elements;
3129 }
3130
3131 //*************************************************************************
3133 //*************************************************************************
3134 static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
3135 {
3136 return All_Set_Element;
3137 }
3138
3139 //*************************************************************************
3141 //*************************************************************************
3142 static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
3143 {
3144 return All_Clear_Element;
3145 }
3146
3147 //*************************************************************************
3149 //*************************************************************************
3150 static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
3151 {
3152 return Top_Mask;
3153 }
3154
3155 //*************************************************************************
3157 //*************************************************************************
3158 static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
3159 {
3160 return Bits_Per_Element;
3161 }
3162
3163 //*************************************************************************
3165 //*************************************************************************
3166 static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
3167 {
3168 return Number_Of_Elements * Bits_Per_Element;
3169 }
3170
3171 //*************************************************************************
3175 //*************************************************************************
3176 static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
3177 {
3178 return Storage_Model;
3179 }
3180
3181 //*************************************************************************
3183 //*************************************************************************
3184 ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
3185 {
3186 return implementation::count(pbuffer, Number_Of_Elements);
3187 }
3188
3189 //*************************************************************************
3190 // Are all the bits sets?
3191 //*************************************************************************
3192 ETL_CONSTEXPR14 bool all() const ETL_NOEXCEPT
3193 {
3194 return implementation::all(pbuffer, Number_Of_Elements, Top_Mask);
3195 }
3196
3197 //*************************************************************************
3198 // Are all the mask bits sets?
3199 //*************************************************************************
3200 ETL_CONSTEXPR14 bool all(element_type mask) const ETL_NOEXCEPT
3201 {
3202 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
3203
3204 return implementation::all(pbuffer, Number_Of_Elements, Top_Mask, mask);
3205 }
3206
3207 //*************************************************************************
3209 //*************************************************************************
3210 ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
3211 {
3212 return implementation::none(pbuffer, Number_Of_Elements);
3213 }
3214
3215 //*************************************************************************
3217 //*************************************************************************
3218 ETL_CONSTEXPR14 bool none(element_type mask) const ETL_NOEXCEPT
3219 {
3220 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
3221
3222 return implementation::none(pbuffer, Number_Of_Elements, mask);
3223 }
3224
3225 //*************************************************************************
3227 //*************************************************************************
3228 ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
3229 {
3230 return implementation::any(pbuffer, Number_Of_Elements);
3231 }
3232
3233 //*************************************************************************
3235 //*************************************************************************
3236 ETL_CONSTEXPR14 bool any(element_type mask) const ETL_NOEXCEPT
3237 {
3238 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
3239
3240 return implementation::any(pbuffer, Number_Of_Elements, mask);
3241 }
3242
3243 //*************************************************************************
3245 //*************************************************************************
3246 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& flip() ETL_NOEXCEPT
3247 {
3248 implementation::flip_all(pbuffer, Number_Of_Elements);
3249
3250 return *this;
3251 }
3252
3253 //*************************************************************************
3255 //*************************************************************************
3256 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& flip(size_t position)
3257 {
3258 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
3259
3260 implementation::flip_position(pbuffer, position);
3261
3262 return *this;
3263 }
3264
3265 //*************************************************************************
3267 //*************************************************************************
3268 ETL_CONSTEXPR14 bool operator[](size_t position) const ETL_NOEXCEPT
3269 {
3270 return implementation::test(pbuffer, position);
3271 }
3272
3273 //*************************************************************************
3275 //*************************************************************************
3276 ETL_CONSTEXPR14 bit_reference operator[](size_t position) ETL_NOEXCEPT
3277 {
3278 return bit_reference(*this, position);
3279 }
3280
3281 //*************************************************************************
3283 //*************************************************************************
3284#if ETL_USING_CPP11
3285 template <typename TString = etl::string<Active_Bits>>
3286#else
3287 template <typename TString>
3288#endif
3289 ETL_CONSTEXPR14 TString to_string(typename TString::value_type zero = typename TString::value_type('0'),
3290 typename TString::value_type one = typename TString::value_type('1')) const
3291 {
3292 return implementation::template to_string<TString>(pbuffer, Active_Bits, zero, one);
3293 }
3294
3295 //*************************************************************************
3299 //*************************************************************************
3300 ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
3301 {
3302 return implementation::find_next(pbuffer, Number_Of_Elements, Active_Bits, state, 0);
3303 }
3304
3305 //*************************************************************************
3310 //*************************************************************************
3311 ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
3312 {
3313 return implementation::find_next(pbuffer, Number_Of_Elements, Active_Bits, state, position);
3314 }
3315
3316 //*************************************************************************
3318 //*************************************************************************
3320 {
3321 implementation::operator_and(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3322
3323 return *this;
3324 }
3325
3326 //*************************************************************************
3328 //*************************************************************************
3330 {
3331 implementation::operator_or(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3332
3333 return *this;
3334 }
3335
3336 //*************************************************************************
3338 //*************************************************************************
3340 {
3341 implementation::operator_xor(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3342
3343 return *this;
3344 }
3345
3346 //*************************************************************************
3348 //*************************************************************************
3349 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator<<=(size_t shift) ETL_NOEXCEPT
3350 {
3351 implementation::operator_shift_left(pbuffer, Number_Of_Elements, Active_Bits, shift);
3352
3353 return *this;
3354 }
3355
3356 //*************************************************************************
3358 //*************************************************************************
3359 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator>>=(size_t shift) ETL_NOEXCEPT
3360 {
3361 implementation::operator_shift_right(pbuffer, Number_Of_Elements, Active_Bits, shift);
3362
3363 return *this;
3364 }
3365
3366 //*************************************************************************
3368 //*************************************************************************
3369 friend ETL_CONSTEXPR14 bool operator==(const bitset_ext<Active_Bits, TElement>& lhs, const bitset_ext<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3370 {
3371 return implementation::operator_equality(lhs.pbuffer, rhs.pbuffer, lhs.Number_Of_Elements);
3372 }
3373
3374 //*************************************************************************
3376 //*************************************************************************
3377 friend ETL_CONSTEXPR14 bool operator!=(const bitset_ext<Active_Bits, TElement>& lhs, const bitset_ext<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3378 {
3379 return !(lhs == rhs);
3380 }
3381
3382 //*************************************************************************
3384 //*************************************************************************
3385 ETL_CONSTEXPR14 void swap(etl::bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
3386 {
3387 implementation::swap(pbuffer, other.pbuffer, Number_Of_Elements);
3388 }
3389
3390 //*************************************************************************
3393 //*************************************************************************
3394 ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
3395 {
3396 return span_type(pbuffer, Number_Of_Elements);
3397 }
3398
3399 //*************************************************************************
3402 //*************************************************************************
3403 ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
3404 {
3405 return const_span_type(pbuffer, Number_Of_Elements);
3406 }
3407
3408 private:
3409
3410 // The implementation of the bitset functionality.
3411 typedef etl::bitset_impl<element_type, (Number_Of_Elements == 1U) ? etl::bitset_storage_model::Single : etl::bitset_storage_model::Multi>
3412 implementation;
3413
3414 // Pointer to the storage for the bitset.
3415 element_type* pbuffer;
3416 };
3417
3418 //***************************************************************************
3421 //***************************************************************************
3422 template <size_t Active_Bits, typename TElement>
3423 ETL_CONSTEXPR14 bool operator!=(const etl::bitset_ext<Active_Bits, TElement>& lhs, const etl::bitset_ext<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3424 {
3425 return !(lhs == rhs);
3426 }
3427
3428 //*************************************************************************
3430 //*************************************************************************
3431 template <size_t Active_Bits, typename TElement>
3433 {
3434 lhs.swap(rhs);
3435 }
3436
3437 namespace private_bitset
3438 {
3439 //*************************************************************************
3442 //*************************************************************************
3443 template <typename TLhsSpan, typename TRhsSpan>
3444 bool compare_bitset_spans(const TLhsSpan& lhs_span, const TRhsSpan& rhs_span)
3445 {
3446 typedef typename TLhsSpan::value_type lhs_element_t;
3447 typedef typename TRhsSpan::value_type rhs_element_t;
3448
3449 const int steps = static_cast<int>(sizeof(lhs_element_t) / sizeof(rhs_element_t));
3450
3451 typename TLhsSpan::iterator lhs_itr = lhs_span.begin();
3452 typename TRhsSpan::iterator rhs_itr = rhs_span.begin();
3453
3454 while (lhs_itr != lhs_span.end())
3455 {
3456 const lhs_element_t& lhs_value = *lhs_itr;
3457
3458 // Build the rhs element in terms of the lhs element type.
3459 lhs_element_t rhs_value = 0;
3460
3461 const int shift_step = etl::integral_limits<rhs_element_t>::bits;
3462 int shift = 0;
3463
3464 for (int i = 0; i < steps; ++i)
3465 {
3466 rhs_value |= (static_cast<lhs_element_t>(*rhs_itr) << shift);
3467 ++rhs_itr;
3468 shift += shift_step;
3469 }
3470
3471 if (lhs_value != rhs_value)
3472 {
3473 return false;
3474 }
3475
3476 ++lhs_itr;
3477 }
3478
3479 return true;
3480 }
3481 } // namespace private_bitset
3482
3483 //***************************************************************************
3488 //***************************************************************************
3489 template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3490 ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3492 {
3493 // Get a span of each type.
3494 typename etl::bitset<Active_Bits, TLhsElement>::const_span_type lhs_span = lhs.span();
3495 typename etl::bitset<Active_Bits, TRhsElement>::const_span_type rhs_span = rhs.span();
3496
3497 // Put the bitset with the largest element type as the first argument.
3498 if ETL_IF_CONSTEXPR (sizeof(TLhsElement) > sizeof(TRhsElement))
3499 {
3500 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3501 }
3502 else
3503 {
3504 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3505 }
3506 }
3507
3508 //***************************************************************************
3513 //***************************************************************************
3514 template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3515 ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3517 {
3518 return !(lhs == rhs);
3519 }
3520
3521 //***************************************************************************
3526 //***************************************************************************
3527 template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3528 ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3530 {
3531 // Get a span of each type.
3532 typename etl::bitset_ext<Active_Bits, TLhsElement>::const_span_type lhs_span = lhs.span();
3533 typename etl::bitset_ext<Active_Bits, TRhsElement>::const_span_type rhs_span = rhs.span();
3534
3535 // Put the bitset with the largest element type as the first argument.
3536 if ETL_IF_CONSTEXPR (sizeof(TLhsElement) > sizeof(TRhsElement))
3537 {
3538 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3539 }
3540 else
3541 {
3542 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3543 }
3544 }
3545
3546 //***************************************************************************
3551 //***************************************************************************
3552 template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3553 ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3555 {
3556 return !(lhs == rhs);
3557 }
3558
3559 //***************************************************************************
3563 //***************************************************************************
3564 template <size_t Active_Bits, typename TElement>
3565 ETL_CONSTEXPR14 bool operator==(const etl::bitset<Active_Bits, TElement>& lhs, const etl::bitset_ext<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3566 {
3567 const char Storage_Model = etl::bitset<Active_Bits, TElement>::Storage_Model;
3568 const size_t Number_Of_Elements = etl::bitset<Active_Bits, TElement>::Number_Of_Elements;
3569
3570 typename etl::bitset<Active_Bits, TElement>::const_span_type lhs_span = lhs.span();
3571 typename etl::bitset_ext<Active_Bits, TElement>::const_span_type rhs_span = rhs.span();
3572
3573 typedef etl::bitset_impl<TElement, Storage_Model> implementation;
3574
3575 return implementation::operator_equality(lhs_span.begin(), rhs_span.begin(), Number_Of_Elements);
3576 }
3577
3578 //***************************************************************************
3582 //***************************************************************************
3583 template <size_t Active_Bits, typename TElement>
3584 ETL_CONSTEXPR14 bool operator!=(const etl::bitset<Active_Bits, TElement>& lhs, const etl::bitset_ext<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3585 {
3586 return !(lhs == rhs);
3587 }
3588
3589 //***************************************************************************
3593 //***************************************************************************
3594 template <size_t Active_Bits, typename TElement>
3595 ETL_CONSTEXPR14 bool operator==(const etl::bitset_ext<Active_Bits, TElement>& lhs, const etl::bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3596 {
3597 const char Storage_Model = etl::bitset<Active_Bits, TElement>::Storage_Model;
3598 const size_t Number_Of_Elements = etl::bitset<Active_Bits, TElement>::Number_Of_Elements;
3599
3600 typename etl::bitset_ext<Active_Bits, TElement>::const_span_type lhs_span = lhs.span();
3601 typename etl::bitset<Active_Bits, TElement>::const_span_type rhs_span = rhs.span();
3602
3603 typedef etl::bitset_impl<TElement, Storage_Model> implementation;
3604
3605 return implementation::operator_equality(lhs_span.begin(), rhs_span.begin(), Number_Of_Elements);
3606 }
3607
3608 //***************************************************************************
3612 //***************************************************************************
3613 template <size_t Active_Bits, typename TElement>
3614 ETL_CONSTEXPR14 bool operator!=(const etl::bitset_ext<Active_Bits, TElement>& lhs, const etl::bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3615 {
3616 return !(lhs == rhs);
3617 }
3618
3619 //***************************************************************************
3623 //***************************************************************************
3624 template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3625 ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3627 {
3628 // Get a span of each type.
3629 typename etl::bitset<Active_Bits, TLhsElement>::const_span_type lhs_span = lhs.span();
3630 typename etl::bitset_ext<Active_Bits, TRhsElement>::const_span_type rhs_span = rhs.span();
3631
3632 // Put the bitset with the largest element type as the first argument.
3633 if ETL_IF_CONSTEXPR (sizeof(TLhsElement) > sizeof(TRhsElement))
3634 {
3635 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3636 }
3637 else
3638 {
3639 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3640 }
3641 }
3642
3643 //***************************************************************************
3647 //***************************************************************************
3648 template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3649 ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3651 {
3652 return !(lhs == rhs);
3653 }
3654
3655 //***************************************************************************
3659 //***************************************************************************
3660 template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3661 ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3663 {
3664 // Get a span of each type.
3665 typename etl::bitset_ext<Active_Bits, TLhsElement>::const_span_type lhs_span = lhs.span();
3666 typename etl::bitset<Active_Bits, TRhsElement>::const_span_type rhs_span = rhs.span();
3667
3668 // Put the bitset with the largest element type as the first argument.
3669 if ETL_IF_CONSTEXPR (sizeof(TLhsElement) > sizeof(TRhsElement))
3670 {
3671 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3672 }
3673 else
3674 {
3675 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3676 }
3677 }
3678
3679 //***************************************************************************
3683 //***************************************************************************
3684 template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3685 ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3687 {
3688 return !(lhs == rhs);
3689 }
3690
3691} // namespace etl
3692
3693#include "minmax_pop.h"
3694
3695#endif
bool compare_bitset_spans(const TLhsSpan &lhs_span, const TRhsSpan &rhs_span)
Definition bitset_new.h:3444
The reference type returned.
Definition bitset_new.h:1712
ETL_CONSTEXPR14 bit_reference(const bit_reference &other) ETL_NOEXCEPT
Copy constructor.
Definition bitset_new.h:1720
ETL_CONSTEXPR14 bit_reference & operator=(const bit_reference &r) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:1746
ETL_CONSTEXPR14 bit_reference & operator=(bool b) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:1737
ETL_CONSTEXPR14 bit_reference & flip() ETL_NOEXCEPT
Flip the bit.
Definition bitset_new.h:1755
ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
Return the logical inverse of the bit.
Definition bitset_new.h:1764
The reference type returned.
Definition bitset_new.h:2625
ETL_CONSTEXPR14 bit_reference & operator=(bool b) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:2650
ETL_CONSTEXPR14 bit_reference & operator=(const bit_reference &r) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:2659
ETL_CONSTEXPR14 bit_reference & flip() ETL_NOEXCEPT
Flip the bit.
Definition bitset_new.h:2668
ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
Return the logical inverse of the bit.
Definition bitset_new.h:2677
ETL_CONSTEXPR14 bit_reference(const bit_reference &other) ETL_NOEXCEPT
Copy constructor.
Definition bitset_new.h:2633
bitset_ext
Definition bitset_new.h:2599
ETL_CONSTEXPR14 etl::enable_if< etl::is_same< TPString, constchar32_t * >::value, bitset_ext< Active_Bits, TElement > & >::type set(TPString text) ETL_NOEXCEPT
Set from a char32 string.
Definition bitset_new.h:2957
ETL_CONSTEXPR14 T extract() const
Definition bitset_new.h:3040
ETL_CONSTEXPR14 etl::enable_if< etl::is_same< TPString, constwchar_t * >::value, bitset_ext< Active_Bits, TElement > & >::type set(TPString text) ETL_NOEXCEPT
Set from a wide string.
Definition bitset_new.h:2933
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & from_string(const char32_t *text) ETL_NOEXCEPT
Set from a u32 string.
Definition bitset_new.h:2997
ETL_CONSTEXPR14 bitset_ext & operator=(const bitset_ext< Active_Bits, TElement > &other) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:2861
ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
Are any of the bits set?
Definition bitset_new.h:3228
ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type &buffer, typename etl::enable_if< is_same< TPString, const char16_t * >::value >::type *=0) ETL_NOEXCEPT
Construct from a string.
Definition bitset_new.h:2829
static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
The value of a set element.
Definition bitset_new.h:3134
ETL_CONSTEXPR14 void swap(etl::bitset_ext< Active_Bits, TElement > &other) ETL_NOEXCEPT
swap
Definition bitset_new.h:3385
friend ETL_CONSTEXPR14 bool operator==(const bitset_ext< Active_Bits, TElement > &lhs, const bitset_ext< Active_Bits, TElement > &rhs) ETL_NOEXCEPT
operator ==
Definition bitset_new.h:3369
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & flip(size_t position)
Flip the bit at the position.
Definition bitset_new.h:3256
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & from_string(const char *text) ETL_NOEXCEPT
Set from a string.
Definition bitset_new.h:2967
ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
Definition bitset_new.h:3311
static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
The mask for the msb element.
Definition bitset_new.h:3150
ETL_CONSTEXPR14 bitset_ext(TPString text, element_type *pbuffer_, typename etl::enable_if< is_same< TPString, const char * >::value >::type *=0)
Construct from a string.
Definition bitset_new.h:2774
ETL_CONSTEXPR14 bitset_ext(TValue value, buffer_type &buffer, typename etl::enable_if< is_integral< TValue >::value >::type *=0) ETL_NOEXCEPT
Construct from a value.
Definition bitset_new.h:2764
ETL_CONSTEXPR14 bitset_ext(TPString text, element_type *pbuffer_, typename etl::enable_if< is_same< TPString, const char16_t * >::value >::type *=0)
Construct from a string.
Definition bitset_new.h:2818
unsigned long long to_ullong() const
Get as an unsigned long long.
Definition bitset_new.h:3062
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & operator<<=(size_t shift) ETL_NOEXCEPT
operator <<=
Definition bitset_new.h:3349
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & operator|=(const bitset_ext< Active_Bits, TElement > &other) ETL_NOEXCEPT
operator |=
Definition bitset_new.h:3329
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & operator^=(const bitset_ext< Active_Bits, TElement > &other) ETL_NOEXCEPT
operator ^=
Definition bitset_new.h:3339
ETL_CONSTEXPR14 bool any(element_type mask) const ETL_NOEXCEPT
Are any of the mask bits set?
Definition bitset_new.h:3236
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & reset() ETL_NOEXCEPT
Reset all of the bits.
Definition bitset_new.h:3072
ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
Are none of the bits set?
Definition bitset_new.h:3210
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & set() ETL_NOEXCEPT
Set all of the bits.
Definition bitset_new.h:2871
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & reset(size_t position)
Reset the bit at the position.
Definition bitset_new.h:3082
ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type &buffer, typename etl::enable_if< is_same< TPString, const wchar_t * >::value >::type *=0) ETL_NOEXCEPT
Construct from a string.
Definition bitset_new.h:2807
ETL_CONSTEXPR14 bitset_ext(element_type *pbuffer_)
Definition bitset_new.h:2709
ETL_CONSTEXPR14 T value() const ETL_NOEXCEPT
Get as an integral value.
Definition bitset_new.h:3008
ETL_CONSTEXPR14 bitset_ext(unsigned long long value, element_type *pbuffer_)
Construct from a value.
Definition bitset_new.h:2753
static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
The number of bits in an element.
Definition bitset_new.h:3158
ETL_CONSTEXPR14 bitset_ext(TPString text, element_type *pbuffer_, typename etl::enable_if< is_same< TPString, const char32_t * >::value >::type *=0)
Construct from a string.
Definition bitset_new.h:2840
ETL_CONSTEXPR14 etl::enable_if< etl::is_same< TPString, constchar * >::value, bitset_ext< Active_Bits, TElement > & >::type set(TPString text) ETL_NOEXCEPT
Set from a string.
Definition bitset_new.h:2920
ETL_CONSTEXPR14 bool operator[](size_t position) const ETL_NOEXCEPT
Read [] operator.
Definition bitset_new.h:3268
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & operator&=(const bitset_ext< Active_Bits, TElement > &other) ETL_NOEXCEPT
operator &=
Definition bitset_new.h:3319
static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
The number of bits in the bitset.
Definition bitset_new.h:3118
static ETL_CONSTEXPR size_t number_of_elements() ETL_NOEXCEPT
The number of storage elements in the bitset.
Definition bitset_new.h:3126
ETL_CONSTEXPR14 bool test(size_t position) const
Definition bitset_new.h:3096
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & flip() ETL_NOEXCEPT
Flip all of the bits.
Definition bitset_new.h:3246
static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
The total number of bits of storage, including unused.
Definition bitset_new.h:3166
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & set(size_t position, bool value=true)
Set the bit at the position.
Definition bitset_new.h:2881
ETL_CONSTEXPR14 bitset_ext(TPString text, element_type *pbuffer_, typename etl::enable_if< is_same< TPString, const wchar_t * >::value >::type *=0)
Construct from a string.
Definition bitset_new.h:2796
unsigned long to_ulong() const
Get as an unsigned long.
Definition bitset_new.h:3052
ETL_CONSTEXPR14 bool test() const
Definition bitset_new.h:3108
ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type &buffer, typename etl::enable_if< is_same< TPString, const char32_t * >::value >::type *=0) ETL_NOEXCEPT
Construct from a string.
Definition bitset_new.h:2851
ETL_CONSTEXPR14 etl::enable_if< etl::is_same< TPString, constchar16_t * >::value, bitset_ext< Active_Bits, TElement > & >::type set(TPString text) ETL_NOEXCEPT
Set from a char16 string.
Definition bitset_new.h:2945
ETL_CONSTEXPR14 bit_reference operator[](size_t position) ETL_NOEXCEPT
Write [] operator.
Definition bitset_new.h:3276
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & from_string(const wchar_t *text) ETL_NOEXCEPT
Set from a wide string.
Definition bitset_new.h:2977
ETL_CONSTEXPR14 bool none(element_type mask) const ETL_NOEXCEPT
Are none of the mask bits set?
Definition bitset_new.h:3218
ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
Count the number of bits set.
Definition bitset_new.h:3184
ETL_CONSTEXPR14 bitset_ext(const bitset_ext< Active_Bits, TElement > &other, buffer_type &buffer) ETL_NOEXCEPT
Construct copy.
Definition bitset_new.h:2739
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & set()
Set the bit at the position.
Definition bitset_new.h:2907
ETL_CONSTEXPR14 bitset_ext(const bitset_ext< Active_Bits, TElement > &other, element_type *pbuffer_)
Construct copy.
Definition bitset_new.h:2729
static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
Definition bitset_new.h:3176
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & operator>>=(size_t shift) ETL_NOEXCEPT
operator >>=
Definition bitset_new.h:3359
friend ETL_CONSTEXPR14 bool operator!=(const bitset_ext< Active_Bits, TElement > &lhs, const bitset_ext< Active_Bits, TElement > &rhs) ETL_NOEXCEPT
operator !=
Definition bitset_new.h:3377
ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
Definition bitset_new.h:3300
static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
The value of a clear element.
Definition bitset_new.h:3142
ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
Definition bitset_new.h:3403
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & set(bool value=true)
Set the bit at the position.
Definition bitset_new.h:2894
ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type &buffer, typename etl::enable_if< is_same< TPString, const char * >::value >::type *=0) ETL_NOEXCEPT
Construct from a string.
Definition bitset_new.h:2785
ETL_CONSTEXPR14 TString to_string(typename TString::value_type zero=typename TString::value_type('0'), typename TString::value_type one=typename TString::value_type('1')) const
Returns a string representing the bitset.
Definition bitset_new.h:3289
ETL_CONSTEXPR14 bitset_ext(const bitset_ext< Active_Bits, TElement > &other) ETL_NOEXCEPT ETL_DELETE
Copy Constructor (Deleted).
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & from_string(const char16_t *text) ETL_NOEXCEPT
Set from a u16 string.
Definition bitset_new.h:2987
ETL_CONSTEXPR14 bitset_ext(buffer_type &buffer)
Default constructor.
Definition bitset_new.h:2719
ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
Definition bitset_new.h:3394
ETL_CONSTEXPR14 T extract(size_t position, size_t length=etl::integral_limits< T >::bits)
Definition bitset_new.h:3021
Definition binary.h:2196
Definition binary.h:2228
Definition bitset_new.h:1602
Definition bitset_new.h:166
Span - Fixed Extent.
Definition span.h:208
ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
Returns an iterator to the beginning of the span.
Definition span.h:484
Definition array.h:85
ETL_CONSTEXPR14 etl::enable_if< etl::is_integral< T >::value &&etl::is_unsigned< T >::value &&(etl::integral_limits< T >::bits==16U), uint_least8_t >::type count_bits(T value)
Definition binary.h:918
ETL_CONSTEXPR14 TReturn sign_extend(TValue value)
Definition binary.h:273
Definition binary.h:356
static ETL_CONSTEXPR14 bool operator_equality(const_pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator_equality
Definition bitset_new.h:1533
ETL_CONSTEXPR14 bool none(element_type mask) const ETL_NOEXCEPT
Are none of the mask bits set?
Definition bitset_new.h:2221
static ETL_CONSTEXPR14 T extract(const_pointer pbuffer)
Extract an integral value from an arbitrary position and length.
Definition bitset_new.h:1239
ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
Definition bitset_new.h:2314
static ETL_CONSTEXPR14 size_t find_next(const_pointer pbuffer, size_t number_of_elements, size_t total_bits, bool state, size_t position) ETL_NOEXCEPT
Definition bitset_new.h:1278
ETL_CONSTEXPR14 T extract(size_t position, size_t length=etl::integral_limits< T >::bits) const
Definition bitset_new.h:2024
static ETL_CONSTEXPR14 etl::make_unsigned< T >::type extract_from_multiple_elements(const element_type *pbuffer, size_t element_index, size_t active_bits_in_msb, size_t length) ETL_NOEXCEPT
Extract an value from multiple elements.
Definition bitset_new.h:1101
static ETL_CONSTEXPR14 void set_all(pointer pbuffer, size_t number_of_elements, element_type top_mask) ETL_NOEXCEPT
Set all bits.
Definition bitset_new.h:865
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set(size_t position, bool value=true)
Set the bit at the position.
Definition bitset_new.h:1884
static ETL_CONSTEXPR14 etl::enable_if< value_is_in_one_element< Position, Length, Bits_Per_Element >::value, typenameetl::make_unsigned< T >::type >::type extract_from_buffer(const_pointer pbuffer)
Definition bitset_new.h:1188
static ETL_CONSTEXPR14 etl::make_unsigned< T >::type extract_from_buffer(const_pointer pbuffer, size_t position, size_t length) ETL_NOEXCEPT
Definition bitset_new.h:1149
ETL_CONSTEXPR14 bitset(const bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
Copy constructor.
Definition bitset_new.h:1805
ibitset & initialise(unsigned long long value)
Initialise from an unsigned long long.
Definition bitset_legacy.h:1006
static ETL_CONSTEXPR14 void swap(pointer lhs_pbuffer, pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
swap
Definition bitset_new.h:735
ETL_CONSTEXPR14 etl::enable_if< etl::is_same< TPString, constchar16_t * >::value, bitset< Active_Bits, TElement > & >::type set(TPString text) ETL_NOEXCEPT
Set from a char16 string.
Definition bitset_new.h:1947
static ETL_CONSTEXPR14 void reset_position(pointer pbuffer, size_t position)
Reset the bit at the position.
Definition bitset_new.h:294
static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t) ETL_NOEXCEPT
Flip all of the bits.
Definition bitset_new.h:557
static ETL_CONSTEXPR14 etl::enable_if<!value_is_in_one_element< Position, Length, Bits_Per_Element >::value, typenameetl::make_unsigned< T >::type >::type extract_from_buffer(const_pointer pbuffer)
Definition bitset_new.h:1206
static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t, element_type mask) ETL_NOEXCEPT
Are any of the mask bits set?
Definition bitset_new.h:549
static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
The value of a set element.
Definition bitset_new.h:2137
static ETL_CONSTEXPR14 void set_position(pointer pbuffer, size_t position, bool value=true)
Set the bit at the position.
Definition bitset_new.h:230
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const char32_t *text) ETL_NOEXCEPT
Set from a u32 string.
Definition bitset_new.h:2000
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const char *text) ETL_NOEXCEPT
Set from a string.
Definition bitset_new.h:934
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & operator&=(const bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
operator &=
Definition bitset_new.h:2334
static ETL_CONSTEXPR14 T extract(const_pointer pbuffer)
Extract an integral value from an arbitrary position and length.
Definition bitset_new.h:470
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & operator>>=(size_t shift) ETL_NOEXCEPT
operator >>=
Definition bitset_new.h:2441
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const char16_t *text) ETL_NOEXCEPT
Set from a u16 string.
Definition bitset_new.h:1990
static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Flip all of the bits.
Definition bitset_new.h:1256
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set() ETL_NOEXCEPT
Set all of the bits.
Definition bitset_new.h:1874
static ETL_CONSTEXPR14 size_t find_next(const_pointer pbuffer, size_t, size_t active_bits, bool state, size_t position) ETL_NOEXCEPT
Definition bitset_new.h:608
static ETL_CONSTEXPR14 void initialise(pointer pbuffer, size_t, unsigned long long value) ETL_NOEXCEPT
Initialise from an unsigned long long.
Definition bitset_new.h:727
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator>>(size_t shift) const ETL_NOEXCEPT
operator >>
Definition bitset_new.h:2429
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator<<(size_t shift) const ETL_NOEXCEPT
operator <<
Definition bitset_new.h:2400
static ETL_CONSTEXPR14 TString to_string(const_pointer pbuffer, size_t active_bits, typename TString::value_type zero, typename TString::value_type one)
Returns a string representing the bitset.
Definition bitset_new.h:1329
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator~() const ETL_NOEXCEPT
operator ~
Definition bitset_new.h:2388
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & flip() ETL_NOEXCEPT
Flip all of the bits.
Definition bitset_new.h:2249
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const char *text) ETL_NOEXCEPT
Set from a string.
Definition bitset_new.h:1970
ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
Definition bitset_new.h:2492
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const wchar_t *text) ETL_NOEXCEPT
Set from a wide string.
Definition bitset_new.h:964
ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
Are none of the bits set?
Definition bitset_new.h:2213
ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if< is_same< TPString, const char16_t * >::value >::type *=0) ETL_NOEXCEPT
Construct from a string.
Definition bitset_new.h:1845
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & operator<<=(size_t shift) ETL_NOEXCEPT
operator <<=
Definition bitset_new.h:2412
static ETL_CONSTEXPR14 void flip_position(pointer pbuffer, size_t position)
Flip the bit at the position.
Definition bitset_new.h:573
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const char16_t *text) ETL_NOEXCEPT
Set from a u16 string.
Definition bitset_new.h:994
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator&(const bitset< Active_Bits, TElement > &other) const ETL_NOEXCEPT
operator &
Definition bitset_new.h:2322
ETL_CONSTEXPR14 bit_reference operator[](size_t position) ETL_NOEXCEPT
Write [] operator.
Definition bitset_new.h:2279
static ETL_CONSTEXPR14 void set_position(pointer pbuffer, bool value=true)
Set the bit at the position.
Definition bitset_new.h:897
static ETL_CONSTEXPR14 void operator_assignment(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator assignment
Definition bitset_new.h:1349
static ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t, element_type mask) ETL_NOEXCEPT
Are none of the mask bits set?
Definition bitset_new.h:533
ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
Definition bitset_new.h:2303
static ETL_CONSTEXPR14 void set_position(pointer pbuffer)
Set the bit at the position.
Definition bitset_new.h:916
ETL_CONSTEXPR14 bitset(TValue value, typename etl::enable_if< is_integral< TValue >::value >::type *=0) ETL_NOEXCEPT
Construct from a value.
Definition bitset_new.h:1815
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const wchar_t *text) ETL_NOEXCEPT
Set from a wide string.
Definition bitset_new.h:1980
static ETL_CONSTEXPR14 void operator_and(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator and
Definition bitset_new.h:1362
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & flip(size_t position)
Flip the bit at the position.
Definition bitset_new.h:2259
etl::enable_if< etl::is_integral< T >::value, T >::type value() const
Put to a value.
Definition bitset_legacy.h:1299
static ETL_CONSTEXPR size_t number_of_elements() ETL_NOEXCEPT
The number of storage elements in the bitset.
Definition bitset_new.h:2129
static ETL_CONSTEXPR14 size_t count(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Count the number of bits set.
Definition bitset_new.h:792
static ETL_CONSTEXPR14 void operator_or(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:662
ETL_CONSTEXPR14 void swap(etl::bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
swap
Definition bitset_new.h:2474
static ETL_CONSTEXPR14 T extract(const_pointer pbuffer, size_t position, size_t length=etl::integral_limits< T >::bits)
Extract an integral value from an arbitrary position and length.
Definition bitset_new.h:1221
ETL_CONSTEXPR14 TString to_string(typename TString::value_type zero=typename TString::value_type('0'), typename TString::value_type one=typename TString::value_type('1')) const
Returns a string representing the bitset.
Definition bitset_new.h:2292
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t, size_t active_bits, const wchar_t *text) ETL_NOEXCEPT
Set from a wide string.
Definition bitset_new.h:336
static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
The total number of bits of storage, including unused.
Definition bitset_new.h:2169
static ETL_CONSTEXPR14 void operator_shift_left(pointer pbuffer, size_t number_of_elements, size_t active_bits, size_t shift) ETL_NOEXCEPT
operator_shift_left
Definition bitset_new.h:1413
static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
The mask for the msb element.
Definition bitset_new.h:2161
static ETL_CONSTEXPR14 void operator_or(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator or
Definition bitset_new.h:1375
static ETL_CONSTEXPR14 void operator_shift_right(pointer pbuffer, size_t, size_t active_bits, size_t shift) ETL_NOEXCEPT
operator_shift_right
Definition bitset_new.h:703
ETL_CONSTEXPR14 bool test(size_t position) const
Definition bitset_new.h:2099
TString to_string(typename TString::value_type zero=typename TString::value_type('0'), typename TString::value_type one=typename TString::value_type('1')) const
Returns a string representing the bitset.
Definition bitset_legacy.h:1351
ETL_CONSTEXPR14 etl::enable_if< etl::is_integral< T >::value, T >::type value() const ETL_NOEXCEPT
Get as an integral value.
Definition bitset_new.h:2011
static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Are any of the bits set?
Definition bitset_new.h:541
ETL_CONSTEXPR14 bool any(element_type mask) const ETL_NOEXCEPT
Are any of the mask bits set?
Definition bitset_new.h:2239
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & operator^=(const bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
operator ^=
Definition bitset_new.h:2378
ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if< is_same< TPString, const char32_t * >::value >::type *=0) ETL_NOEXCEPT
Construct from a string.
Definition bitset_new.h:1855
static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
The value of a clear element.
Definition bitset_new.h:2145
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & reset() ETL_NOEXCEPT
Reset all of the bits.
Definition bitset_new.h:2075
static ETL_CONSTEXPR14 void reset_all(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Reset all of the bits.
Definition bitset_new.h:1054
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t, size_t active_bits, const char *text) ETL_NOEXCEPT
Set from a string.
Definition bitset_new.h:303
static ETL_CONSTEXPR14 void operator_shift_left(pointer pbuffer, size_t, size_t active_bits, size_t shift) ETL_NOEXCEPT
operator_shift_left
Definition bitset_new.h:688
static ETL_CONSTEXPR14 void operator_xor(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:671
static ETL_CONSTEXPR14 T value(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Get as a value.
Definition bitset_new.h:1077
static ETL_CONSTEXPR14 void flip_bits(pointer pbuffer, element_type mask=etl::integral_limits< element_type >::max) ETL_NOEXCEPT
Flip some of the bits.
Definition bitset_new.h:565
static ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Are none of the bits set?
Definition bitset_new.h:830
static ETL_CONSTEXPR14 void flip_position(pointer pbuffer, size_t position) ETL_NOEXCEPT
Flip the bit at the position.
Definition bitset_new.h:1264
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator|(const bitset< Active_Bits, TElement > &other) const ETL_NOEXCEPT
operator |
Definition bitset_new.h:2344
static ETL_CONSTEXPR14 void set_position(pointer pbuffer, size_t position, bool value=true) ETL_NOEXCEPT
Set the bit at the position.
Definition bitset_new.h:878
static ETL_CONSTEXPR14 void swap(pointer pbuffer1, pointer pbuffer2, size_t number_of_elements)
Swap bitset buffers.
Definition bitset_new.h:1591
static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator not
Definition bitset_new.h:1401
ETL_CONSTEXPR14 bitset & operator=(const bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:1864
static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
The number of bits in an element.
Definition bitset_new.h:2153
ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
Count the number of bits set.
Definition bitset_new.h:2187
static ETL_CONSTEXPR14 etl::enable_if< etl::integral_limits< TElementType >::bits==etl::integral_limits< unsignedlonglong >::bits, void >::type initialise(pointer pbuffer, size_t number_of_elements, unsigned long long value) ETL_NOEXCEPT
Definition bitset_new.h:1546
bitset()
Definition bitset_legacy.h:1137
static ETL_CONSTEXPR14 T value(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Get as an integral value.
Definition bitset_new.h:436
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set(bool value=true)
Set the bit at the position.
Definition bitset_new.h:1897
ETL_CONSTEXPR14 bool operator[](size_t position) const ETL_NOEXCEPT
Read [] operator.
Definition bitset_new.h:2271
static ETL_CONSTEXPR14 void reset_all(pointer pbuffer, size_t) ETL_NOEXCEPT
Reset all of the bits.
Definition bitset_new.h:283
ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if< is_same< TPString, const wchar_t * >::value >::type *=0) ETL_NOEXCEPT
Construct from a string.
Definition bitset_new.h:1835
ETL_CONSTEXPR14 etl::enable_if< etl::is_same< TPString, constchar * >::value, bitset< Active_Bits, TElement > & >::type set(TPString text) ETL_NOEXCEPT
Set from a string.
Definition bitset_new.h:1923
static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Are any of the bits set?
Definition bitset_new.h:846
static ETL_CONSTEXPR14 bool test(const_pointer pbuffer, size_t position)
Definition bitset_new.h:492
static ETL_CONSTEXPR14 void reset_position(pointer pbuffer, size_t position) ETL_NOEXCEPT
Reset the bit at the position.
Definition bitset_new.h:1065
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator^(const bitset< Active_Bits, TElement > &other) const ETL_NOEXCEPT
operator ^
Definition bitset_new.h:2366
static ETL_CONSTEXPR14 void set_all(pointer pbuffer, size_t, element_type top_mask) ETL_NOEXCEPT
Set all of the bits.
Definition bitset_new.h:222
static ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Are none of the bits set?
Definition bitset_new.h:525
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const char32_t *text) ETL_NOEXCEPT
Set from a u32 string.
Definition bitset_new.h:1024
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & reset(size_t position)
Reset the bit at the position.
Definition bitset_new.h:2085
ETL_CONSTEXPR14 etl::enable_if< etl::is_same< TPString, constwchar_t * >::value, bitset< Active_Bits, TElement > & >::type set(TPString text) ETL_NOEXCEPT
Set from a wide string.
Definition bitset_new.h:1935
static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
The number of bits in the bitset.
Definition bitset_new.h:2121
ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if< is_same< TPString, const char * >::value >::type *=0) ETL_NOEXCEPT
Construct from a string.
Definition bitset_new.h:1825
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t, size_t active_bits, const char32_t *text) ETL_NOEXCEPT
Set from a u32 string.
Definition bitset_new.h:402
static ETL_CONSTEXPR14 void operator_shift_right(pointer pbuffer, size_t number_of_elements, size_t active_bits, size_t shift) ETL_NOEXCEPT
operator_shift_right
Definition bitset_new.h:1472
static ETL_CONSTEXPR14 void operator_and(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:653
static ETL_CONSTEXPR14 void set_position(pointer pbuffer)
Set the bit at the position.
Definition bitset_new.h:266
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set()
Set the bit at the position.
Definition bitset_new.h:1910
static ETL_CONSTEXPR14 T extract(const_pointer pbuffer, size_t position, size_t length=etl::integral_limits< T >::bits)
Extract an integral value from an arbitrary position and length.
Definition bitset_new.h:445
unsigned long long to_ullong() const
Get as an unsigned long long.
Definition bitset_new.h:2065
ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
Are any of the bits set?
Definition bitset_new.h:2231
static ETL_CONSTEXPR14 bool operator_equality(const_pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
operator_equality
Definition bitset_new.h:718
ETL_CONSTEXPR14 bool test() const
Definition bitset_new.h:2111
ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
Definition bitset_new.h:2483
static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t, size_t active_bits, const char16_t *text) ETL_NOEXCEPT
Set from a u16 string.
Definition bitset_new.h:369
static ETL_CONSTEXPR14 void set_position(pointer pbuffer, bool value=true)
Set the bit at the position.
Definition bitset_new.h:248
unsigned long to_ulong() const
Get as an unsigned long.
Definition bitset_new.h:2055
static ETL_CONSTEXPR14 void operator_xor(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator xor
Definition bitset_new.h:1388
friend ETL_CONSTEXPR14 bool operator==(const bitset< Active_Bits, TElement > &lhs, const bitset< Active_Bits, TElement > &rhs) ETL_NOEXCEPT
operator ==
Definition bitset_new.h:2458
static ETL_CONSTEXPR14 etl::enable_if< etl::integral_limits< TElementType >::bits!=etl::integral_limits< unsignedlonglong >::bits, void >::type initialise(pointer pbuffer, size_t number_of_elements, unsigned long long value) ETL_NOEXCEPT
Definition bitset_new.h:1568
static ETL_CONSTEXPR14 size_t count(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Count the number of bits set.
Definition bitset_new.h:501
static ETL_CONSTEXPR14 void operator_assignment(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:644
static ETL_CONSTEXPR14 bool test(const_pointer pbuffer, size_t position) ETL_NOEXCEPT
Definition bitset_new.h:781
ETL_CONSTEXPR14 T extract() const
Definition bitset_new.h:2043
static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:680
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & operator|=(const bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
operator |=
Definition bitset_new.h:2356
friend ETL_CONSTEXPR14 bool operator!=(const bitset< Active_Bits, TElement > &lhs, const bitset< Active_Bits, TElement > &rhs) ETL_NOEXCEPT
operator !=
Definition bitset_new.h:2466
static ETL_CONSTEXPR14 TString to_string(const_pointer pbuffer, size_t active_bits, typename TString::value_type zero=typename TString::value_type('0'), typename TString::value_type one=typename TString::value_type('1'))
Returns a string representing the bitset.
Definition bitset_new.h:583
ETL_CONSTEXPR14 etl::enable_if< etl::is_same< TPString, constchar32_t * >::value, bitset< Active_Bits, TElement > & >::type set(TPString text) ETL_NOEXCEPT
Set from a char32 string.
Definition bitset_new.h:1959
ETL_CONSTEXPR14 bitset() ETL_NOEXCEPT
Default constructor.
Definition bitset_new.h:1796
static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
Definition bitset_new.h:2179
Bitset forward declaration.
Definition bitset_legacy.h:1124
Definition bitset_legacy.h:83
Definition bitset_new.h:198
Definition bitset_new.h:152
Definition bitset_legacy.h:125
Definition bitset_new.h:124
Definition bitset_new.h:90
#define ETL_ASSERT(b, e)
Definition error_handler.h:511
Definition exception.h:59
Definition integral_limits.h:517
#define ETL_DECLARE_ENUM_TYPE(TypeName, ValueType)
Definition enum_type.h:90
Definition absolute.h:40
ETL_CONSTEXPR14 void swap(etl::typed_storage_ext< T > &lhs, etl::typed_storage_ext< T > &rhs) ETL_NOEXCEPT
Swap two etl::typed_storage_ext.
Definition alignment.h:856
ETL_CONSTEXPR14 bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1078
ETL_CONSTEXPR TContainer::pointer data(TContainer &container)
Definition iterator.h:1470
etl::byte operator|(etl::byte lhs, etl::byte rhs)
Or.
Definition byte.h:250
etl::byte operator&(etl::byte lhs, etl::byte rhs)
And.
Definition byte.h:258
ETL_CONSTEXPR14 bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1090
etl::byte operator^(etl::byte lhs, etl::byte rhs)
Exclusive Or.
Definition byte.h:266
ETL_CONSTEXPR14 size_t strlen(const T *t) ETL_NOEXCEPT
Alternative strlen for all character types.
Definition char_traits.h:293
Check to see if the requested extract is contained within one element.
Definition bitset_new.h:771