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 element_type mask = element_type(element_type(1) << (string_length - 1U));
315
316 for (size_t i = 0U; i < string_length; ++i)
317 {
318 if (text[i] == ETL_STR('1'))
319 {
320 *pbuffer |= mask;
321 }
322
323 mask >>= 1U;
324 }
325 }
326 }
327
328 //*************************************************************************
330 //*************************************************************************
331 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, const wchar_t* text) ETL_NOEXCEPT
332 {
333 reset_all(pbuffer, 1U);
334
335 if (text != ETL_NULLPTR)
336 {
337 size_t string_length = etl::strlen(text);
338
339 // Build from the string.
340 string_length = etl::min(active_bits, string_length);
341
342 element_type mask = element_type(element_type(1) << (string_length - 1U));
343
344 for (size_t i = 0U; i < string_length; ++i)
345 {
346 if (text[i] == ETL_STRL('1'))
347 {
348 *pbuffer |= mask;
349 }
350
351 mask >>= 1U;
352 }
353 }
354 }
355
356 //*************************************************************************
358 //*************************************************************************
359 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, const char16_t* text) ETL_NOEXCEPT
360 {
361 reset_all(pbuffer, 1U);
362
363 if (text != ETL_NULLPTR)
364 {
365 size_t string_length = etl::strlen(text);
366
367 // Build from the string.
368 string_length = etl::min(active_bits, string_length);
369
370 element_type mask = element_type(element_type(1) << (string_length - 1U));
371
372 for (size_t i = 0U; i < string_length; ++i)
373 {
374 if (text[i] == ETL_STRu('1'))
375 {
376 *pbuffer |= mask;
377 }
378
379 mask >>= 1U;
380 }
381 }
382 }
383
384 //*************************************************************************
386 //*************************************************************************
387 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, const char32_t* text) ETL_NOEXCEPT
388 {
389 reset_all(pbuffer, 1U);
390
391 if (text != ETL_NULLPTR)
392 {
393 size_t string_length = etl::strlen(text);
394
395 // Build from the string.
396 string_length = etl::min(active_bits, string_length);
397
398 element_type mask = element_type(element_type(1) << (string_length - 1U));
399
400 for (size_t i = 0U; i < string_length; ++i)
401 {
402 if (text[i] == ETL_STRU('1'))
403 {
404 *pbuffer |= mask;
405 }
406
407 mask >>= 1U;
408 }
409 }
410 }
411
412 //*************************************************************************
414 //*************************************************************************
415 template <typename T>
416 static ETL_CONSTEXPR14 T value(const_pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
417 {
418 return T(*pbuffer);
419 }
420
421 //*************************************************************************
423 //*************************************************************************
424 template <typename T>
425 static ETL_CONSTEXPR14 T extract(const_pointer pbuffer, size_t position, size_t length = etl::integral_limits<T>::bits)
426 {
427 typedef typename etl::make_unsigned<T>::type unsigned_t;
428
429 const unsigned_t Mask = etl::make_lsb_mask<unsigned_t>(length);
430 const unsigned_t Shift = position % Bits_Per_Element;
431
432 unsigned_t value = static_cast<unsigned_t>(*pbuffer >> Shift) & Mask;
433
435 {
436 value = static_cast<unsigned_t>(etl::sign_extend<T>(static_cast<T>(value), length));
437 }
438
439 return static_cast<T>(value);
440 }
441
442 //*************************************************************************
444 //*************************************************************************
445#if ETL_USING_CPP11
446 template <typename T, size_t Position, size_t Length = etl::integral_limits<T>::bits>
447#else
448 template <typename T, size_t Position, size_t Length>
449#endif
450 static ETL_CONSTEXPR14 T extract(const_pointer pbuffer)
451 {
452 typedef typename etl::make_unsigned<T>::type unsigned_t;
453
454 const unsigned_t Mask = etl::make_lsb_mask<unsigned_t>(Length);
455 const unsigned_t Shift = Position % Bits_Per_Element;
456
457 unsigned_t value = static_cast<unsigned_t>(*pbuffer >> Shift) & Mask;
458
460 {
461 value = static_cast<unsigned_t>(etl::sign_extend<T>(static_cast<T>(value), Length));
462 }
463
464 return static_cast<T>(value);
465 }
466
467 //*************************************************************************
471 //*************************************************************************
472 static ETL_CONSTEXPR14 bool test(const_pointer pbuffer, size_t position)
473 {
474 const element_type mask = element_type(element_type(1) << position);
475 return (*pbuffer & mask) != 0U;
476 }
477
478 //*************************************************************************
480 //*************************************************************************
481 static ETL_CONSTEXPR14 size_t count(const_pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
482 {
483 return etl::count_bits(*pbuffer);
484 }
485
486 //*************************************************************************
487 // Are all the bits sets?
488 //*************************************************************************
489 static ETL_CONSTEXPR14 bool all(const_pointer pbuffer, size_t /*number_of_elements*/, element_type top_mask) ETL_NOEXCEPT
490 {
491 return (*pbuffer & top_mask) == top_mask;
492 }
493
494 //*************************************************************************
495 // Are all the mask bits sets?
496 //*************************************************************************
497 static ETL_CONSTEXPR14 bool all(const_pointer pbuffer, size_t /*number_of_elements*/, element_type top_mask, element_type mask) ETL_NOEXCEPT
498 {
499 return (*pbuffer & top_mask & mask) == mask;
500 }
501
502 //*************************************************************************
504 //*************************************************************************
505 static ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
506 {
507 return *pbuffer == All_Clear_Element;
508 }
509
510 //*************************************************************************
512 //*************************************************************************
513 static ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t /*number_of_elements*/, element_type mask) ETL_NOEXCEPT
514 {
515 return (*pbuffer & mask) == All_Clear_Element;
516 }
517
518 //*************************************************************************
520 //*************************************************************************
521 static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
522 {
523 return *pbuffer != All_Clear_Element;
524 }
525
526 //*************************************************************************
528 //*************************************************************************
529 static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t /*number_of_elements*/, element_type mask) ETL_NOEXCEPT
530 {
531 return (*pbuffer & mask) != All_Clear_Element;
532 }
533
534 //*************************************************************************
536 //*************************************************************************
537 static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
538 {
539 *pbuffer = ~*pbuffer;
540 }
541
542 //*************************************************************************
544 //*************************************************************************
545 static ETL_CONSTEXPR14 void flip_bits(pointer pbuffer, element_type mask = etl::integral_limits<element_type>::max) ETL_NOEXCEPT
546 {
547 *pbuffer ^= mask;
548 }
549
550 //*************************************************************************
552 //*************************************************************************
553 static ETL_CONSTEXPR14 void flip_position(pointer pbuffer, size_t position)
554 {
555 const element_type mask = element_type(element_type(1) << position);
556 *pbuffer ^= mask;
557 }
558
559 //*************************************************************************
561 //*************************************************************************
562 template <typename TString>
563 static ETL_CONSTEXPR14 TString to_string(const_pointer pbuffer, size_t active_bits,
564 typename TString::value_type zero = typename TString::value_type('0'),
565 typename TString::value_type one = typename TString::value_type('1'))
566 {
567 TString result;
568
569 result.resize(active_bits, '\0');
570
571 // Check that the string type can contain the digits.
572 ETL_ASSERT_OR_RETURN_VALUE(result.size() == active_bits, ETL_ERROR(etl::bitset_string_too_small), result);
573
574 for (size_t i = active_bits; i > 0; --i)
575 {
576 result[active_bits - i] = test(pbuffer, i - 1) ? one : zero;
577 }
578
579 return result;
580 }
581
582 //*************************************************************************
587 //*************************************************************************
588 static ETL_CONSTEXPR14 size_t find_next(const_pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, bool state, size_t position)
589 ETL_NOEXCEPT
590 {
591 if (position < active_bits)
592 {
593 // Where to start.
594 size_t bit = position;
595
596 element_type mask = 1U << position;
597
598 // Needs checking?
599 if ((state && (*pbuffer != All_Clear_Element)) || (!state && (*pbuffer != All_Set_Element)))
600 {
601 // For each bit in the element...
602 while (bit < active_bits)
603 {
604 // Equal to the required state?
605 if (((*pbuffer & mask) != 0) == state)
606 {
607 return bit;
608 }
609
610 // Move on to the next bit.
611 mask <<= 1;
612 ++bit;
613 }
614 }
615 }
616
617 return npos;
618 }
619
620 //*************************************************************************
623 //*************************************************************************
624 static ETL_CONSTEXPR14 void operator_assignment(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
625 {
626 *lhs_pbuffer = *rhs_pbuffer;
627 }
628
629 //*************************************************************************
632 //*************************************************************************
633 static ETL_CONSTEXPR14 void operator_and(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
634 {
635 *lhs_pbuffer &= *rhs_pbuffer;
636 }
637
638 //*************************************************************************
641 //*************************************************************************
642 static ETL_CONSTEXPR14 void operator_or(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
643 {
644 *lhs_pbuffer |= *rhs_pbuffer;
645 }
646
647 //*************************************************************************
650 //*************************************************************************
651 static ETL_CONSTEXPR14 void operator_xor(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
652 {
653 *lhs_pbuffer ^= *rhs_pbuffer;
654 }
655
656 //*************************************************************************
659 //*************************************************************************
660 static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
661 {
662 *pbuffer = ~*pbuffer;
663 }
664
665 //*************************************************************************
667 //*************************************************************************
668 static ETL_CONSTEXPR14 void operator_shift_left(pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, size_t shift) ETL_NOEXCEPT
669 {
670 if (shift >= active_bits)
671 {
672 reset_all(pbuffer, 1U);
673 }
674 else
675 {
676 *pbuffer <<= shift;
677 }
678 }
679
680 //*************************************************************************
682 //*************************************************************************
683 static ETL_CONSTEXPR14 void operator_shift_right(pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, size_t shift) ETL_NOEXCEPT
684 {
685 if (shift >= active_bits)
686 {
687 reset_all(pbuffer, 1U);
688 }
689 else
690 {
691 *pbuffer >>= shift;
692 }
693 }
694
695 //*************************************************************************
697 //*************************************************************************
698 static ETL_CONSTEXPR14 bool operator_equality(const_pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
699 {
700 return (*lhs_pbuffer == *rhs_pbuffer);
701 }
702
703 //*************************************************************************
705 //*************************************************************************
706 template <typename TElementType>
707 static ETL_CONSTEXPR14 void initialise(pointer pbuffer, size_t /*number_of_elements*/, unsigned long long value) ETL_NOEXCEPT
708 {
709 *pbuffer = static_cast<TElementType>(value);
710 }
711
712 //*************************************************************************
714 //*************************************************************************
715 static ETL_CONSTEXPR14 void swap(pointer lhs_pbuffer, pointer rhs_pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
716 {
717 element_type temp = *lhs_pbuffer;
718 *lhs_pbuffer = *rhs_pbuffer;
719 *rhs_pbuffer = temp;
720 }
721 };
722
723 //*************************************************************************
726 //*************************************************************************
727 template <typename TElement>
728 class bitset_impl<TElement, etl::bitset_storage_model::Multi> : public etl::private_bitset::bitset_impl_common<TElement>
729 {
730 private:
731
733
734 public:
735
736 using typename etl::private_bitset::bitset_impl_common<TElement>::element_type;
737 using typename etl::private_bitset::bitset_impl_common<TElement>::pointer;
738 using typename etl::private_bitset::bitset_impl_common<TElement>::const_pointer;
739
740 using etl::private_bitset::bitset_impl_common<TElement>::Bits_Per_Element;
741 using etl::private_bitset::bitset_impl_common<TElement>::All_Set_Element;
742 using etl::private_bitset::bitset_impl_common<TElement>::All_Clear_Element;
743
744 using etl::private_bitset::bitset_impl_common<TElement>::npos;
745
746 //*************************************************************************
748 //*************************************************************************
749 template <size_t Position, size_t Length, size_t Bits_Per_Element>
751 {
752 static
753 ETL_CONSTANT bool value = ((Position + Length - 1) >> etl::log2<Bits_Per_Element>::value) == (Position >> etl::log2<Bits_Per_Element>::value);
754 };
755
756 //*************************************************************************
760 //*************************************************************************
761 static ETL_CONSTEXPR14 bool test(const_pointer pbuffer, size_t position) ETL_NOEXCEPT
762 {
763 size_t index = position >> etl::log2<Bits_Per_Element>::value;
764 element_type mask = element_type(1) << (position & (Bits_Per_Element - 1));
765
766 return (pbuffer[index] & mask) != 0;
767 }
768
769 //*************************************************************************
771 //*************************************************************************
772 static ETL_CONSTEXPR14 size_t count(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
773 {
774 size_t count = 0;
775
776 while (number_of_elements-- != 0)
777 {
778 count += etl::count_bits(*pbuffer++);
779 }
780
781 return count;
782 }
783
784 //*************************************************************************
785 // Are all the bits sets?
786 //*************************************************************************
787 static ETL_CONSTEXPR14 bool all(const_pointer pbuffer, size_t number_of_elements, element_type top_mask) ETL_NOEXCEPT
788 {
789 // All but the last.
790 while (number_of_elements-- != 1U)
791 {
792 if (*pbuffer++ != All_Set_Element)
793 {
794 return false;
795 }
796 }
797
798 // The last.
799 if ((*pbuffer & top_mask) != top_mask)
800 {
801 return false;
802 }
803
804 return true;
805 }
806
807 //*************************************************************************
809 //*************************************************************************
810 static ETL_CONSTEXPR14 bool none(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
811 {
812 while (number_of_elements-- != 0)
813 {
814 if (*pbuffer++ != 0)
815 {
816 return false;
817 }
818 }
819
820 return true;
821 }
822
823 //*************************************************************************
825 //*************************************************************************
826 static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
827 {
828 bool any_set = false;
829
830 while (number_of_elements-- != 0)
831 {
832 if (*pbuffer++ != All_Clear_Element)
833 {
834 any_set = true;
835 break;
836 }
837 }
838
839 return any_set;
840 }
841
842 //*************************************************************************
844 //*************************************************************************
845 static ETL_CONSTEXPR14 void set_all(pointer pbuffer, size_t number_of_elements, element_type top_mask) ETL_NOEXCEPT
846 {
847 while (number_of_elements-- != 1U)
848 {
849 *pbuffer++ = All_Set_Element;
850 }
851
852 *pbuffer = (All_Set_Element & top_mask);
853 }
854
855 //*************************************************************************
857 //*************************************************************************
858 static ETL_CONSTEXPR14 void set_position(pointer pbuffer, size_t position, bool value = true) ETL_NOEXCEPT
859 {
860 size_t index = position >> etl::log2<Bits_Per_Element>::value;
861 element_type bit = element_type(1) << (position & (Bits_Per_Element - 1));
862
863 if (value == true)
864 {
865 pbuffer[index] |= bit;
866 }
867 else
868 {
869 pbuffer[index] &= ~bit;
870 }
871 }
872
873 //*************************************************************************
875 //*************************************************************************
876 template <size_t Position>
877 static ETL_CONSTEXPR14 void set_position(pointer pbuffer, bool value = true)
878 {
879 size_t index = Position >> etl::log2<Bits_Per_Element>::value;
880 element_type bit = element_type(1) << (Position & (Bits_Per_Element - 1));
881
882 if (value == true)
883 {
884 pbuffer[index] |= bit;
885 }
886 else
887 {
888 pbuffer[index] &= ~bit;
889 }
890 }
891
892 //*************************************************************************
894 //*************************************************************************
895 template <size_t Position, bool Value>
896 static ETL_CONSTEXPR14 void set_position(pointer pbuffer)
897 {
898 size_t index = Position >> etl::log2<Bits_Per_Element>::value;
899 element_type bit = element_type(1) << (Position & (Bits_Per_Element - 1));
900
901 if (Value == true)
902 {
903 pbuffer[index] |= bit;
904 }
905 else
906 {
907 pbuffer[index] &= ~bit;
908 }
909 }
910
911 //*************************************************************************
913 //*************************************************************************
914 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const char* text) ETL_NOEXCEPT
915 {
916 if (text == ETL_NULLPTR)
917 {
918 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
919 }
920 else
921 {
922 size_t string_length = etl::strlen(text);
923 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
924
925 // Only reset elements we need to.
926 while (index != number_of_elements)
927 {
928 pbuffer[index++] = All_Clear_Element;
929 }
930
931 // Build from the string.
932 size_t i = etl::min(total_bits, string_length);
933
934 while (i > 0)
935 {
936 set_position(pbuffer, --i, *text++ == ETL_STR('1'));
937 }
938 }
939 }
940
941 //*************************************************************************
943 //*************************************************************************
944 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const wchar_t* text) ETL_NOEXCEPT
945 {
946 if (text == ETL_NULLPTR)
947 {
948 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
949 }
950 else
951 {
952 size_t string_length = etl::strlen(text);
953 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
954
955 // Only reset elements we need to.
956 while (index != number_of_elements)
957 {
958 pbuffer[index++] = All_Clear_Element;
959 }
960
961 // Build from the string.
962 size_t i = etl::min(total_bits, string_length);
963
964 while (i > 0)
965 {
966 set_position(pbuffer, --i, *text++ == ETL_STRL('1'));
967 }
968 }
969 }
970
971 //*************************************************************************
973 //*************************************************************************
974 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const char16_t* text) ETL_NOEXCEPT
975 {
976 if (text == ETL_NULLPTR)
977 {
978 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
979 }
980 else
981 {
982 size_t string_length = etl::strlen(text);
983 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
984
985 // Only reset elements we need to.
986 while (index != number_of_elements)
987 {
988 pbuffer[index++] = All_Clear_Element;
989 }
990
991 // Build from the string.
992 size_t i = etl::min(total_bits, string_length);
993
994 while (i > 0)
995 {
996 set_position(pbuffer, --i, *text++ == ETL_STRu('1'));
997 }
998 }
999 }
1000
1001 //*************************************************************************
1003 //*************************************************************************
1004 static ETL_CONSTEXPR14 void from_string(pointer pbuffer, size_t number_of_elements, size_t total_bits, const char32_t* text) ETL_NOEXCEPT
1005 {
1006 if (text == ETL_NULLPTR)
1007 {
1008 etl::fill_n(pbuffer, number_of_elements, All_Clear_Element);
1009 }
1010 else
1011 {
1012 size_t string_length = etl::strlen(text);
1013 size_t index = etl::min(number_of_elements - 1U, (string_length / Bits_Per_Element));
1014
1015 // Only reset elements we need to.
1016 while (index != number_of_elements)
1017 {
1018 pbuffer[index++] = All_Clear_Element;
1019 }
1020
1021 // Build from the string.
1022 size_t i = etl::min(total_bits, string_length);
1023
1024 while (i > 0)
1025 {
1026 set_position(pbuffer, --i, *text++ == ETL_STRU('1'));
1027 }
1028 }
1029 }
1030
1031 //*************************************************************************
1033 //*************************************************************************
1034 static ETL_CONSTEXPR14 void reset_all(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1035 {
1036 while (number_of_elements-- != 0U)
1037 {
1038 *pbuffer++ = All_Clear_Element;
1039 }
1040 }
1041
1042 //*************************************************************************
1044 //*************************************************************************
1045 static ETL_CONSTEXPR14 void reset_position(pointer pbuffer, size_t position) ETL_NOEXCEPT
1046 {
1047 const size_t index = position >> etl::log2<Bits_Per_Element>::value;
1048 const element_type bit = element_type(1) << (position & (Bits_Per_Element - 1));
1049
1050 pbuffer[index] &= ~bit;
1051 }
1052
1053 //*************************************************************************
1055 //*************************************************************************
1056 template <typename T>
1057 static ETL_CONSTEXPR14 T value(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1058 {
1059 T v = T(0);
1060
1061 const bool OK = (sizeof(T) * CHAR_BIT) >= (number_of_elements * Bits_Per_Element);
1062
1063 if (OK)
1064 {
1065 uint_least8_t shift = 0U;
1066
1067 for (size_t i = 0UL; i < number_of_elements; ++i)
1068 {
1069 v |= T(typename etl::make_unsigned<T>::type(pbuffer[i]) << shift);
1070 shift += uint_least8_t(Bits_Per_Element);
1071 }
1072 }
1073
1074 return v;
1075 }
1076
1077 //*************************************************************************
1079 //*************************************************************************
1080 template <typename T>
1081 static ETL_CONSTEXPR14 typename etl::make_unsigned<T>::type extract_from_multiple_elements(const element_type* pbuffer, int element_index,
1082 size_t active_bits_in_msb, size_t length) ETL_NOEXCEPT
1083 {
1084 typedef typename etl::make_unsigned<T>::type unsigned_t;
1085
1086 unsigned_t value(0);
1087
1088 // Extract the first element, if partially filled.
1089 if (active_bits_in_msb < Bits_Per_Element)
1090 {
1091 element_type mask = etl::make_lsb_mask< element_type>(active_bits_in_msb);
1092 value = pbuffer[element_index] & mask;
1093 length -= active_bits_in_msb;
1094 if (length >= Bits_Per_Element)
1095 {
1096 value = value << Bits_Per_Element;
1097 }
1098 --element_index;
1099 }
1100
1101 // Loop through the fully filled elements
1102 while (length >= Bits_Per_Element)
1103 {
1104 value |= pbuffer[element_index];
1105 length -= Bits_Per_Element;
1106 if (length >= Bits_Per_Element)
1107 {
1108 value = value << Bits_Per_Element;
1109 }
1110 --element_index;
1111 }
1112
1113 // Extract the last element, if partially filled.
1114 if (length != 0)
1115 {
1116 value = value << length;
1117 element_type mask = etl::make_lsb_mask< element_type>(length);
1118 value |= (pbuffer[element_index] >> (Bits_Per_Element - length)) & mask;
1119 }
1120
1121 return value;
1122 }
1123
1124 //*************************************************************************
1127 //*************************************************************************
1128 template <typename T>
1129 static ETL_CONSTEXPR14 typename etl::make_unsigned<T>::type extract_from_buffer(const_pointer pbuffer, size_t position, size_t length)
1130 ETL_NOEXCEPT
1131 {
1132 typedef typename etl::make_unsigned<T>::type unsigned_t;
1133
1134 unsigned_t value(0);
1135
1136 const int Msb_Element_Index = (position + length - 1) >> etl::log2<Bits_Per_Element>::value;
1137 const int Lsb_Element_Index = position >> etl::log2<Bits_Per_Element>::value;
1138
1139 // Is the value contained within one element?
1140 if (Msb_Element_Index == Lsb_Element_Index)
1141 {
1142 const unsigned_t Mask = etl::make_lsb_mask< unsigned_t>(length);
1143 const unsigned_t Shift = position % Bits_Per_Element;
1144
1145 value = static_cast<unsigned_t>(pbuffer[Msb_Element_Index] >> Shift) & Mask;
1146 }
1147 else
1148 {
1149 // Get the number of active bits in the msb element
1150 size_t active_bits_in_msb = (position + length) - (static_cast<size_t>(Msb_Element_Index) * Bits_Per_Element);
1151
1152 // Start with index of the element containing the msb.
1153 int element_index = Msb_Element_Index;
1154
1155 value = extract_from_multiple_elements<T>(pbuffer, element_index, active_bits_in_msb, length);
1156 }
1157
1158 return value;
1159 }
1160
1161 //*************************************************************************
1164 //*************************************************************************
1165 template <typename T, size_t Position, size_t Length>
1166 static ETL_CONSTEXPR14
1167 typename etl::enable_if< value_is_in_one_element<Position, Length, Bits_Per_Element>::value, typename etl::make_unsigned<T>::type>::type
1168 extract_from_buffer(const_pointer pbuffer)
1169 {
1170 typedef typename etl::make_unsigned<T>::type unsigned_t;
1171
1172 const int Element_Index = (Position + Length - 1) >> etl::log2<Bits_Per_Element>::value;
1173 const unsigned_t Mask = etl::lsb_mask<unsigned_t, Length>::value;
1174 const unsigned_t Shift = Position % Bits_Per_Element;
1175
1176 return static_cast<unsigned_t>(pbuffer[Element_Index] >> Shift) & Mask;
1177 }
1178
1179 //*************************************************************************
1182 //*************************************************************************
1183 template <typename T, size_t Position, size_t Length>
1184 static ETL_CONSTEXPR14
1185 typename etl::enable_if< !value_is_in_one_element<Position, Length, Bits_Per_Element>::value, typename etl::make_unsigned<T>::type>::type
1186 extract_from_buffer(const_pointer pbuffer)
1187 {
1188 // Start with index of the element containing the msb.
1189 const int Msb_Element_Index = (Position + Length - 1) >> etl::log2<Bits_Per_Element>::value;
1190
1191 // Get the number of active bits in the first element
1192 const size_t Active_Bits_In_Msb = ((Position + Length - 1) % Bits_Per_Element) + 1;
1193
1194 return extract_from_multiple_elements<T>(pbuffer, Msb_Element_Index, Active_Bits_In_Msb, Length);
1195 }
1196
1197 //*************************************************************************
1199 //*************************************************************************
1200 template <typename T>
1201 static ETL_CONSTEXPR14 T extract(const_pointer pbuffer, size_t position, size_t length = etl::integral_limits<T>::bits)
1202 {
1203 typedef typename etl::make_unsigned<T>::type unsigned_t;
1204
1205 unsigned_t value = extract_from_buffer<unsigned_t>(pbuffer, position, length);
1206
1208 {
1209 value = static_cast<unsigned_t>(etl::sign_extend<T>(static_cast<T>(value), length));
1210 }
1211
1212 return static_cast<T>(value);
1213 }
1214
1215 //*************************************************************************
1217 //*************************************************************************
1218 template <typename T, size_t Position, size_t Length>
1219 static ETL_CONSTEXPR14 T extract(const_pointer pbuffer)
1220 {
1221 typedef typename etl::make_unsigned<T>::type unsigned_t;
1222
1224
1226 {
1227 value = static_cast<unsigned_t>(etl::sign_extend<T>(static_cast<T>(value), Length));
1228 }
1229
1230 return static_cast<T>(value);
1231 }
1232
1233 //*************************************************************************
1235 //*************************************************************************
1236 static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1237 {
1238 operator_not(pbuffer, number_of_elements);
1239 }
1240
1241 //*************************************************************************
1243 //*************************************************************************
1244 static ETL_CONSTEXPR14 void flip_position(pointer pbuffer, size_t position) ETL_NOEXCEPT
1245 {
1246 const size_t index = position >> etl::log2<Bits_Per_Element>::value;
1247 const element_type bit = element_type(1) << (position & (Bits_Per_Element - 1));
1248
1249 pbuffer[index] ^= bit;
1250 }
1251
1252 //*************************************************************************
1257 //*************************************************************************
1258 static ETL_CONSTEXPR14 size_t find_next(const_pointer pbuffer, size_t number_of_elements, size_t total_bits, bool state, size_t position)
1259 ETL_NOEXCEPT
1260 {
1261 // Where to start.
1262 size_t index = position >> log2<Bits_Per_Element>::value;
1263 size_t bit = position & (Bits_Per_Element - 1);
1264
1265 element_type mask = 1 << bit;
1266
1267 // For each element in the bitset...
1268 while (index < number_of_elements)
1269 {
1270 element_type value = pbuffer[index];
1271
1272 // Needs checking?
1273 if ((state && (value != All_Clear_Element)) || (!state && (value != All_Set_Element)))
1274 {
1275 // For each bit in the element...
1276 while ((bit < Bits_Per_Element) && (position < total_bits))
1277 {
1278 // Equal to the required state?
1279 if (((value & mask) != 0) == state)
1280 {
1281 return position;
1282 }
1283
1284 // Move on to the next bit.
1285 mask <<= 1;
1286 ++position;
1287 ++bit;
1288 }
1289 }
1290 else
1291 {
1292 position += (Bits_Per_Element - bit);
1293 }
1294
1295 // Start at the beginning for all other elements.
1296 bit = 0;
1297 mask = 1;
1298
1299 ++index;
1300 }
1301
1302 return npos;
1303 }
1304
1305 //*************************************************************************
1307 //*************************************************************************
1308 template <typename TString>
1309 static ETL_CONSTEXPR14 TString to_string(const_pointer pbuffer, size_t active_bits, typename TString::value_type zero, typename TString::value_type one)
1310 {
1311 TString result;
1312
1313 result.resize(active_bits, '\0');
1314
1315 // Check that the string type can contain the digits.
1316 ETL_ASSERT_OR_RETURN_VALUE(result.size() == active_bits, ETL_ERROR(etl::bitset_string_too_small), result);
1317
1318 for (size_t i = active_bits; i > 0; --i)
1319 {
1320 result[active_bits - i] = test(pbuffer, i - 1) ? one : zero;
1321 }
1322
1323 return result;
1324 }
1325
1326 //*************************************************************************
1328 //*************************************************************************
1329 static ETL_CONSTEXPR14 void operator_assignment(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1330 {
1331 while (number_of_elements-- != 0)
1332 {
1333 *lhs_pbuffer = *rhs_pbuffer;
1334 ++lhs_pbuffer;
1335 ++rhs_pbuffer;
1336 }
1337 }
1338
1339 //*************************************************************************
1341 //*************************************************************************
1342 static ETL_CONSTEXPR14 void operator_and(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1343 {
1344 while (number_of_elements-- != 0)
1345 {
1346 *lhs_pbuffer &= *rhs_pbuffer;
1347 ++lhs_pbuffer;
1348 ++rhs_pbuffer;
1349 }
1350 }
1351
1352 //*************************************************************************
1354 //*************************************************************************
1355 static ETL_CONSTEXPR14 void operator_or(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1356 {
1357 while (number_of_elements-- != 0)
1358 {
1359 *lhs_pbuffer |= *rhs_pbuffer;
1360 ++lhs_pbuffer;
1361 ++rhs_pbuffer;
1362 }
1363 }
1364
1365 //*************************************************************************
1367 //*************************************************************************
1368 static ETL_CONSTEXPR14 void operator_xor(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1369 {
1370 while (number_of_elements-- != 0)
1371 {
1372 *lhs_pbuffer ^= *rhs_pbuffer;
1373 ++lhs_pbuffer;
1374 ++rhs_pbuffer;
1375 }
1376 }
1377
1378 //*************************************************************************
1380 //*************************************************************************
1381 static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1382 {
1383 while (number_of_elements-- != 0)
1384 {
1385 *pbuffer = ~*pbuffer;
1386 ++pbuffer;
1387 }
1388 }
1389
1390 //*************************************************************************
1392 //*************************************************************************
1393 static ETL_CONSTEXPR14 void operator_shift_left(pointer pbuffer, size_t number_of_elements, size_t active_bits, size_t shift) ETL_NOEXCEPT
1394 {
1395 if (shift >= active_bits)
1396 {
1397 reset_all(pbuffer, number_of_elements);
1398 }
1399 else
1400 {
1401 // The place where the elements are split when shifting.
1402 const size_t split_position = Bits_Per_Element - (shift % Bits_Per_Element);
1403
1404 // Where we are shifting from.
1405 int src_index = int(number_of_elements - (shift / Bits_Per_Element) - 1U);
1406
1407 // Where we are shifting to.
1408 int dst_index = int(number_of_elements - 1U);
1409
1410 // Shift control constants.
1411 const size_t lsb_shift = Bits_Per_Element - split_position;
1412 const size_t msb_shift = split_position;
1413
1414 const element_type lsb_mask = element_type(etl::integral_limits<element_type>::max >> (Bits_Per_Element - split_position));
1416 const element_type lsb_shifted_mask = element_type(lsb_mask << lsb_shift);
1417
1418 // First lsb.
1419 element_type lsb = element_type((pbuffer[src_index] & lsb_mask) << lsb_shift);
1420 pbuffer[dst_index] = lsb;
1421 --src_index;
1422
1423 // Now do the shifting.
1424 while (src_index >= 0)
1425 {
1426 // Shift msb.
1427 element_type msb = element_type((pbuffer[src_index] & msb_mask) >> msb_shift);
1428 pbuffer[dst_index] = pbuffer[dst_index] | msb;
1429 --dst_index;
1430
1431 // Shift lsb.
1432 lsb = element_type((pbuffer[src_index] & lsb_mask) << lsb_shift);
1433 pbuffer[dst_index] = lsb;
1434 --src_index;
1435 }
1436
1437 // Clear the remaining bits.
1438 // First lsb.
1439 pbuffer[dst_index] &= lsb_shifted_mask;
1440
1441 // The other remaining bytes on the right.
1442 for (int i = 0; i < dst_index; ++i)
1443 {
1444 pbuffer[i] = 0;
1445 }
1446 }
1447 }
1448
1449 //*************************************************************************
1451 //*************************************************************************
1452 static ETL_CONSTEXPR14 void operator_shift_right(pointer pbuffer, size_t number_of_elements, size_t active_bits, size_t shift) ETL_NOEXCEPT
1453 {
1454 if (shift >= active_bits)
1455 {
1456 reset_all(pbuffer, number_of_elements);
1457 }
1458 else
1459 {
1460 // The place where the elements are split when shifting.
1461 const size_t split_position = shift % Bits_Per_Element;
1462
1463 // Where we are shifting from.
1464 int src_index = int(shift / Bits_Per_Element);
1465
1466 // Where we are shifting to.
1467 int dst_index = 0;
1468
1469 // Shift control constants.
1470 const size_t lsb_shift = Bits_Per_Element - split_position;
1471 const size_t msb_shift = split_position;
1472
1473 const element_type lsb_mask = element_type(etl::integral_limits<element_type>::max >> (Bits_Per_Element - split_position));
1475 const element_type msb_shifted_mask = element_type(msb_mask >> msb_shift);
1476
1477 // Now do the shifting.
1478 while (src_index < int(number_of_elements - 1))
1479 {
1480 // Shift msb.
1481 element_type msb = element_type((pbuffer[src_index] & msb_mask) >> msb_shift);
1482 ++src_index;
1483
1484 // Shift lsb.
1485 element_type lsb = element_type((pbuffer[src_index] & lsb_mask) << lsb_shift);
1486
1487 // Combine them.
1488 pbuffer[dst_index] = lsb | msb;
1489 ++dst_index;
1490 }
1491
1492 // Final msb.
1493 element_type msb = element_type((pbuffer[src_index] & msb_mask) >> msb_shift);
1494 pbuffer[dst_index] = msb;
1495
1496 // Clear the remaining bits.
1497 // First msb.
1498 pbuffer[dst_index] &= msb_shifted_mask;
1499 ++dst_index;
1500
1501 // The other remaining bytes.
1502 while (dst_index < int(number_of_elements))
1503 {
1504 pbuffer[dst_index] = 0;
1505 ++dst_index;
1506 }
1507 }
1508 }
1509
1510 //*************************************************************************
1512 //*************************************************************************
1513 static ETL_CONSTEXPR14 bool operator_equality(const_pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t number_of_elements) ETL_NOEXCEPT
1514 {
1515 return etl::equal(lhs_pbuffer, lhs_pbuffer + number_of_elements, rhs_pbuffer);
1516 }
1517
1518 //*************************************************************************
1522 //*************************************************************************
1523 template <typename TElementType>
1524 static
1525 ETL_CONSTEXPR14 typename etl::enable_if< etl::integral_limits<TElementType>::bits == etl::integral_limits<unsigned long long>::bits, void>::type
1526 initialise(pointer pbuffer, size_t number_of_elements, unsigned long long value) ETL_NOEXCEPT
1527 {
1528 size_t i = 0UL;
1529
1530 // Set the non-zero elements.
1531 pbuffer[i++] = value;
1532
1533 // Clear the remaining elements.
1534 while (i != number_of_elements)
1535 {
1536 pbuffer[i++] = All_Clear_Element;
1537 }
1538 }
1539
1540 //*************************************************************************
1544 //*************************************************************************
1545 template <typename TElementType>
1546 static
1547 ETL_CONSTEXPR14 typename etl::enable_if< etl::integral_limits<TElementType>::bits != etl::integral_limits<unsigned long long>::bits, void>::type
1548 initialise(pointer pbuffer, size_t number_of_elements, unsigned long long value) ETL_NOEXCEPT
1549 {
1550 size_t i = 0UL;
1551
1552 // Set the non-zero elements.
1553 const unsigned long long Shift = etl::integral_limits<element_type>::bits;
1554
1555 while ((value != 0) && (i != number_of_elements))
1556 {
1557 pbuffer[i++] = value & All_Set_Element;
1558 value = value >> Shift;
1559 }
1560
1561 // Clear the remaining elements.
1562 while (i != number_of_elements)
1563 {
1564 pbuffer[i++] = All_Clear_Element;
1565 }
1566 }
1567
1568 //*************************************************************************
1570 //*************************************************************************
1571 static ETL_CONSTEXPR14 void swap(pointer pbuffer1, pointer pbuffer2, size_t number_of_elements)
1572 {
1573 etl::swap_ranges(pbuffer1, pbuffer1 + number_of_elements, pbuffer2);
1574 }
1575 };
1576
1577 namespace private_bitset
1578 {
1579 //***************************************************************************
1580 template <size_t Active_Bits, typename TElement>
1582 {
1583 public:
1584
1585 typedef typename etl::private_bitset::bitset_impl_common<TElement>::element_type element_type;
1586
1587 using etl::private_bitset::bitset_impl_common<TElement>::Bits_Per_Element;
1588 using etl::private_bitset::bitset_impl_common<TElement>::All_Set_Element;
1589 using etl::private_bitset::bitset_impl_common< TElement>::All_Clear_Element;
1590
1591 static ETL_CONSTANT size_t Number_Of_Elements =
1592 (Active_Bits % Bits_Per_Element == 0) ? Active_Bits / Bits_Per_Element : Active_Bits / Bits_Per_Element + 1;
1593 static ETL_CONSTANT size_t Size = Active_Bits;
1594 static ETL_CONSTANT size_t Allocated_Bits = Number_Of_Elements * Bits_Per_Element;
1595
1596#if ETL_USING_CPP11
1597 static ETL_CONSTANT etl::bitset_storage_model Storage_Model =
1598 (bitset_common<Active_Bits, TElement>::Number_Of_Elements == 1U) ? etl::bitset_storage_model::Single : etl::bitset_storage_model::Multi;
1599#else
1600 static ETL_CONSTANT etl::bitset_storage_model Storage_Model;
1601#endif
1602
1605
1606 private:
1607
1608 static ETL_CONSTANT size_t Top_Mask_Shift = ((Bits_Per_Element - ((Number_Of_Elements * Bits_Per_Element) - Active_Bits)) % Bits_Per_Element);
1609
1610 public:
1611
1612 static ETL_CONSTANT TElement Top_Mask = element_type(Top_Mask_Shift == 0 ? All_Set_Element : ~(All_Set_Element << Top_Mask_Shift));
1613 };
1614
1615 template <size_t Active_Bits, typename TElement>
1616 ETL_CONSTANT size_t bitset_common<Active_Bits, TElement>::Number_Of_Elements;
1617
1618 template <size_t Active_Bits, typename TElement>
1619 ETL_CONSTANT size_t bitset_common<Active_Bits, TElement>::Size;
1620
1621#if ETL_USING_CPP11
1622 template <size_t Active_Bits, typename TElement>
1623 ETL_CONSTANT etl::bitset_storage_model bitset_common<Active_Bits, TElement>::Storage_Model;
1624#else
1625 template <size_t Active_Bits, typename TElement>
1626 ETL_CONSTANT etl::bitset_storage_model bitset_common<Active_Bits, TElement>::Storage_Model =
1627 (bitset_common<Active_Bits, TElement>::Number_Of_Elements == 1U) ? etl::bitset_storage_model::Single : etl::bitset_storage_model::Multi;
1628#endif
1629
1630 template <size_t Active_Bits, typename TElement>
1631 ETL_CONSTANT size_t bitset_common<Active_Bits, TElement>::Top_Mask_Shift;
1632
1633 template <size_t Active_Bits, typename TElement>
1634 ETL_CONSTANT TElement bitset_common<Active_Bits, TElement>::Top_Mask;
1635 } // namespace private_bitset
1636
1637 //***************************************************************************
1639 //***************************************************************************
1640 template <size_t Active_Bits = 0U, typename TElement = unsigned char>
1641 class bitset;
1642
1643 //***************************************************************************
1645 //***************************************************************************
1646 template <>
1647 class bitset<0U, unsigned char> : public etl::private_bitset::bitset_common<0U, unsigned char>
1648 {
1649 public:
1650
1651 typedef etl::private_bitset::bitset_common<0U, unsigned char>::element_type element_type;
1652 typedef etl::private_bitset::bitset_common<0U, unsigned char>::span_type span_type;
1653 typedef etl::private_bitset::bitset_common< 0U, unsigned char>::const_span_type const_span_type;
1654
1655 using etl::private_bitset::bitset_common<0U, unsigned char>::Bits_Per_Element;
1656 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Set_Element;
1657 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Clear_Element;
1658 using etl::private_bitset::bitset_common<0U, unsigned char>::Number_Of_Elements;
1659 using etl::private_bitset::bitset_common<0U, unsigned char>::Size;
1660 using etl::private_bitset::bitset_common<0U, unsigned char>::Storage_Model;
1661 using etl::private_bitset::bitset_common<0U, unsigned char>::Top_Mask;
1662 using etl::private_bitset::bitset_common<0U, unsigned char>::Allocated_Bits;
1663 };
1664
1665 //*************************************************************************
1667 //*************************************************************************
1668 template <size_t Active_Bits, typename TElement>
1669 class bitset : public etl::private_bitset::bitset_common<Active_Bits, TElement>
1670 {
1671 public:
1672
1673 ETL_STATIC_ASSERT(etl::is_unsigned<TElement>::value, "The element type must be unsigned");
1674
1675 typedef typename etl::private_bitset::bitset_common< Active_Bits, TElement>::element_type element_type;
1676 typedef typename etl::private_bitset::bitset_common< Active_Bits, TElement>::span_type span_type;
1677 typedef typename etl::private_bitset::bitset_common< Active_Bits, TElement>::const_span_type const_span_type;
1678
1679 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Bits_Per_Element;
1680 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Set_Element;
1681 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Clear_Element;
1682 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Number_Of_Elements;
1683 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Size;
1684 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Storage_Model;
1685 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Top_Mask;
1686 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Allocated_Bits;
1687
1688 //*************************************************************************
1690 //*************************************************************************
1692 {
1693 public:
1694
1695 friend class bitset;
1696
1697 //*******************************
1699 //*******************************
1700 ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT
1701 : p_bitset(other.p_bitset)
1702 , position(other.position)
1703 {
1704 }
1705
1706 //*******************************
1708 //*******************************
1709 ETL_CONSTEXPR14 operator bool() const ETL_NOEXCEPT
1710 {
1711 return p_bitset->test(position);
1712 }
1713
1714 //*******************************
1716 //*******************************
1717 ETL_CONSTEXPR14 bit_reference& operator=(bool b) ETL_NOEXCEPT
1718 {
1719 p_bitset->set(position, b);
1720 return *this;
1721 }
1722
1723 //*******************************
1725 //*******************************
1726 ETL_CONSTEXPR14 bit_reference& operator=(const bit_reference& r) ETL_NOEXCEPT
1727 {
1728 p_bitset->set(position, bool(r));
1729 return *this;
1730 }
1731
1732 //*******************************
1734 //*******************************
1735 ETL_CONSTEXPR14 bit_reference& flip() ETL_NOEXCEPT
1736 {
1737 p_bitset->flip(position);
1738 return *this;
1739 }
1740
1741 //*******************************
1743 //*******************************
1744 ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
1745 {
1746 return !p_bitset->test(position);
1747 }
1748
1749 private:
1750
1751 //*******************************
1753 //*******************************
1754 ETL_CONSTEXPR14 bit_reference() ETL_NOEXCEPT
1755 : p_bitset(ETL_NULLPTR)
1756 , position(0)
1757 {
1758 }
1759
1760 //*******************************
1762 //*******************************
1763 ETL_CONSTEXPR14 bit_reference(bitset<Active_Bits, TElement>& r_bitset, size_t position_) ETL_NOEXCEPT
1764 : p_bitset(&r_bitset)
1765 , position(position_)
1766 {
1767 }
1768
1769 bitset<Active_Bits, TElement>* p_bitset;
1770 size_t position;
1771 };
1772
1773 //*************************************************************************
1775 //*************************************************************************
1776 ETL_CONSTEXPR14 bitset() ETL_NOEXCEPT
1777 : buffer()
1778 {
1779 implementation::reset_all(buffer, Number_Of_Elements);
1780 }
1781
1782 //*************************************************************************
1784 //*************************************************************************
1785 ETL_CONSTEXPR14 bitset(const bitset<Active_Bits, TElement>& other) ETL_NOEXCEPT
1786 : buffer()
1787 {
1788 implementation::operator_assignment(buffer, other.buffer, Number_Of_Elements);
1789 }
1790
1791 //*************************************************************************
1793 //*************************************************************************
1794 template <typename TValue>
1795 ETL_CONSTEXPR14 bitset(TValue value, typename etl::enable_if<is_integral<TValue>::value>::type* = 0) ETL_NOEXCEPT
1796 : buffer()
1797 {
1798 implementation::template initialise<element_type>(buffer, Number_Of_Elements, static_cast<unsigned long long>(value));
1799 }
1800
1801 //*************************************************************************
1803 //*************************************************************************
1804 template <typename TPString>
1805 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if<is_same<TPString, const char*>::value>::type* = 0) ETL_NOEXCEPT
1806 : buffer()
1807 {
1808 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1809 }
1810
1811 //*************************************************************************
1813 //*************************************************************************
1814 template <typename TPString>
1815 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if<is_same<TPString, const wchar_t*>::value>::type* = 0) ETL_NOEXCEPT
1816 : buffer()
1817 {
1818 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1819 }
1820
1821 //*************************************************************************
1823 //*************************************************************************
1824 template <typename TPString>
1825 ETL_CONSTEXPR14 bitset(TPString text, typename etl::enable_if< is_same<TPString, const char16_t*>::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 char32_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 ETL_CONSTEXPR14 bitset& operator=(const bitset<Active_Bits, TElement>& other) ETL_NOEXCEPT
1845 {
1846 implementation::operator_assignment(buffer, other.buffer, Number_Of_Elements);
1847
1848 return *this;
1849 }
1850
1851 //*************************************************************************
1853 //*************************************************************************
1854 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& set() ETL_NOEXCEPT
1855 {
1856 implementation::set_all(buffer, Number_Of_Elements, Top_Mask);
1857
1858 return *this;
1859 }
1860
1861 //*************************************************************************
1863 //*************************************************************************
1864 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& set(size_t position, bool value = true)
1865 {
1866 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
1867
1868 implementation::set_position(buffer, position, value);
1869
1870 return *this;
1871 }
1872
1873 //*************************************************************************
1875 //*************************************************************************
1876 template <size_t Position>
1877 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& set(bool value = true)
1878 {
1879 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
1880
1881 implementation::template set_position<Position>(buffer, value);
1882
1883 return *this;
1884 }
1885
1886 //*************************************************************************
1888 //*************************************************************************
1889 template <size_t Position, bool Value>
1891 {
1892 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
1893
1894 implementation::template set_position<Position, Value>(buffer);
1895
1896 return *this;
1897 }
1898
1899 //*************************************************************************
1901 //*************************************************************************
1902 template <typename TPString>
1903 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const char*>::value, bitset<Active_Bits, TElement>&>::type set(TPString text)
1904 ETL_NOEXCEPT
1905 {
1906 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1907
1908 return *this;
1909 }
1910
1911 //*************************************************************************
1913 //*************************************************************************
1914 template <typename TPString>
1915 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const wchar_t*>::value, bitset<Active_Bits, TElement>&>::type set(TPString text)
1916 ETL_NOEXCEPT
1917 {
1918 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1919
1920 return *this;
1921 }
1922
1923 //*************************************************************************
1925 //*************************************************************************
1926 template <typename TPString>
1927 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const char16_t*>::value, bitset<Active_Bits, TElement>&>::type set(TPString text)
1928 ETL_NOEXCEPT
1929 {
1930 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1931
1932 return *this;
1933 }
1934
1935 //*************************************************************************
1937 //*************************************************************************
1938 template <typename TPString>
1939 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const char32_t*>::value, bitset<Active_Bits, TElement>&>::type set(TPString text)
1940 ETL_NOEXCEPT
1941 {
1942 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1943
1944 return *this;
1945 }
1946
1947 //*************************************************************************
1949 //*************************************************************************
1950 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const char* text) ETL_NOEXCEPT
1951 {
1952 implementation::from_string(buffer, Number_Of_Elements, Active_Bits, text);
1953
1954 return *this;
1955 }
1956
1957 //*************************************************************************
1959 //*************************************************************************
1960 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& from_string(const wchar_t* text) 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 char16_t* 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 char32_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 template <typename T>
1991 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_integral<T>::value, T>::type value() const ETL_NOEXCEPT
1992 {
1993 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
1994 ETL_STATIC_ASSERT(etl::integral_limits<T>::bits >= (Number_Of_Elements * Bits_Per_Element), "Type too small");
1995
1996 return implementation::template value<T>(buffer, Number_Of_Elements);
1997 }
1998
1999 //*************************************************************************
2002 //*************************************************************************
2003 template <typename T>
2004 ETL_CONSTEXPR14 T extract(size_t position, size_t length = etl::integral_limits<T>::bits) const
2005 {
2006 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
2007
2008 ETL_ASSERT_OR_RETURN_VALUE(length <= etl::integral_limits<T>::bits, ETL_ERROR(bitset_overflow), 0);
2009 ETL_ASSERT_OR_RETURN_VALUE((position + length) <= Active_Bits, ETL_ERROR(bitset_overflow), 0);
2010
2011 return implementation::template extract<T>(buffer, position, length);
2012 }
2013
2014 //*************************************************************************
2017 //*************************************************************************
2018#if ETL_USING_CPP11
2019 template <typename T, size_t Position, size_t Length = etl::integral_limits<T>::bits>
2020#else
2021 template <typename T, size_t Position, size_t Length>
2022#endif
2023 ETL_CONSTEXPR14 T extract() const
2024 {
2025 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
2026 ETL_STATIC_ASSERT(Length <= etl::integral_limits<T>::bits, "Length is larger that the required type");
2027 ETL_STATIC_ASSERT((Position + Length) <= Active_Bits, "Position/Length overflows bitset");
2028
2029 return implementation::template extract<T, Position, Length>(buffer);
2030 }
2031
2032 //*************************************************************************
2034 //*************************************************************************
2035 unsigned long to_ulong() const
2036 {
2038
2039 return implementation::template value<unsigned long>(buffer, Number_Of_Elements);
2040 }
2041
2042 //*************************************************************************
2044 //*************************************************************************
2045 unsigned long long to_ullong() const
2046 {
2048
2049 return implementation::template value<unsigned long long>(buffer, Number_Of_Elements);
2050 }
2051
2052 //*************************************************************************
2054 //*************************************************************************
2055 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& reset() ETL_NOEXCEPT
2056 {
2057 implementation::reset_all(buffer, Number_Of_Elements);
2058
2059 return *this;
2060 }
2061
2062 //*************************************************************************
2064 //*************************************************************************
2065 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& reset(size_t position)
2066 {
2067 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
2068
2069 implementation::reset_position(buffer, position);
2070
2071 return *this;
2072 }
2073
2074 //*************************************************************************
2078 //*************************************************************************
2079 ETL_CONSTEXPR14 bool test(size_t position) const
2080 {
2081 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), false);
2082
2083 return implementation::test(buffer, position);
2084 }
2085
2086 //*************************************************************************
2089 //*************************************************************************
2090 template <size_t Position>
2091 ETL_CONSTEXPR14 bool test() const
2092 {
2093 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
2094
2095 return implementation::test(buffer, Position);
2096 }
2097
2098 //*************************************************************************
2100 //*************************************************************************
2101 static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
2102 {
2103 return Active_Bits;
2104 }
2105
2106 //*************************************************************************
2108 //*************************************************************************
2109 static ETL_CONSTEXPR size_t number_of_elements() ETL_NOEXCEPT
2110 {
2111 return Number_Of_Elements;
2112 }
2113
2114 //*************************************************************************
2116 //*************************************************************************
2117 static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
2118 {
2119 return All_Set_Element;
2120 }
2121
2122 //*************************************************************************
2124 //*************************************************************************
2125 static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
2126 {
2127 return All_Clear_Element;
2128 }
2129
2130 //*************************************************************************
2132 //*************************************************************************
2133 static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
2134 {
2135 return Bits_Per_Element;
2136 }
2137
2138 //*************************************************************************
2140 //*************************************************************************
2141 static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
2142 {
2143 return Top_Mask;
2144 }
2145
2146 //*************************************************************************
2148 //*************************************************************************
2149 static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
2150 {
2151 return Number_Of_Elements * Bits_Per_Element;
2152 }
2153
2154 //*************************************************************************
2158 //*************************************************************************
2159 static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
2160 {
2161 return Storage_Model;
2162 }
2163
2164 //*************************************************************************
2166 //*************************************************************************
2167 ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
2168 {
2169 return implementation::count(buffer, Number_Of_Elements);
2170 }
2171
2172 //*************************************************************************
2173 // Are all the bits sets?
2174 //*************************************************************************
2175 ETL_CONSTEXPR14 bool all() const ETL_NOEXCEPT
2176 {
2177 return implementation::all(buffer, Number_Of_Elements, Top_Mask);
2178 }
2179
2180 //*************************************************************************
2181 // Are all the mask bits sets?
2182 //*************************************************************************
2183 ETL_CONSTEXPR14 bool all(element_type mask) const ETL_NOEXCEPT
2184 {
2185 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
2186
2187 return implementation::all(buffer, Number_Of_Elements, Top_Mask, mask);
2188 }
2189
2190 //*************************************************************************
2192 //*************************************************************************
2193 ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
2194 {
2195 return implementation::none(buffer, Number_Of_Elements);
2196 }
2197
2198 //*************************************************************************
2200 //*************************************************************************
2201 ETL_CONSTEXPR14 bool none(element_type mask) const ETL_NOEXCEPT
2202 {
2203 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
2204
2205 return implementation::none(buffer, Number_Of_Elements, mask);
2206 }
2207
2208 //*************************************************************************
2210 //*************************************************************************
2211 ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
2212 {
2213 return implementation::any(buffer, Number_Of_Elements);
2214 }
2215
2216 //*************************************************************************
2218 //*************************************************************************
2219 ETL_CONSTEXPR14 bool any(element_type mask) const ETL_NOEXCEPT
2220 {
2221 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
2222
2223 return implementation::any(buffer, Number_Of_Elements, mask);
2224 }
2225
2226 //*************************************************************************
2228 //*************************************************************************
2229 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& flip() ETL_NOEXCEPT
2230 {
2231 implementation::flip_all(buffer, Number_Of_Elements);
2232
2233 return *this;
2234 }
2235
2236 //*************************************************************************
2238 //*************************************************************************
2239 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& flip(size_t position)
2240 {
2241 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
2242
2243 implementation::flip_position(buffer, position);
2244
2245 return *this;
2246 }
2247
2248 //*************************************************************************
2250 //*************************************************************************
2251 ETL_CONSTEXPR14 bool operator[](size_t position) const ETL_NOEXCEPT
2252 {
2253 return implementation::test(buffer, position);
2254 }
2255
2256 //*************************************************************************
2258 //*************************************************************************
2259 ETL_CONSTEXPR14 bit_reference operator[](size_t position) ETL_NOEXCEPT
2260 {
2261 return bit_reference(*this, position);
2262 }
2263
2264 //*************************************************************************
2266 //*************************************************************************
2267#if ETL_USING_CPP11
2268 template <typename TString = etl::string<Active_Bits>>
2269#else
2270 template <typename TString>
2271#endif
2272 ETL_CONSTEXPR14 TString to_string(typename TString::value_type zero = typename TString::value_type('0'),
2273 typename TString::value_type one = typename TString::value_type('1')) const
2274 {
2275 return implementation::template to_string<TString>(buffer, Active_Bits, zero, one);
2276 }
2277
2278 //*************************************************************************
2282 //*************************************************************************
2283 ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
2284 {
2285 return implementation::find_next(buffer, Number_Of_Elements, Active_Bits, state, 0);
2286 }
2287
2288 //*************************************************************************
2293 //*************************************************************************
2294 ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
2295 {
2296 return implementation::find_next(buffer, Number_Of_Elements, Active_Bits, state, position);
2297 }
2298
2299 //*************************************************************************
2301 //*************************************************************************
2302 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator&(const bitset<Active_Bits, TElement>& other) const ETL_NOEXCEPT
2303 {
2305
2306 implementation::operator_and(temp.buffer, other.buffer, Number_Of_Elements);
2307
2308 return temp;
2309 }
2310
2311 //*************************************************************************
2313 //*************************************************************************
2315 {
2316 implementation::operator_and(buffer, other.buffer, Number_Of_Elements);
2317
2318 return *this;
2319 }
2320
2321 //*************************************************************************
2323 //*************************************************************************
2324 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator|(const bitset<Active_Bits, TElement>& other) const ETL_NOEXCEPT
2325 {
2327
2328 implementation::operator_or(temp.buffer, other.buffer, Number_Of_Elements);
2329
2330 return temp;
2331 }
2332
2333 //*************************************************************************
2335 //*************************************************************************
2337 {
2338 implementation::operator_or(&buffer[0], &other.buffer[0], Number_Of_Elements);
2339
2340 return *this;
2341 }
2342
2343 //*************************************************************************
2345 //*************************************************************************
2346 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator^(const bitset<Active_Bits, TElement>& other) const ETL_NOEXCEPT
2347 {
2349
2350 implementation::operator_xor(temp.buffer, other.buffer, Number_Of_Elements);
2351
2352 return temp;
2353 }
2354
2355 //*************************************************************************
2357 //*************************************************************************
2359 {
2360 implementation::operator_xor(buffer, other.buffer, Number_Of_Elements);
2361
2362 return *this;
2363 }
2364
2365 //*************************************************************************
2367 //*************************************************************************
2368 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator~() const ETL_NOEXCEPT
2369 {
2371
2372 implementation::flip_all(temp.buffer, Number_Of_Elements);
2373
2374 return temp;
2375 }
2376
2377 //*************************************************************************
2379 //*************************************************************************
2380 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator<<(size_t shift) const ETL_NOEXCEPT
2381 {
2383
2384 implementation::operator_shift_left(temp.buffer, Number_Of_Elements, Active_Bits, shift);
2385
2386 return temp;
2387 }
2388
2389 //*************************************************************************
2391 //*************************************************************************
2392 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& operator<<=(size_t shift) ETL_NOEXCEPT
2393 {
2394 if (shift >= Active_Bits)
2395 {
2396 implementation::reset_all(buffer, Number_Of_Elements);
2397 }
2398 else
2399 {
2400 implementation::operator_shift_left(buffer, Number_Of_Elements, Active_Bits, shift);
2401 }
2402
2403 return *this;
2404 }
2405
2406 //*************************************************************************
2408 //*************************************************************************
2409 ETL_CONSTEXPR14 bitset<Active_Bits, TElement> operator>>(size_t shift) const ETL_NOEXCEPT
2410 {
2412
2413 implementation::operator_shift_right(temp.buffer, Number_Of_Elements, Active_Bits, shift);
2414
2415 return temp;
2416 }
2417
2418 //*************************************************************************
2420 //*************************************************************************
2421 ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& operator>>=(size_t shift) ETL_NOEXCEPT
2422 {
2423 if (shift >= Active_Bits)
2424 {
2425 implementation::reset_all(buffer, Number_Of_Elements);
2426 }
2427 else
2428 {
2429 implementation::operator_shift_right(buffer, Number_Of_Elements, Active_Bits, shift);
2430 }
2431
2432 return *this;
2433 }
2434
2435 //*************************************************************************
2437 //*************************************************************************
2438 friend ETL_CONSTEXPR14 bool operator==(const bitset<Active_Bits, TElement>& lhs, const bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2439 {
2440 return implementation::operator_equality(lhs.buffer, rhs.buffer, lhs.Number_Of_Elements);
2441 }
2442
2443 //*************************************************************************
2445 //*************************************************************************
2446 friend ETL_CONSTEXPR14 bool operator!=(const bitset<Active_Bits, TElement>& lhs, const bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2447 {
2448 return !(lhs == rhs);
2449 }
2450
2451 //*************************************************************************
2453 //*************************************************************************
2454 ETL_CONSTEXPR14 void swap(etl::bitset<Active_Bits, TElement>& other) ETL_NOEXCEPT
2455 {
2456 implementation::swap(buffer, other.buffer, Number_Of_Elements);
2457 }
2458
2459 //*************************************************************************
2462 //*************************************************************************
2463 ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
2464 {
2465 return span_type(buffer, Number_Of_Elements);
2466 }
2467
2468 //*************************************************************************
2471 //*************************************************************************
2472 ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
2473 {
2474 return const_span_type(buffer, Number_Of_Elements);
2475 }
2476
2477 private:
2478
2479 // The implementation of the bitset functionality.
2480 typedef etl::bitset_impl<element_type, (Number_Of_Elements == 1U) ? etl::bitset_storage_model::Single : etl::bitset_storage_model::Multi>
2481 implementation;
2482
2483 // The storage for the bitset.
2484 element_type buffer[Number_Of_Elements];
2485 };
2486
2487 //***************************************************************************
2490 //***************************************************************************
2491 template <size_t Active_Bits, typename TElement>
2493 {
2494 bitset<Active_Bits> temp(lhs);
2495 temp &= rhs;
2496 return temp;
2497 }
2498
2499 //***************************************************************************
2502 //***************************************************************************
2503 template <size_t Active_Bits, typename TElement>
2505 {
2506 bitset<Active_Bits> temp(lhs);
2507 temp |= rhs;
2508 return temp;
2509 }
2510
2511 //***************************************************************************
2514 //***************************************************************************
2515 template <size_t Active_Bits, typename TElement>
2517 {
2518 bitset<Active_Bits> temp(lhs);
2519 temp ^= rhs;
2520 return temp;
2521 }
2522} // namespace etl
2523
2524//***************************************************************************
2527//***************************************************************************
2528template <size_t Active_Bits, typename TElement>
2529ETL_CONSTEXPR14 bool operator!=(const etl::bitset<Active_Bits, TElement>& lhs, const etl::bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
2530{
2531 return !(lhs == rhs);
2532}
2533
2534//*************************************************************************
2536//*************************************************************************
2537template <size_t Active_Bits, typename TElement>
2539{
2540 lhs.swap(rhs);
2541}
2542
2543//***************************************************************************
2545//***************************************************************************
2546namespace etl
2547{
2548 //***************************************************************************
2549 template <size_t Active_Bits = 0U, typename TElement = unsigned char>
2550 class bitset_ext;
2551
2552 //***************************************************************************
2554 //***************************************************************************
2555 template <>
2556 class bitset_ext<0U, unsigned char> : public etl::private_bitset::bitset_common<0U, unsigned char>
2557 {
2558 public:
2559
2560 typedef size_t size_type;
2561
2562 typedef etl::private_bitset::bitset_common<0U, unsigned char>::element_type element_type;
2563 typedef etl::private_bitset::bitset_common<0U, unsigned char>::span_type span_type;
2564 typedef etl::private_bitset::bitset_common< 0U, unsigned char>::const_span_type const_span_type;
2565
2566 using etl::private_bitset::bitset_common<0U, unsigned char>::Bits_Per_Element;
2567 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Set_Element;
2568 using etl::private_bitset::bitset_common<0U, unsigned char>::All_Clear_Element;
2569 using etl::private_bitset::bitset_common<0U, unsigned char>::Number_Of_Elements;
2570 using etl::private_bitset::bitset_common<0U, unsigned char>::Size;
2571 using etl::private_bitset::bitset_common<0U, unsigned char>::Storage_Model;
2572 using etl::private_bitset::bitset_common<0U, unsigned char>::Top_Mask;
2573 using etl::private_bitset::bitset_common<0U, unsigned char>::Allocated_Bits;
2574 };
2575
2576 //*************************************************************************
2578 //*************************************************************************
2579 template <size_t Active_Bits, typename TElement>
2580 class bitset_ext : public etl::private_bitset::bitset_common<Active_Bits, TElement>
2581 {
2582 public:
2583
2584 ETL_STATIC_ASSERT(etl::is_unsigned<TElement>::value, "The element type must be unsigned");
2585
2586 typedef size_t size_type;
2587
2588 typedef typename etl::private_bitset::bitset_common< Active_Bits, TElement>::element_type element_type;
2589 typedef typename etl::private_bitset::bitset_common< Active_Bits, TElement>::span_type span_type;
2590 typedef typename etl::private_bitset::bitset_common< Active_Bits, TElement>::const_span_type const_span_type;
2591
2592 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Bits_Per_Element;
2593 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Set_Element;
2594 using etl::private_bitset::bitset_common<Active_Bits, TElement>::All_Clear_Element;
2595 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Number_Of_Elements;
2596 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Size;
2597 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Storage_Model;
2598 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Top_Mask;
2599 using etl::private_bitset::bitset_common<Active_Bits, TElement>::Allocated_Bits;
2600
2601 typedef etl::array<TElement, Number_Of_Elements> buffer_type;
2602
2603 //*************************************************************************
2605 //*************************************************************************
2607 {
2608 public:
2609
2610 friend class bitset_ext;
2611
2612 //*******************************
2614 //*******************************
2615 ETL_CONSTEXPR14 bit_reference(const bit_reference& other) ETL_NOEXCEPT
2616 : p_bitset(other.p_bitset)
2617 , position(other.position)
2618 {
2619 }
2620
2621 //*******************************
2623 //*******************************
2624 ETL_CONSTEXPR14 operator bool() const ETL_NOEXCEPT
2625 {
2626 return p_bitset->test(position);
2627 }
2628
2629 //*******************************
2631 //*******************************
2632 ETL_CONSTEXPR14 bit_reference& operator=(bool b) ETL_NOEXCEPT
2633 {
2634 p_bitset->set(position, b);
2635 return *this;
2636 }
2637
2638 //*******************************
2640 //*******************************
2641 ETL_CONSTEXPR14 bit_reference& operator=(const bit_reference& r) ETL_NOEXCEPT
2642 {
2643 p_bitset->set(position, bool(r));
2644 return *this;
2645 }
2646
2647 //*******************************
2649 //*******************************
2650 ETL_CONSTEXPR14 bit_reference& flip() ETL_NOEXCEPT
2651 {
2652 p_bitset->flip(position);
2653 return *this;
2654 }
2655
2656 //*******************************
2658 //*******************************
2659 ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
2660 {
2661 return !p_bitset->test(position);
2662 }
2663
2664 private:
2665
2666 //*******************************
2668 //*******************************
2669 ETL_CONSTEXPR14 bit_reference() ETL_NOEXCEPT
2670 : p_bitset(ETL_NULLPTR)
2671 , position(0)
2672 {
2673 }
2674
2675 //*******************************
2677 //*******************************
2678 ETL_CONSTEXPR14 bit_reference(bitset_ext<Active_Bits, TElement>& r_bitset, size_t position_) ETL_NOEXCEPT
2679 : p_bitset(&r_bitset)
2680 , position(position_)
2681 {
2682 }
2683
2684 bitset_ext<Active_Bits, TElement>* p_bitset;
2685 size_t position;
2686 };
2687
2688 //*************************************************************************
2690 //*************************************************************************
2691 ETL_CONSTEXPR14 explicit bitset_ext(element_type* pbuffer_)
2692 : pbuffer(pbuffer_)
2693 {
2694 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2695 implementation::reset_all(pbuffer, Number_Of_Elements);
2696 }
2697
2698 //*************************************************************************
2700 //*************************************************************************
2701 ETL_CONSTEXPR14 explicit bitset_ext(buffer_type& buffer)
2702 : pbuffer(buffer.data())
2703 {
2704 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2705 implementation::reset_all(pbuffer, Number_Of_Elements);
2706 }
2707
2708 //*************************************************************************
2710 //*************************************************************************
2711 ETL_CONSTEXPR14 bitset_ext(const bitset_ext<Active_Bits, TElement>& other, element_type* pbuffer_)
2712 : pbuffer(pbuffer_)
2713 {
2714 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2715 implementation::operator_assignment(pbuffer, other.pbuffer, Number_Of_Elements);
2716 }
2717
2718 //*************************************************************************
2720 //*************************************************************************
2721 ETL_CONSTEXPR14 bitset_ext(const bitset_ext<Active_Bits, TElement>& other, buffer_type& buffer) ETL_NOEXCEPT
2722 : pbuffer(buffer.data())
2723 {
2724 implementation::operator_assignment(pbuffer, other.pbuffer, Number_Of_Elements);
2725 }
2726
2727 //*************************************************************************
2729 //*************************************************************************
2730 ETL_CONSTEXPR14 bitset_ext(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT ETL_DELETE;
2731
2732 //*************************************************************************
2734 //*************************************************************************
2735 ETL_CONSTEXPR14 bitset_ext(unsigned long long value, element_type* pbuffer_)
2736 : pbuffer(pbuffer_)
2737 {
2738 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2739 implementation::template initialise<element_type>(pbuffer, Number_Of_Elements, value);
2740 }
2741
2742 //*************************************************************************
2744 //*************************************************************************
2745 template <typename TValue>
2746 ETL_CONSTEXPR14 bitset_ext(TValue value, buffer_type& buffer, typename etl::enable_if<is_integral<TValue>::value>::type* = 0) ETL_NOEXCEPT
2747 : pbuffer(buffer.data())
2748 {
2749 implementation::template initialise<element_type>(pbuffer, Number_Of_Elements, static_cast<unsigned long long>(value));
2750 }
2751
2752 //*************************************************************************
2754 //*************************************************************************
2755 template <typename TPString>
2756 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if<is_same<TPString, const char*>::value>::type* = 0)
2757 : pbuffer(pbuffer_)
2758 {
2759 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2760 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2761 }
2762
2763 //*************************************************************************
2765 //*************************************************************************
2766 template <typename TPString>
2767 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if<is_same<TPString, const char*>::value>::type* = 0)
2768 ETL_NOEXCEPT
2769 : pbuffer(buffer.data())
2770 {
2771 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2772 }
2773
2774 //*************************************************************************
2776 //*************************************************************************
2777 template <typename TPString>
2778 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if<is_same<TPString, const wchar_t*>::value>::type* = 0)
2779 : pbuffer(pbuffer_)
2780 {
2781 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2782 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2783 }
2784
2785 //*************************************************************************
2787 //*************************************************************************
2788 template <typename TPString>
2789 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if<is_same<TPString, const wchar_t*>::value>::type* = 0)
2790 ETL_NOEXCEPT
2791 : pbuffer(buffer.data())
2792 {
2793 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2794 }
2795
2796 //*************************************************************************
2798 //*************************************************************************
2799 template <typename TPString>
2800 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if< is_same<TPString, const char16_t*>::value>::type* = 0)
2801 : pbuffer(pbuffer_)
2802 {
2803 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2804 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2805 }
2806
2807 //*************************************************************************
2809 //*************************************************************************
2810 template <typename TPString>
2811 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if< is_same<TPString, const char16_t*>::value>::type* = 0)
2812 ETL_NOEXCEPT
2813 : pbuffer(buffer.data())
2814 {
2815 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2816 }
2817
2818 //*************************************************************************
2820 //*************************************************************************
2821 template <typename TPString>
2822 ETL_CONSTEXPR14 bitset_ext(TPString text, element_type* pbuffer_, typename etl::enable_if< is_same<TPString, const char32_t*>::value>::type* = 0)
2823 : pbuffer(pbuffer_)
2824 {
2825 ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
2826 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2827 }
2828
2829 //*************************************************************************
2831 //*************************************************************************
2832 template <typename TPString>
2833 ETL_CONSTEXPR14 bitset_ext(TPString text, buffer_type& buffer, typename etl::enable_if< is_same<TPString, const char32_t*>::value>::type* = 0)
2834 ETL_NOEXCEPT
2835 : pbuffer(buffer.data())
2836 {
2837 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2838 }
2839
2840 //*************************************************************************
2842 //*************************************************************************
2843 ETL_CONSTEXPR14 bitset_ext& operator=(const bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
2844 {
2845 implementation::operator_assignment(pbuffer, other.pbuffer, Number_Of_Elements);
2846
2847 return *this;
2848 }
2849
2850 //*************************************************************************
2852 //*************************************************************************
2853 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& set() ETL_NOEXCEPT
2854 {
2855 implementation::set_all(pbuffer, Number_Of_Elements, Top_Mask);
2856
2857 return *this;
2858 }
2859
2860 //*************************************************************************
2862 //*************************************************************************
2863 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& set(size_t position, bool value = true)
2864 {
2865 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
2866
2867 implementation::set_position(pbuffer, position, value);
2868
2869 return *this;
2870 }
2871
2872 //*************************************************************************
2874 //*************************************************************************
2875 template <size_t Position>
2876 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& set(bool value = true)
2877 {
2878 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
2879
2880 implementation::template set_position<Position>(pbuffer, value);
2881
2882 return *this;
2883 }
2884
2885 //*************************************************************************
2887 //*************************************************************************
2888 template <size_t Position, bool Value>
2890 {
2891 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
2892
2893 implementation::template set_position<Position, Value>(pbuffer);
2894
2895 return *this;
2896 }
2897
2898 //*************************************************************************
2900 //*************************************************************************
2901 template <typename TPString>
2902 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const char*>::value, bitset_ext<Active_Bits, TElement>&>::type set(TPString text)
2903 ETL_NOEXCEPT
2904 {
2905 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2906
2907 return *this;
2908 }
2909
2910 //*************************************************************************
2912 //*************************************************************************
2913 template <typename TPString>
2914 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const wchar_t*>::value, bitset_ext<Active_Bits, TElement>&>::type
2915 set(TPString text) ETL_NOEXCEPT
2916 {
2917 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2918
2919 return *this;
2920 }
2921
2922 //*************************************************************************
2924 //*************************************************************************
2925 template <typename TPString>
2926 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const char16_t*>::value, bitset_ext<Active_Bits, TElement>&>::type
2927 set(TPString text) ETL_NOEXCEPT
2928 {
2929 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2930
2931 return *this;
2932 }
2933
2934 //*************************************************************************
2936 //*************************************************************************
2937 template <typename TPString>
2938 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_same<TPString, const char32_t*>::value, bitset_ext<Active_Bits, TElement>&>::type
2939 set(TPString text) ETL_NOEXCEPT
2940 {
2941 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2942
2943 return *this;
2944 }
2945
2946 //*************************************************************************
2948 //*************************************************************************
2949 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const char* text) ETL_NOEXCEPT
2950 {
2951 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2952
2953 return *this;
2954 }
2955
2956 //*************************************************************************
2958 //*************************************************************************
2959 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const wchar_t* text) ETL_NOEXCEPT
2960 {
2961 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2962
2963 return *this;
2964 }
2965
2966 //*************************************************************************
2968 //*************************************************************************
2969 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const char16_t* text) ETL_NOEXCEPT
2970 {
2971 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2972
2973 return *this;
2974 }
2975
2976 //*************************************************************************
2978 //*************************************************************************
2979 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& from_string(const char32_t* text) ETL_NOEXCEPT
2980 {
2981 implementation::from_string(pbuffer, Number_Of_Elements, Active_Bits, text);
2982
2983 return *this;
2984 }
2985
2986 //*************************************************************************
2988 //*************************************************************************
2989 template <typename T>
2990 ETL_CONSTEXPR14 T value() const ETL_NOEXCEPT
2991 {
2992 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
2993 ETL_STATIC_ASSERT(etl::integral_limits<T>::bits >= (Number_Of_Elements * Bits_Per_Element), "Type too small");
2994
2995 return implementation::template value<T>(pbuffer, Number_Of_Elements);
2996 }
2997
2998 //*************************************************************************
3001 //*************************************************************************
3002 template <typename T>
3003 ETL_CONSTEXPR14 T extract(size_t position, size_t length = etl::integral_limits<T>::bits)
3004 {
3005 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
3006
3007 ETL_ASSERT_OR_RETURN_VALUE(length <= etl::integral_limits<T>::bits, ETL_ERROR(bitset_overflow), 0);
3008 ETL_ASSERT_OR_RETURN_VALUE((position + length) <= Active_Bits, ETL_ERROR(bitset_overflow), 0);
3009
3010 return implementation::template extract<T>(pbuffer, position, length);
3011 }
3012
3013 //*************************************************************************
3016 //*************************************************************************
3017#if ETL_USING_CPP11
3018 template <typename T, size_t Position, size_t Length = etl::integral_limits<T>::bits>
3019#else
3020 template <typename T, size_t Position, size_t Length>
3021#endif
3022 ETL_CONSTEXPR14 T extract() const
3023 {
3024 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Only integral types are supported");
3025 ETL_STATIC_ASSERT(Length <= etl::integral_limits<T>::bits, "Length is larger that the required type");
3026 ETL_STATIC_ASSERT((Position + Length) <= Active_Bits, "Position/Length overflows bitset");
3027
3028 return implementation::template extract<T, Position, Length>(pbuffer);
3029 }
3030
3031 //*************************************************************************
3033 //*************************************************************************
3034 unsigned long to_ulong() const
3035 {
3037
3038 return implementation::template value<unsigned long>(pbuffer, Number_Of_Elements);
3039 }
3040
3041 //*************************************************************************
3043 //*************************************************************************
3044 unsigned long long to_ullong() const
3045 {
3047
3048 return implementation::template value<unsigned long long>(pbuffer, Number_Of_Elements);
3049 }
3050
3051 //*************************************************************************
3053 //*************************************************************************
3054 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& reset() ETL_NOEXCEPT
3055 {
3056 implementation::reset_all(pbuffer, Number_Of_Elements);
3057
3058 return *this;
3059 }
3060
3061 //*************************************************************************
3063 //*************************************************************************
3064 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& reset(size_t position)
3065 {
3066 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
3067
3068 implementation::reset_position(pbuffer, position);
3069
3070 return *this;
3071 }
3072
3073 //*************************************************************************
3077 //*************************************************************************
3078 ETL_CONSTEXPR14 bool test(size_t position) const
3079 {
3080 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), false);
3081
3082 return implementation::test(pbuffer, position);
3083 }
3084
3085 //*************************************************************************
3088 //*************************************************************************
3089 template <size_t Position>
3090 ETL_CONSTEXPR14 bool test() const
3091 {
3092 ETL_STATIC_ASSERT(Position < Active_Bits, "Position out of bounds");
3093
3094 return implementation::test(pbuffer, Position);
3095 }
3096
3097 //*************************************************************************
3099 //*************************************************************************
3100 static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
3101 {
3102 return Active_Bits;
3103 }
3104
3105 //*************************************************************************
3107 //*************************************************************************
3108 static ETL_CONSTEXPR size_t number_of_elements() ETL_NOEXCEPT
3109 {
3110 return Number_Of_Elements;
3111 }
3112
3113 //*************************************************************************
3115 //*************************************************************************
3116 static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
3117 {
3118 return All_Set_Element;
3119 }
3120
3121 //*************************************************************************
3123 //*************************************************************************
3124 static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
3125 {
3126 return All_Clear_Element;
3127 }
3128
3129 //*************************************************************************
3131 //*************************************************************************
3132 static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
3133 {
3134 return Top_Mask;
3135 }
3136
3137 //*************************************************************************
3139 //*************************************************************************
3140 static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
3141 {
3142 return Bits_Per_Element;
3143 }
3144
3145 //*************************************************************************
3147 //*************************************************************************
3148 static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
3149 {
3150 return Number_Of_Elements * Bits_Per_Element;
3151 }
3152
3153 //*************************************************************************
3157 //*************************************************************************
3158 static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
3159 {
3160 return Storage_Model;
3161 }
3162
3163 //*************************************************************************
3165 //*************************************************************************
3166 ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
3167 {
3168 return implementation::count(pbuffer, Number_Of_Elements);
3169 }
3170
3171 //*************************************************************************
3172 // Are all the bits sets?
3173 //*************************************************************************
3174 ETL_CONSTEXPR14 bool all() const ETL_NOEXCEPT
3175 {
3176 return implementation::all(pbuffer, Number_Of_Elements, Top_Mask);
3177 }
3178
3179 //*************************************************************************
3180 // Are all the mask bits sets?
3181 //*************************************************************************
3182 ETL_CONSTEXPR14 bool all(element_type mask) const ETL_NOEXCEPT
3183 {
3184 ETL_STATIC_ASSERT(Storage_Model == etl::bitset_storage_model::Single, "Not supported for 'Multi' bitset storage model");
3185
3186 return implementation::all(pbuffer, Number_Of_Elements, Top_Mask, mask);
3187 }
3188
3189 //*************************************************************************
3191 //*************************************************************************
3192 ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
3193 {
3194 return implementation::none(pbuffer, Number_Of_Elements);
3195 }
3196
3197 //*************************************************************************
3199 //*************************************************************************
3200 ETL_CONSTEXPR14 bool none(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::none(pbuffer, Number_Of_Elements, mask);
3205 }
3206
3207 //*************************************************************************
3209 //*************************************************************************
3210 ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
3211 {
3212 return implementation::any(pbuffer, Number_Of_Elements);
3213 }
3214
3215 //*************************************************************************
3217 //*************************************************************************
3218 ETL_CONSTEXPR14 bool any(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::any(pbuffer, Number_Of_Elements, mask);
3223 }
3224
3225 //*************************************************************************
3227 //*************************************************************************
3228 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& flip() ETL_NOEXCEPT
3229 {
3230 implementation::flip_all(pbuffer, Number_Of_Elements);
3231
3232 return *this;
3233 }
3234
3235 //*************************************************************************
3237 //*************************************************************************
3238 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& flip(size_t position)
3239 {
3240 ETL_ASSERT_OR_RETURN_VALUE(position < Active_Bits, ETL_ERROR(bitset_overflow), *this);
3241
3242 implementation::flip_position(pbuffer, position);
3243
3244 return *this;
3245 }
3246
3247 //*************************************************************************
3249 //*************************************************************************
3250 ETL_CONSTEXPR14 bool operator[](size_t position) const ETL_NOEXCEPT
3251 {
3252 return implementation::test(pbuffer, position);
3253 }
3254
3255 //*************************************************************************
3257 //*************************************************************************
3258 ETL_CONSTEXPR14 bit_reference operator[](size_t position) ETL_NOEXCEPT
3259 {
3260 return bit_reference(*this, position);
3261 }
3262
3263 //*************************************************************************
3265 //*************************************************************************
3266#if ETL_USING_CPP11
3267 template <typename TString = etl::string<Active_Bits>>
3268#else
3269 template <typename TString>
3270#endif
3271 ETL_CONSTEXPR14 TString to_string(typename TString::value_type zero = typename TString::value_type('0'),
3272 typename TString::value_type one = typename TString::value_type('1')) const
3273 {
3274 return implementation::template to_string<TString>(pbuffer, Active_Bits, zero, one);
3275 }
3276
3277 //*************************************************************************
3281 //*************************************************************************
3282 ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
3283 {
3284 return implementation::find_next(pbuffer, Number_Of_Elements, Active_Bits, state, 0);
3285 }
3286
3287 //*************************************************************************
3292 //*************************************************************************
3293 ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
3294 {
3295 return implementation::find_next(pbuffer, Number_Of_Elements, Active_Bits, state, position);
3296 }
3297
3298 //*************************************************************************
3300 //*************************************************************************
3302 {
3303 implementation::operator_and(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3304
3305 return *this;
3306 }
3307
3308 //*************************************************************************
3310 //*************************************************************************
3312 {
3313 implementation::operator_or(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3314
3315 return *this;
3316 }
3317
3318 //*************************************************************************
3320 //*************************************************************************
3322 {
3323 implementation::operator_xor(&pbuffer[0], &other.pbuffer[0], Number_Of_Elements);
3324
3325 return *this;
3326 }
3327
3328 //*************************************************************************
3330 //*************************************************************************
3331 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator<<=(size_t shift) ETL_NOEXCEPT
3332 {
3333 implementation::operator_shift_left(pbuffer, Number_Of_Elements, Active_Bits, shift);
3334
3335 return *this;
3336 }
3337
3338 //*************************************************************************
3340 //*************************************************************************
3341 ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator>>=(size_t shift) ETL_NOEXCEPT
3342 {
3343 implementation::operator_shift_right(pbuffer, Number_Of_Elements, Active_Bits, shift);
3344
3345 return *this;
3346 }
3347
3348 //*************************************************************************
3350 //*************************************************************************
3351 friend ETL_CONSTEXPR14 bool operator==(const bitset_ext<Active_Bits, TElement>& lhs, const bitset_ext<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3352 {
3353 return implementation::operator_equality(lhs.pbuffer, rhs.pbuffer, lhs.Number_Of_Elements);
3354 }
3355
3356 //*************************************************************************
3358 //*************************************************************************
3359 friend ETL_CONSTEXPR14 bool operator!=(const bitset_ext<Active_Bits, TElement>& lhs, const bitset_ext<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3360 {
3361 return !(lhs == rhs);
3362 }
3363
3364 //*************************************************************************
3366 //*************************************************************************
3367 ETL_CONSTEXPR14 void swap(etl::bitset_ext<Active_Bits, TElement>& other) ETL_NOEXCEPT
3368 {
3369 implementation::swap(pbuffer, other.pbuffer, Number_Of_Elements);
3370 }
3371
3372 //*************************************************************************
3375 //*************************************************************************
3376 ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
3377 {
3378 return span_type(pbuffer, Number_Of_Elements);
3379 }
3380
3381 //*************************************************************************
3384 //*************************************************************************
3385 ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
3386 {
3387 return const_span_type(pbuffer, Number_Of_Elements);
3388 }
3389
3390 private:
3391
3392 // The implementation of the bitset functionality.
3393 typedef etl::bitset_impl<element_type, (Number_Of_Elements == 1U) ? etl::bitset_storage_model::Single : etl::bitset_storage_model::Multi>
3394 implementation;
3395
3396 // Pointer to the storage for the bitset.
3397 element_type* pbuffer;
3398 };
3399} // namespace etl
3400
3401//***************************************************************************
3404//***************************************************************************
3405template <size_t Active_Bits, typename TElement>
3407{
3408 return !(lhs == rhs);
3409}
3410
3411//*************************************************************************
3413//*************************************************************************
3414template <size_t Active_Bits, typename TElement>
3416{
3417 lhs.swap(rhs);
3418}
3419
3420namespace etl
3421{
3422 namespace private_bitset
3423 {
3424 //*************************************************************************
3427 //*************************************************************************
3428 template <typename TLhsSpan, typename TRhsSpan>
3429 bool compare_bitset_spans(const TLhsSpan& lhs_span, const TRhsSpan& rhs_span)
3430 {
3431 typedef typename TLhsSpan::value_type lhs_element_t;
3432 typedef typename TRhsSpan::value_type rhs_element_t;
3433
3434 const int steps = static_cast<int>(sizeof(lhs_element_t) / sizeof(rhs_element_t));
3435
3436 typename TLhsSpan::iterator lhs_itr = lhs_span.begin();
3437 typename TRhsSpan::iterator rhs_itr = rhs_span.begin();
3438
3439 while (lhs_itr != lhs_span.end())
3440 {
3441 const lhs_element_t& lhs_value = *lhs_itr;
3442
3443 // Build the rhs element in terms of the lhs element type.
3444 lhs_element_t rhs_value = 0;
3445
3446 const int shift_step = etl::integral_limits<rhs_element_t>::bits;
3447 int shift = 0;
3448
3449 for (int i = 0; i < steps; ++i)
3450 {
3451 rhs_value |= (static_cast<lhs_element_t>(*rhs_itr) << shift);
3452 ++rhs_itr;
3453 shift += shift_step;
3454 }
3455
3456 if (lhs_value != rhs_value)
3457 {
3458 return false;
3459 }
3460
3461 ++lhs_itr;
3462 }
3463
3464 return true;
3465 }
3466 } // namespace private_bitset
3467} // namespace etl
3468
3469//***************************************************************************
3474//***************************************************************************
3475template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3476ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3478{
3479 // Get a span of each type.
3480 typename etl::bitset<Active_Bits, TLhsElement>::const_span_type lhs_span = lhs.span();
3481 typename etl::bitset<Active_Bits, TRhsElement>::const_span_type rhs_span = rhs.span();
3482
3483 // Put the bitset with the largest element type as the first argument.
3484 if ETL_IF_CONSTEXPR (sizeof(TLhsElement) > sizeof(TRhsElement))
3485 {
3486 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3487 }
3488 else
3489 {
3490 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3491 }
3492}
3493
3494//***************************************************************************
3499//***************************************************************************
3500template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3501ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3503{
3504 return !(lhs == rhs);
3505}
3506
3507//***************************************************************************
3512//***************************************************************************
3513template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3514ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3516{
3517 // Get a span of each type.
3518 typename etl::bitset_ext<Active_Bits, TLhsElement>::const_span_type lhs_span = lhs.span();
3519 typename etl::bitset_ext<Active_Bits, TRhsElement>::const_span_type rhs_span = rhs.span();
3520
3521 // Put the bitset with the largest element type as the first argument.
3522 if ETL_IF_CONSTEXPR (sizeof(TLhsElement) > sizeof(TRhsElement))
3523 {
3524 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3525 }
3526 else
3527 {
3528 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3529 }
3530}
3531
3532//***************************************************************************
3537//***************************************************************************
3538template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3539ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3541{
3542 return !(lhs == rhs);
3543}
3544
3545//***************************************************************************
3549//***************************************************************************
3550template <size_t Active_Bits, typename TElement>
3551ETL_CONSTEXPR14 bool operator==(const etl::bitset<Active_Bits, TElement>& lhs, const etl::bitset_ext<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3552{
3553 const char Storage_Model = etl::bitset<Active_Bits, TElement>::Storage_Model;
3554 const size_t Number_Of_Elements = etl::bitset<Active_Bits, TElement>::Number_Of_Elements;
3555
3556 typename etl::bitset<Active_Bits, TElement>::const_span_type lhs_span = lhs.span();
3557 typename etl::bitset_ext<Active_Bits, TElement>::const_span_type rhs_span = rhs.span();
3558
3559 typedef etl::bitset_impl<TElement, Storage_Model> implementation;
3560
3561 return implementation::operator_equality(lhs_span.begin(), rhs_span.begin(), Number_Of_Elements);
3562}
3563
3564//***************************************************************************
3568//***************************************************************************
3569template <size_t Active_Bits, typename TElement>
3570ETL_CONSTEXPR14 bool operator!=(const etl::bitset<Active_Bits, TElement>& lhs, const etl::bitset_ext<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3571{
3572 return !(lhs == rhs);
3573}
3574
3575//***************************************************************************
3579//***************************************************************************
3580template <size_t Active_Bits, typename TElement>
3581ETL_CONSTEXPR14 bool operator==(const etl::bitset_ext<Active_Bits, TElement>& lhs, const etl::bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3582{
3583 const char Storage_Model = etl::bitset<Active_Bits, TElement>::Storage_Model;
3584 const size_t Number_Of_Elements = etl::bitset<Active_Bits, TElement>::Number_Of_Elements;
3585
3586 typename etl::bitset_ext<Active_Bits, TElement>::const_span_type lhs_span = lhs.span();
3587 typename etl::bitset<Active_Bits, TElement>::const_span_type rhs_span = rhs.span();
3588
3589 typedef etl::bitset_impl<TElement, Storage_Model> implementation;
3590
3591 return implementation::operator_equality(lhs_span.begin(), rhs_span.begin(), Number_Of_Elements);
3592}
3593
3594//***************************************************************************
3598//***************************************************************************
3599template <size_t Active_Bits, typename TElement>
3600ETL_CONSTEXPR14 bool operator!=(const etl::bitset_ext<Active_Bits, TElement>& lhs, const etl::bitset<Active_Bits, TElement>& rhs) ETL_NOEXCEPT
3601{
3602 return !(lhs == rhs);
3603}
3604
3605//***************************************************************************
3609//***************************************************************************
3610template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3611ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3613{
3614 // Get a span of each type.
3615 typename etl::bitset<Active_Bits, TLhsElement>::const_span_type lhs_span = lhs.span();
3616 typename etl::bitset_ext<Active_Bits, TRhsElement>::const_span_type rhs_span = rhs.span();
3617
3618 // Put the bitset with the largest element type as the first argument.
3619 if ETL_IF_CONSTEXPR (sizeof(TLhsElement) > sizeof(TRhsElement))
3620 {
3621 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3622 }
3623 else
3624 {
3625 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3626 }
3627}
3628
3629//***************************************************************************
3633//***************************************************************************
3634template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3635ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3637{
3638 return !(lhs == rhs);
3639}
3640
3641//***************************************************************************
3645//***************************************************************************
3646template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3647ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3649{
3650 // Get a span of each type.
3651 typename etl::bitset_ext<Active_Bits, TLhsElement>::const_span_type lhs_span = lhs.span();
3652 typename etl::bitset<Active_Bits, TRhsElement>::const_span_type rhs_span = rhs.span();
3653
3654 // Put the bitset with the largest element type as the first argument.
3655 if ETL_IF_CONSTEXPR (sizeof(TLhsElement) > sizeof(TRhsElement))
3656 {
3657 return etl::private_bitset::compare_bitset_spans(lhs_span, rhs_span);
3658 }
3659 else
3660 {
3661 return etl::private_bitset::compare_bitset_spans(rhs_span, lhs_span);
3662 }
3663}
3664
3665//***************************************************************************
3669//***************************************************************************
3670template <size_t Active_Bits, typename TLhsElement, typename TRhsElement>
3671ETL_CONSTEXPR14 typename etl::enable_if<!etl::is_same<TLhsElement, TRhsElement>::value, bool>::type
3673{
3674 return !(lhs == rhs);
3675}
3676
3677#include "minmax_pop.h"
3678
3679#endif
ETL_CONSTEXPR14 void swap(etl::bitset< Active_Bits, TElement > &lhs, etl::bitset< Active_Bits, TElement > &rhs) ETL_NOEXCEPT
swap
Definition bitset_new.h:2538
bool compare_bitset_spans(const TLhsSpan &lhs_span, const TRhsSpan &rhs_span)
Definition bitset_new.h:3429
The reference type returned.
Definition bitset_new.h:1692
ETL_CONSTEXPR14 bit_reference(const bit_reference &other) ETL_NOEXCEPT
Copy constructor.
Definition bitset_new.h:1700
ETL_CONSTEXPR14 bit_reference & operator=(const bit_reference &r) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:1726
ETL_CONSTEXPR14 bit_reference & operator=(bool b) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:1717
ETL_CONSTEXPR14 bit_reference & flip() ETL_NOEXCEPT
Flip the bit.
Definition bitset_new.h:1735
ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
Return the logical inverse of the bit.
Definition bitset_new.h:1744
The reference type returned.
Definition bitset_new.h:2607
ETL_CONSTEXPR14 bit_reference & operator=(bool b) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:2632
ETL_CONSTEXPR14 bit_reference & operator=(const bit_reference &r) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:2641
ETL_CONSTEXPR14 bit_reference & flip() ETL_NOEXCEPT
Flip the bit.
Definition bitset_new.h:2650
ETL_CONSTEXPR14 bool operator~() const ETL_NOEXCEPT
Return the logical inverse of the bit.
Definition bitset_new.h:2659
ETL_CONSTEXPR14 bit_reference(const bit_reference &other) ETL_NOEXCEPT
Copy constructor.
Definition bitset_new.h:2615
A bitset that uses externally declared storage.
Definition bitset_new.h:2581
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:2939
ETL_CONSTEXPR14 T extract() const
Definition bitset_new.h:3022
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:2915
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & from_string(const char32_t *text) ETL_NOEXCEPT
Set from a u32 string.
Definition bitset_new.h:2979
ETL_CONSTEXPR14 bitset_ext & operator=(const bitset_ext< Active_Bits, TElement > &other) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:2843
ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
Are any of the bits set?
Definition bitset_new.h:3210
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:2811
static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
The value of a set element.
Definition bitset_new.h:3116
ETL_CONSTEXPR14 void swap(etl::bitset_ext< Active_Bits, TElement > &other) ETL_NOEXCEPT
swap
Definition bitset_new.h:3367
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:3351
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & flip(size_t position)
Flip the bit at the position.
Definition bitset_new.h:3238
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & from_string(const char *text) ETL_NOEXCEPT
Set from a string.
Definition bitset_new.h:2949
ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
Definition bitset_new.h:3293
static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
The mask for the msb element.
Definition bitset_new.h:3132
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:2756
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:2746
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:2800
unsigned long long to_ullong() const
Get as an unsigned long long.
Definition bitset_new.h:3044
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & operator<<=(size_t shift) ETL_NOEXCEPT
operator <<=
Definition bitset_new.h:3331
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & operator|=(const bitset_ext< Active_Bits, TElement > &other) ETL_NOEXCEPT
operator |=
Definition bitset_new.h:3311
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & operator^=(const bitset_ext< Active_Bits, TElement > &other) ETL_NOEXCEPT
operator ^=
Definition bitset_new.h:3321
ETL_CONSTEXPR14 bool any(element_type mask) const ETL_NOEXCEPT
Are any of the mask bits set?
Definition bitset_new.h:3218
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & reset() ETL_NOEXCEPT
Reset all of the bits.
Definition bitset_new.h:3054
ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
Are none of the bits set?
Definition bitset_new.h:3192
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & set() ETL_NOEXCEPT
Set all of the bits.
Definition bitset_new.h:2853
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & reset(size_t position)
Reset the bit at the position.
Definition bitset_new.h:3064
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:2789
ETL_CONSTEXPR14 bitset_ext(element_type *pbuffer_)
Definition bitset_new.h:2691
ETL_CONSTEXPR14 T value() const ETL_NOEXCEPT
Get as an integral value.
Definition bitset_new.h:2990
ETL_CONSTEXPR14 bitset_ext(unsigned long long value, element_type *pbuffer_)
Construct from a value.
Definition bitset_new.h:2735
static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
The number of bits in an element.
Definition bitset_new.h:3140
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:2822
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:2902
ETL_CONSTEXPR14 bool operator[](size_t position) const ETL_NOEXCEPT
Read [] operator.
Definition bitset_new.h:3250
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & operator&=(const bitset_ext< Active_Bits, TElement > &other) ETL_NOEXCEPT
operator &=
Definition bitset_new.h:3301
static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
The number of bits in the bitset.
Definition bitset_new.h:3100
static ETL_CONSTEXPR size_t number_of_elements() ETL_NOEXCEPT
The number of storage elements in the bitset.
Definition bitset_new.h:3108
ETL_CONSTEXPR14 bool test(size_t position) const
Definition bitset_new.h:3078
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & flip() ETL_NOEXCEPT
Flip all of the bits.
Definition bitset_new.h:3228
static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
The total number of bits of storage, including unused.
Definition bitset_new.h:3148
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & set(size_t position, bool value=true)
Set the bit at the position.
Definition bitset_new.h:2863
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:2778
unsigned long to_ulong() const
Get as an unsigned long.
Definition bitset_new.h:3034
ETL_CONSTEXPR14 bool test() const
Definition bitset_new.h:3090
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:2833
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:2927
ETL_CONSTEXPR14 bit_reference operator[](size_t position) ETL_NOEXCEPT
Write [] operator.
Definition bitset_new.h:3258
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & from_string(const wchar_t *text) ETL_NOEXCEPT
Set from a wide string.
Definition bitset_new.h:2959
ETL_CONSTEXPR14 bool none(element_type mask) const ETL_NOEXCEPT
Are none of the mask bits set?
Definition bitset_new.h:3200
ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
Count the number of bits set.
Definition bitset_new.h:3166
ETL_CONSTEXPR14 bitset_ext(const bitset_ext< Active_Bits, TElement > &other, buffer_type &buffer) ETL_NOEXCEPT
Construct copy.
Definition bitset_new.h:2721
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & set()
Set the bit at the position.
Definition bitset_new.h:2889
ETL_CONSTEXPR14 bitset_ext(const bitset_ext< Active_Bits, TElement > &other, element_type *pbuffer_)
Construct copy.
Definition bitset_new.h:2711
static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
Definition bitset_new.h:3158
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & operator>>=(size_t shift) ETL_NOEXCEPT
operator >>=
Definition bitset_new.h:3341
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:3359
ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
Definition bitset_new.h:3282
static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
The value of a clear element.
Definition bitset_new.h:3124
ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
Definition bitset_new.h:3385
ETL_CONSTEXPR14 bitset_ext< Active_Bits, TElement > & set(bool value=true)
Set the bit at the position.
Definition bitset_new.h:2876
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:2767
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:3271
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:2969
ETL_CONSTEXPR14 bitset_ext(buffer_type &buffer)
Default constructor.
Definition bitset_new.h:2701
ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
Definition bitset_new.h:3376
ETL_CONSTEXPR14 T extract(size_t position, size_t length=etl::integral_limits< T >::bits)
Definition bitset_new.h:3003
Definition binary.h:2196
Definition binary.h:2228
Definition bitset_new.h:1582
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
#define ETL_DECLARE_ENUM_TYPE(TypeName, ValueType)
Definition enum_type.h:90
Definition array.h:88
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:1513
static ETL_CONSTEXPR14 etl::make_unsigned< T >::type extract_from_multiple_elements(const element_type *pbuffer, int element_index, size_t active_bits_in_msb, size_t length) ETL_NOEXCEPT
Extract an value from multiple elements.
Definition bitset_new.h:1081
ETL_CONSTEXPR14 bool none(element_type mask) const ETL_NOEXCEPT
Are none of the mask bits set?
Definition bitset_new.h:2201
static ETL_CONSTEXPR14 T extract(const_pointer pbuffer)
Extract an integral value from an arbitrary position and length.
Definition bitset_new.h:1219
ETL_CONSTEXPR14 size_t find_next(bool state, size_t position) const ETL_NOEXCEPT
Definition bitset_new.h:2294
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:1258
ETL_CONSTEXPR14 T extract(size_t position, size_t length=etl::integral_limits< T >::bits) const
Definition bitset_new.h:2004
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:845
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set(size_t position, bool value=true)
Set the bit at the position.
Definition bitset_new.h:1864
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:1168
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:1129
ETL_CONSTEXPR14 bitset(const bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
Copy constructor.
Definition bitset_new.h:1785
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:715
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:1927
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:537
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:1186
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:529
static ETL_CONSTEXPR element_type all_set_element() ETL_NOEXCEPT
The value of a set element.
Definition bitset_new.h:2117
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:1980
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:914
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & operator&=(const bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
operator &=
Definition bitset_new.h:2314
static ETL_CONSTEXPR14 T extract(const_pointer pbuffer)
Extract an integral value from an arbitrary position and length.
Definition bitset_new.h:450
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & operator>>=(size_t shift) ETL_NOEXCEPT
operator >>=
Definition bitset_new.h:2421
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const char16_t *text) ETL_NOEXCEPT
Set from a u16 string.
Definition bitset_new.h:1970
static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Flip all of the bits.
Definition bitset_new.h:1236
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set() ETL_NOEXCEPT
Set all of the bits.
Definition bitset_new.h:1854
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:588
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:707
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator>>(size_t shift) const ETL_NOEXCEPT
operator >>
Definition bitset_new.h:2409
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator<<(size_t shift) const ETL_NOEXCEPT
operator <<
Definition bitset_new.h:2380
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:1309
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator~() const ETL_NOEXCEPT
operator ~
Definition bitset_new.h:2368
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & flip() ETL_NOEXCEPT
Flip all of the bits.
Definition bitset_new.h:2229
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const char *text) ETL_NOEXCEPT
Set from a string.
Definition bitset_new.h:1950
ETL_CONSTEXPR14 const_span_type span() const ETL_NOEXCEPT
Definition bitset_new.h:2472
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:944
ETL_CONSTEXPR14 bool none() const ETL_NOEXCEPT
Are none of the bits set?
Definition bitset_new.h:2193
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:1825
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & operator<<=(size_t shift) ETL_NOEXCEPT
operator <<=
Definition bitset_new.h:2392
static ETL_CONSTEXPR14 void flip_position(pointer pbuffer, size_t position)
Flip the bit at the position.
Definition bitset_new.h:553
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:974
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator&(const bitset< Active_Bits, TElement > &other) const ETL_NOEXCEPT
operator &
Definition bitset_new.h:2302
ETL_CONSTEXPR14 bit_reference operator[](size_t position) ETL_NOEXCEPT
Write [] operator.
Definition bitset_new.h:2259
static ETL_CONSTEXPR14 void set_position(pointer pbuffer, bool value=true)
Set the bit at the position.
Definition bitset_new.h:877
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:1329
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:513
ETL_CONSTEXPR14 size_t find_first(bool state) const ETL_NOEXCEPT
Definition bitset_new.h:2283
static ETL_CONSTEXPR14 void set_position(pointer pbuffer)
Set the bit at the position.
Definition bitset_new.h:896
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:1795
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & from_string(const wchar_t *text) ETL_NOEXCEPT
Set from a wide string.
Definition bitset_new.h:1960
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:1342
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & flip(size_t position)
Flip the bit at the position.
Definition bitset_new.h:2239
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:2109
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:772
static ETL_CONSTEXPR14 void operator_or(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:642
ETL_CONSTEXPR14 void swap(etl::bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
swap
Definition bitset_new.h:2454
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:1201
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:2272
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:331
static ETL_CONSTEXPR size_t allocated_bits() ETL_NOEXCEPT
The total number of bits of storage, including unused.
Definition bitset_new.h:2149
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:1393
static ETL_CONSTEXPR element_type top_mask() ETL_NOEXCEPT
The mask for the msb element.
Definition bitset_new.h:2141
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:1355
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:683
ETL_CONSTEXPR14 bool test(size_t position) const
Definition bitset_new.h:2079
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:1991
static ETL_CONSTEXPR14 bool any(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Are any of the bits set?
Definition bitset_new.h:521
ETL_CONSTEXPR14 bool any(element_type mask) const ETL_NOEXCEPT
Are any of the mask bits set?
Definition bitset_new.h:2219
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & operator^=(const bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
operator ^=
Definition bitset_new.h:2358
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:1835
static ETL_CONSTEXPR element_type all_clear_element() ETL_NOEXCEPT
The value of a clear element.
Definition bitset_new.h:2125
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & reset() ETL_NOEXCEPT
Reset all of the bits.
Definition bitset_new.h:2055
static ETL_CONSTEXPR14 void reset_all(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Reset all of the bits.
Definition bitset_new.h:1034
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:668
static ETL_CONSTEXPR14 void operator_xor(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:651
static ETL_CONSTEXPR14 T value(const_pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
Get as a value.
Definition bitset_new.h:1057
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:545
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:810
static ETL_CONSTEXPR14 void flip_position(pointer pbuffer, size_t position) ETL_NOEXCEPT
Flip the bit at the position.
Definition bitset_new.h:1244
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator|(const bitset< Active_Bits, TElement > &other) const ETL_NOEXCEPT
operator |
Definition bitset_new.h:2324
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:858
static ETL_CONSTEXPR14 void swap(pointer pbuffer1, pointer pbuffer2, size_t number_of_elements)
Swap bitset buffers.
Definition bitset_new.h:1571
static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
operator not
Definition bitset_new.h:1381
ETL_CONSTEXPR14 bitset & operator=(const bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
Assignment operator.
Definition bitset_new.h:1844
static ETL_CONSTEXPR size_t bits_per_element() ETL_NOEXCEPT
The number of bits in an element.
Definition bitset_new.h:2133
ETL_CONSTEXPR14 size_t count() const ETL_NOEXCEPT
Count the number of bits set.
Definition bitset_new.h:2167
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:1526
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:416
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & set(bool value=true)
Set the bit at the position.
Definition bitset_new.h:1877
ETL_CONSTEXPR14 bool operator[](size_t position) const ETL_NOEXCEPT
Read [] operator.
Definition bitset_new.h:2251
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:1815
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:1903
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:826
static ETL_CONSTEXPR14 bool test(const_pointer pbuffer, size_t position)
Definition bitset_new.h:472
static ETL_CONSTEXPR14 void reset_position(pointer pbuffer, size_t position) ETL_NOEXCEPT
Reset the bit at the position.
Definition bitset_new.h:1045
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > operator^(const bitset< Active_Bits, TElement > &other) const ETL_NOEXCEPT
operator ^
Definition bitset_new.h:2346
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:505
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:1004
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & reset(size_t position)
Reset the bit at the position.
Definition bitset_new.h:2065
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:1915
static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
The number of bits in the bitset.
Definition bitset_new.h:2101
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:1805
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:387
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:1452
static ETL_CONSTEXPR14 void operator_and(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:633
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:1890
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:425
unsigned long long to_ullong() const
Get as an unsigned long long.
Definition bitset_new.h:2045
ETL_CONSTEXPR14 bool any() const ETL_NOEXCEPT
Are any of the bits set?
Definition bitset_new.h:2211
static ETL_CONSTEXPR14 bool operator_equality(const_pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
operator_equality
Definition bitset_new.h:698
ETL_CONSTEXPR14 bool test() const
Definition bitset_new.h:2091
ETL_CONSTEXPR14 span_type span() ETL_NOEXCEPT
Definition bitset_new.h:2463
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:359
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:2035
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:1368
friend ETL_CONSTEXPR14 bool operator==(const bitset< Active_Bits, TElement > &lhs, const bitset< Active_Bits, TElement > &rhs) ETL_NOEXCEPT
operator ==
Definition bitset_new.h:2438
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:1548
static ETL_CONSTEXPR14 size_t count(const_pointer pbuffer, size_t) ETL_NOEXCEPT
Count the number of bits set.
Definition bitset_new.h:481
static ETL_CONSTEXPR14 void operator_assignment(pointer lhs_pbuffer, const_pointer rhs_pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:624
static ETL_CONSTEXPR14 bool test(const_pointer pbuffer, size_t position) ETL_NOEXCEPT
Definition bitset_new.h:761
ETL_CONSTEXPR14 T extract() const
Definition bitset_new.h:2023
static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t) ETL_NOEXCEPT
Definition bitset_new.h:660
ETL_CONSTEXPR14 bitset< Active_Bits, TElement > & operator|=(const bitset< Active_Bits, TElement > &other) ETL_NOEXCEPT
operator |=
Definition bitset_new.h:2336
friend ETL_CONSTEXPR14 bool operator!=(const bitset< Active_Bits, TElement > &lhs, const bitset< Active_Bits, TElement > &rhs) ETL_NOEXCEPT
operator !=
Definition bitset_new.h:2446
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:563
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:1939
ETL_CONSTEXPR14 bitset() ETL_NOEXCEPT
Default constructor.
Definition bitset_new.h:1776
static ETL_CONSTEXPR etl::bitset_storage_model storage_model() ETL_NOEXCEPT
Definition bitset_new.h:2159
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
ETL_CONSTEXPR14 etl::enable_if<!etl::is_same< TLhsElement, TRhsElement >::value, bool >::type operator==(const etl::bitset< Active_Bits, TLhsElement > &lhs, const etl::bitset< Active_Bits, TRhsElement > &rhs) ETL_NOEXCEPT
Definition bitset_new.h:3477
ETL_CONSTEXPR14 bool operator!=(const etl::bitset< Active_Bits, TElement > &lhs, const etl::bitset< Active_Bits, TElement > &rhs) ETL_NOEXCEPT
Definition bitset_new.h:2529
Definition bitset_new.h:90
#define ETL_ASSERT(b, e)
Definition error_handler.h:511
Definition exception.h:59
Definition integral_limits.h:518
bitset_ext
Definition absolute.h:40
ETL_CONSTEXPR TContainer::pointer data(TContainer &container)
Definition iterator.h:1228
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::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:751