Embedded Template Library  1.0
 All Classes Files Functions Variables Typedefs Friends Modules Pages
bitset.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 
8 Copyright(c) 2014 jwellbelove
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files(the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions :
16 
17 The above copyright notice and this permission notice shall be included in all
18 copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 SOFTWARE.
27 ******************************************************************************/
28 
29 #ifndef __ETL_BITSET__
30 #define __ETL_BITSET__
31 
32 #include <algorithm>
33 #include <iterator>
34 #include <string.h>
35 #include <stdint.h>
36 #include <stddef.h>
37 
38 #include "integral_limits.h"
39 #include "smallest.h"
40 #include "array.h"
41 #include "nullptr.h"
42 #include "log.h"
43 #include "ibitset.h"
44 
45 #if WIN32
46 #undef min
47 #endif
48 
49 //*****************************************************************************
53 //*****************************************************************************
54 
55 namespace etl
56 {
57  //*************************************************************************
63  //*************************************************************************
64  template <const size_t N>
65  class bitset : public ibitset
66  {
67  public:
68 
69  //*************************************************************************
71  //*************************************************************************
73  {
74  public:
75 
76  friend class bitset<N>;
77 
78  //*******************************
80  //*******************************
81  operator bool() const
82  {
83  return p_bitset->test(position);
84  }
85 
86  //*******************************
88  //*******************************
90  {
91  p_bitset->set(position, b);
92  return *this;
93  }
94 
95  //*******************************
97  //*******************************
99  {
100  p_bitset->set(position, bool(r));
101  return *this;
102  }
103 
104  //*******************************
106  //*******************************
108  {
109  p_bitset->flip(position);
110  return *this;
111  }
112 
113  //*******************************
115  //*******************************
116  bool operator~() const
117  {
118  return !p_bitset->test(position);
119  }
120 
121  private:
122 
123  //*******************************
125  //*******************************
126  bit_reference()
127  : p_bitset(nullptr),
128  position(0)
129  {
130  }
131 
132  //*******************************
134  //*******************************
135  bit_reference(bitset<N>& r_bitset, size_t position)
136  : p_bitset(&r_bitset),
137  position(position)
138  {
139  }
140 
141  bitset<N>* p_bitset;
142  size_t position;
143  };
144 
145  //*************************************************************************
147  //*************************************************************************
148  class iterator : public std::iterator<std::random_access_iterator_tag, bool>
149  {
150  public:
151 
152  friend class bitset<N>;
153  friend class const_iterator;
154 
155  //*******************************
157  //*******************************
159  : position(0)
160  {
161  }
162 
163  //*******************************
165  //*******************************
166  iterator(const iterator& other)
167  : position(other.position)
168  {
169  }
170 
171  //*******************************
173  //*******************************
175  {
176  ++position;
177  return *this;
178  }
179 
180  //*******************************
182  //*******************************
184  {
185  iterator temp(*this);
186  ++position;
187  return temp;
188  }
189 
190  //*******************************
192  //*******************************
194  {
195  --position;
196  return *this;
197  }
198 
199  //*******************************
201  //*******************************
203  {
204  iterator temp(*this);
205  --position;
206  return temp;
207  }
208 
209  //*******************************
211  //*******************************
213  {
214  return bit_reference(*p_bitset, position);
215  }
216 
217  //*******************************
219  //*******************************
220  bool operator *() const
221  {
222  return p_bitset->test(position);
223  }
224 
225  //*******************************
227  //*******************************
229  {
230  position += i;
231  return *this;
232  }
233 
234  //*******************************
236  //*******************************
238  {
239  position -= i;
240  return *this;
241  }
242 
243  //*******************************
245  //*******************************
246  iterator& operator =(const iterator& other)
247  {
248  position = other.position;
249  p_bitset = other.p_bitset;
250  return *this;
251  }
252 
253  //*******************************
255  //*******************************
256  friend iterator operator +(const iterator& other, int i)
257  {
258  iterator temp(other);
259  temp += i;
260  return temp;
261  }
262 
263  //*******************************
265  //*******************************
266  friend iterator operator -(const iterator& other, int i)
267  {
268  iterator temp(other);
269  temp -= i;
270  return temp;
271  }
272 
273  //*******************************
275  //*******************************
276  friend bool operator ==(const iterator& lhs, const iterator& rhs)
277  {
278  return lhs.position == rhs.position;
279  }
280 
281  //*******************************
283  //*******************************
284  friend bool operator !=(const iterator& lhs, const iterator& rhs)
285  {
286  return lhs.position != rhs.position;
287  }
288 
289  //*******************************
291  //*******************************
292  friend bool operator <(const iterator& lhs, const iterator& rhs)
293  {
294  return lhs.position < rhs.position;
295  }
296 
297  //*******************************
299  //*******************************
300  friend bool operator >(const iterator& lhs, const iterator& rhs)
301  {
302  return lhs.position > rhs.position;
303  }
304 
305  //*******************************
307  //*******************************
308  friend bool operator <=(const iterator& lhs, const iterator& rhs)
309  {
310  return lhs.position <= rhs.position;
311  }
312 
313  //*******************************
315  //*******************************
316  friend bool operator >=(const iterator& lhs, const iterator& rhs)
317  {
318  return lhs.position >-rhs.position;
319  }
320 
321  private:
322 
323  //*******************************
325  //*******************************
326  iterator(bitset<N>& r_bitset, size_t position)
327  : p_bitset(&r_bitset),
328  position(position)
329  {}
330 
331  bitset<N>* p_bitset;
332  size_t position;
333  };
334 
335  //*************************************************************************
337  //*************************************************************************
338  class const_iterator : public std::iterator<std::random_access_iterator_tag, const bool>
339  {
340  public:
341 
342  friend class bitset<N>;
343 
344  //*******************************
346  //*******************************
348  : position(0)
349  {
350  }
351 
352  //*******************************
354  //*******************************
355  const_iterator(const typename bitset<N>::iterator& other)
356  : position(other.position)
357  {
358  }
359 
360  //*******************************
362  //*******************************
364  : position(other.position)
365  {
366  }
367 
368  //*******************************
370  //*******************************
372  {
373  ++position;
374  return *this;
375  }
376 
377  //*******************************
379  //*******************************
381  {
382  const_iterator temp(*this);
383  ++position;
384  return temp;
385  }
386 
387  //*******************************
389  //*******************************
391  {
392  --position;
393  return *this;
394  }
395 
396  //*******************************
398  //*******************************
400  {
401  const_iterator temp(*this);
402  --position;
403  return temp;
404  }
405 
406  //*******************************
408  //*******************************
409  bool operator *() const
410  {
411  return p_bitset->test(position);
412  }
413 
414  //*******************************
416  //*******************************
418  {
419  position += i;
420  return *this;
421  }
422 
423  //*******************************
425  //*******************************
427  {
428  position -= i;
429  return *this;
430  }
431 
432  //*******************************
434  //*******************************
436  {
437  position = other.position;
438  p_bitset = other.p_bitset;
439  return *this;
440  }
441 
442  //*******************************
444  //*******************************
445  friend const_iterator operator +(const const_iterator& other, int i)
446  {
447  const_iterator temp(other);
448  temp += i;
449  return temp;
450  }
451 
452  //*******************************
454  //*******************************
455  friend const_iterator operator -(const const_iterator& other, int i)
456  {
457  const_iterator temp(other);
458  temp -= i;
459  return temp;
460  }
461 
462  //*******************************
464  //*******************************
465  friend bool operator ==(const const_iterator& lhs, const const_iterator& rhs)
466  {
467  return lhs.position == rhs.position;
468  }
469 
470  //*******************************
472  //*******************************
473  friend bool operator !=(const const_iterator& lhs, const const_iterator& rhs)
474  {
475  return lhs.position != rhs.position;
476  }
477 
478  //*******************************
480  //*******************************
481  friend bool operator <(const const_iterator& lhs, const const_iterator& rhs)
482  {
483  return lhs.position < rhs.position;
484  }
485 
486  //*******************************
488  //*******************************
489  friend bool operator >(const const_iterator& lhs, const const_iterator& rhs)
490  {
491  return lhs.position > rhs.position;
492  }
493 
494  //*******************************
496  //*******************************
497  friend bool operator <=(const const_iterator& lhs, const const_iterator& rhs)
498  {
499  return lhs.position <= rhs.position;
500  }
501 
502  //*******************************
504  //*******************************
505  friend bool operator >=(const const_iterator& lhs, const const_iterator& rhs)
506  {
507  return lhs.position >- rhs.position;
508  }
509 
510  private:
511 
512  //*******************************
514  //*******************************
515  const_iterator(bitset<N>& r_bitset, size_t position)
516  : p_bitset(&r_bitset),
517  position(position)
518  {
519  }
520 
521  bitset<N>* p_bitset;
522  size_t position;
523  };
524 
525  //*************************************************************************
527  //*************************************************************************
529  {
530  reset();
531  }
532 
533  //*************************************************************************
535  //*************************************************************************
536  bitset(const bitset<N>& other)
537  {
538  data = other.data;
539  }
540 
541  //*************************************************************************
543  //*************************************************************************
544  bitset(unsigned long long value)
545  {
546  reset();
547 
548  const size_t SHIFT = (integral_limits<unsigned long long>::bits <= BITS_PER_ELEMENT) ? 0 : BITS_PER_ELEMENT;
549 
550  // Can we do it in one hit?
551  if (SHIFT == 0)
552  {
553  data[0] = value;
554  }
555  else
556  {
557  size_t i = 0;
558 
559  while ((value != 0) && (i < ARRAY_SIZE))
560  {
561  data[i++] = value & ALL_SET;
562  value = value >> SHIFT;
563  }
564  }
565 
566  data.back() &= TOP_MASK;
567  }
568 
569  //*************************************************************************
571  //*************************************************************************
572  bitset(const char* text)
573  {
574  reset();
575 
576  size_t i = std::min(N, strlen(text));
577 
578  while (i > 0)
579  {
580  set(--i, *text++ == '1');
581  }
582  }
583 
584  //*************************************************************************
586  //*************************************************************************
588  {
589  data.fill(ALL_SET);
590  data.back() &= TOP_MASK;
591 
592  return *this;
593  }
594 
595  //*************************************************************************
597  //*************************************************************************
598  bitset<N>& set(size_t position, bool value = true)
599  {
600  if (position < N)
601  {
602  size_t index;
603  element_type bit;
604 
605  if (ARRAY_SIZE == 1)
606  {
607  index = 0;
608  bit = element_type(1) << position;
609  }
610  else
611  {
612  index = position >> log2<BITS_PER_ELEMENT>::value;
613  bit = element_type(1) << (position & (BITS_PER_ELEMENT - 1));
614  }
615 
616  if (value)
617  {
618  data[index] |= bit;
619  }
620  else
621  {
622  data[index] &= ~bit;
623  }
624  }
625 
626  return *this;
627  }
628 
629  //*************************************************************************
631  //*************************************************************************
632  bitset<N>& set(const char* text)
633  {
634  reset();
635 
636  size_t i = std::min(N, strlen(text));
637 
638  while (i > 0)
639  {
640  set(--i, *text++ == '1');
641  }
642 
643  return *this;
644  }
645 
646  //*************************************************************************
648  //*************************************************************************
650  {
651  data.fill(ALL_CLEAR);
652  return *this;
653  }
654 
655  //*************************************************************************
657  //*************************************************************************
658  bitset<N>& reset(size_t position)
659  {
660  if (position < N)
661  {
662  size_t index;
663  element_type bit;
664 
665  if (ARRAY_SIZE == 1)
666  {
667  index = 0;
668  bit = element_type(1) << position;
669  }
670  else
671  {
672  index = position >> log2<BITS_PER_ELEMENT>::value;
673  bit = element_type(1) << (position & (BITS_PER_ELEMENT - 1));
674  }
675 
676  data[index] &= ~bit;
677  }
678 
679  return *this;
680  }
681 
682  //*************************************************************************
684  //*************************************************************************
686  {
687  for (size_t i = 0; i < ARRAY_SIZE; ++i)
688  {
689  data[i] = ~data[i];
690  }
691 
692  data.back() &= TOP_MASK;
693 
694  return *this;
695  }
696 
697  //*************************************************************************
699  //*************************************************************************
700  bitset<N>& flip(size_t position)
701  {
702  if (position < N)
703  {
704  size_t index;
705  element_type bit;
706 
707  if (ARRAY_SIZE == 1)
708  {
709  index = 0;
710  bit = element_type(1) << position;
711  }
712  else
713  {
714  index = position >> log2<BITS_PER_ELEMENT>::value;
715  bit = element_type(1) << (position & (BITS_PER_ELEMENT - 1));
716  }
717 
718  data[index] ^= bit;
719  }
720 
721  return *this;
722  }
723 
724  //*************************************************************************
726  //*************************************************************************
727  bool operator[] (size_t position) const
728  {
729  return test(position);
730  }
731 
732  //*************************************************************************
734  //*************************************************************************
735  bit_reference operator [] (size_t position)
736  {
737  return bit_reference(*this, position);
738  }
739 
740  //*************************************************************************
743  //*************************************************************************
744  bool test(size_t position) const
745  {
746  if (position < N)
747  {
748  size_t index;
749  element_type bit;
750 
751  if (ARRAY_SIZE == 1)
752  {
753  index = 0;
754  bit = element_type(1) << position;
755  }
756  else
757  {
758  index = position >> log2<BITS_PER_ELEMENT>::value;
759  bit = element_type(1) << (position & (BITS_PER_ELEMENT - 1));
760  }
761 
762  return (data[index] & bit) != 0;
763  }
764  else
765  {
766  return false;
767  }
768  }
769 
770  //*************************************************************************
771  // Are all the bits sets?
772  //*************************************************************************
773  bool all() const
774  {
775  // All but the last.
776  for (size_t i = 0; i < (ARRAY_SIZE - 1); ++i)
777  {
778  if (data[i] != ALL_SET)
779  {
780  return false;
781  }
782  }
783 
784  // The last.
785  if (data[ARRAY_SIZE - 1] != (ALL_SET & TOP_MASK))
786  {
787  return false;
788  }
789 
790  return true;
791  }
792 
793  //*************************************************************************
795  //*************************************************************************
796  bool any() const
797  {
798  return !none();
799  }
800 
801  //*************************************************************************
803  //*************************************************************************
804  bool none() const
805  {
806  for (size_t i = 0; i < ARRAY_SIZE; ++i)
807  {
808  if (data[i] != 0)
809  {
810  return false;
811  }
812  }
813 
814  return true;
815  }
816 
817  //*************************************************************************
819  //*************************************************************************
820  size_t count() const
821  {
822  size_t n = 0;
823 
824  for (size_t i = 0; i < ARRAY_SIZE; ++i)
825  {
826  element_type value = data[i];
827 
828  while (value != 0)
829  {
830  n += (value & 1);
831 
832  value >>= 1;
833  }
834  }
835 
836  return n;
837  }
838 
839  //*************************************************************************
841  //*************************************************************************
842  size_t size() const
843  {
844  return N;
845  }
846 
847  //*************************************************************************
851  //*************************************************************************
852  size_t find_first(bool state) const
853  {
854  return find_next(state, 0);
855  }
856 
857  //*************************************************************************
862  //*************************************************************************
863  size_t find_next(bool state, size_t position) const
864  {
865  // Where to start.
866  size_t element_index = position >> log2<BITS_PER_ELEMENT>::value;
867  size_t bit_index = position & log2<BITS_PER_ELEMENT>::value;;
868  element_type mask = 1 << bit_index;
869 
870  // For each element in the bitset...
871  while (element_index < ARRAY_SIZE)
872  {
873  const element_type& element = data[element_index];
874 
875  // For each bit in the element...
876  while ((bit_index < BITS_PER_ELEMENT) && (position != N))
877  {
878  // Equal to the required state?
879  if (((element & mask) != 0) == state)
880  {
881  return position;
882  }
883 
884  // Move on to the next bit.
885  mask <<= 1;
886  ++position;
887  ++bit_index;
888  }
889 
890  // Start at the beginning for all other elements.
891  bit_index = 0;
892  mask = 1;
893 
894  ++element_index;
895  }
896 
897  return N;
898  }
899 
900  //*************************************************************************
902  //*************************************************************************
904  {
905  for (size_t i = 0; i < ARRAY_SIZE; ++i)
906  {
907  data[i] &= other.data[i];
908  }
909 
910  return *this;
911  }
912 
913  //*************************************************************************
915  //*************************************************************************
917  {
918  for (size_t i = 0; i < ARRAY_SIZE; ++i)
919  {
920  data[i] |= other.data[i];
921  }
922 
923  return *this;
924  }
925 
926  //*************************************************************************
928  //*************************************************************************
930  {
931  for (size_t i = 0; i < ARRAY_SIZE; ++i)
932  {
933  data[i] ^= other.data[i];
934  }
935 
936  return *this;
937  }
938 
939  //*************************************************************************
941  //*************************************************************************
943  {
944  bitset<N> temp;
945 
946  for (size_t i = 0; i < ARRAY_SIZE; ++i)
947  {
948  temp[i] = ~data[i];
949  }
950 
951  return temp;
952  }
953 
954  //*************************************************************************
956  //*************************************************************************
957  bitset<N> operator<<(size_t shift) const
958  {
959  bitset<N> temp;
960 
961  if (ARRAY_SIZE == 1)
962  {
963  temp.data[0] = data[0] << shift;
964  }
965  else
966  {
967  size_t source = N - shift - 1;
968  size_t destination = N - 1;
969 
970  for (size_t i = 0; i < (N - shift); ++i)
971  {
972  temp.set(destination--, test(source--));
973  }
974  }
975 
976  return temp;
977  }
978 
979  //*************************************************************************
981  //*************************************************************************
982  bitset<N>& operator<<=(size_t shift)
983  {
984  if (ARRAY_SIZE == 1)
985  {
986  data[0] <<= shift;
987  }
988  else
989  {
990  size_t source = N - shift - 1;
991  size_t destination = N - 1;
992 
993  for (size_t i = 0; i < (N - shift); ++i)
994  {
995  set(destination--, test(source--));
996  }
997 
998  for (size_t i = 0; i < shift; ++i)
999  {
1000  reset(destination--);
1001  }
1002  }
1003 
1004  return *this;
1005  }
1006 
1007  //*************************************************************************
1009  //*************************************************************************
1010  bitset<N> operator>>(size_t shift) const
1011  {
1012  bitset<N> temp;
1013 
1014  if (ARRAY_SIZE == 1)
1015  {
1016  temp.data[0] = data[0] >> shift;
1017  }
1018  else
1019  {
1020  size_t source = shift;
1021  size_t destination = 0;
1022 
1023  while (source != N)
1024  {
1025  temp.set(destination++, test(source++));
1026  }
1027  }
1028 
1029  return temp;
1030  }
1031 
1032  //*************************************************************************
1034  //*************************************************************************
1035  bitset<N>& operator>>=(size_t shift)
1036  {
1037  if (ARRAY_SIZE == 1)
1038  {
1039  data[0] >>= shift;
1040  }
1041  else
1042  {
1043  size_t source = shift;
1044  size_t destination = 0;
1045 
1046  for (size_t i = 0; i < (N - shift); ++i)
1047  {
1048  set(destination++, test(source++));
1049  }
1050 
1051  for (size_t i = 0; i < shift; ++i)
1052  {
1053  reset(destination++);
1054  }
1055  }
1056 
1057  return *this;
1058  }
1059 
1060  //*************************************************************************
1062  //*************************************************************************
1063  void swap(bitset<N>& other)
1064  {
1065  data.swap(other.data);
1066  }
1067 
1068  //*************************************************************************
1070  //*************************************************************************
1071  iterator begin()
1072  {
1073  return iterator(*this, 0);
1074  }
1075 
1076  //*************************************************************************
1078  //*************************************************************************
1079  const_iterator begin() const
1080  {
1081  return const_iterator(*this, 0);
1082  }
1083 
1084  //*************************************************************************
1086  //*************************************************************************
1087  const_iterator cbegin()
1088  {
1089  return const_iterator(*this, 0);
1090  }
1091 
1092  //*************************************************************************
1094  //*************************************************************************
1095  iterator end()
1096  {
1097  return iterator(*this, N - 1);
1098  }
1099 
1100  //*************************************************************************
1102  //*************************************************************************
1103  const_iterator end() const
1104  {
1105  return const_iterator(*this, N - 1);
1106  }
1107 
1108  //*************************************************************************
1110  //*************************************************************************
1111  const_iterator cend()
1112  {
1113  return const_iterator(*this, N - 1);
1114  }
1115 
1116 
1117  //*************************************************************************
1119  //*************************************************************************
1120  friend bool operator == (const bitset<N>& lhs, const bitset<N>& rhs)
1121  {
1122  for (size_t i = 0; i < ARRAY_SIZE; ++i)
1123  {
1124  if (lhs.data[i] != rhs.data[i])
1125  {
1126  return false;
1127  }
1128  }
1129 
1130  return true;
1131  }
1132 
1133  private:
1134 
1135  // The type used for each element in the array.
1136  typedef typename smallest_uint_for_bits<N>::type element_type;
1137 
1138  static const element_type ALL_SET = etl::integral_limits<element_type>::max;
1139  static const element_type ALL_CLEAR = 0;
1140  static const size_t BITS_PER_ELEMENT = etl::integral_limits<element_type>::bits;
1141  static const size_t ARRAY_SIZE = (N % BITS_PER_ELEMENT == 0) ? N / BITS_PER_ELEMENT : N / BITS_PER_ELEMENT + 1;
1142  static const size_t TOTAL_BITS = ARRAY_SIZE * BITS_PER_ELEMENT;
1143  static const size_t TOP_MASK_SHIFT = ((BITS_PER_ELEMENT - (TOTAL_BITS - N)) % BITS_PER_ELEMENT);
1144  static const element_type TOP_MASK = element_type(TOP_MASK_SHIFT == 0 ? ALL_SET : ~(ALL_SET << TOP_MASK_SHIFT));
1145 
1147  };
1148 
1149  //***************************************************************************
1152  //***************************************************************************
1153  template <const size_t N>
1154  bitset<N> operator & (const bitset<N>& lhs, const bitset<N>& rhs)
1155  {
1156  bitset<N> temp(lhs);
1157  temp &= rhs;
1158  return temp;
1159  }
1160 
1161  //***************************************************************************
1164  //***************************************************************************
1165  template<const size_t N>
1166  bitset<N> operator | (const bitset<N>& lhs, const bitset<N>& rhs)
1167  {
1168  bitset<N> temp(lhs);
1169  temp |= rhs;
1170  return temp;
1171  }
1172 
1173  //***************************************************************************
1176  //***************************************************************************
1177  template<const size_t N>
1178  bitset<N> operator ^ (const bitset<N>& lhs, const bitset<N>& rhs)
1179  {
1180  bitset<N> temp(lhs);
1181  temp ^= rhs;
1182  return temp;
1183  }
1184 
1185  //***************************************************************************
1188  //***************************************************************************
1189  template<const size_t N>
1190  bool operator != (const bitset<N>& lhs, const bitset<N>& rhs)
1191  {
1192  return !(lhs == rhs);
1193  }
1194 }
1195 
1196 //*************************************************************************
1198 //*************************************************************************
1199 template <const size_t N>
1201 {
1202  lhs.swap(rhs);
1203 }
1204 
1205 #if WIN32
1206 #define min(a,b) (((a) < (b)) ? (a) : (b))
1207 #endif
1208 
1209 #endif
iterator begin()
begin
Definition: bitset.h:1071
friend bool operator>=(const const_iterator &lhs, const const_iterator &rhs)
>= operator
Definition: bitset.h:505
const_iterator()
Constructor.
Definition: bitset.h:347
friend bool operator!=(const const_iterator &lhs, const const_iterator &rhs)
!= operator
Definition: bitset.h:473
friend const_iterator operator+(const const_iterator &other, int i)
Definition: bitset.h:445
bitset< N > & operator<<=(size_t shift)
operator <<=
Definition: bitset.h:982
bitset< N > operator<<(size_t shift) const
operator <<
Definition: bitset.h:957
bool none() const
Are none of th bits set?
Definition: bitset.h:804
bitset< N > operator&(const bitset< N > &lhs, const bitset< N > &rhs)
Definition: bitset.h:1154
bitset< N > & operator^=(const bitset< N > &other)
operator ^=
Definition: bitset.h:929
const_iterator begin() const
begin
Definition: bitset.h:1079
iterator & operator-=(int i)
-= operator
Definition: bitset.h:237
void fill(parameter_t value)
Definition: array.h:354
bool test(size_t position) const
Definition: bitset.h:744
friend bool operator==(const iterator &lhs, const iterator &rhs)
== operator
Definition: bitset.h:276
void swap(etl::bitset< N > &lhs, etl::bitset< N > &rhs)
swap
Definition: bitset.h:1200
bitset< N > operator>>(size_t shift) const
operator >>
Definition: bitset.h:1010
iterator & operator=(const iterator &other)
= operator
Definition: bitset.h:246
size_t find_next(bool state, size_t position) const
Definition: bitset.h:863
bitset< N > operator^(const bitset< N > &lhs, const bitset< N > &rhs)
Definition: bitset.h:1178
bitset(const bitset< N > &other)
Copy constructor.
Definition: bitset.h:536
const_iterator cbegin()
cbegin
Definition: bitset.h:1087
friend bool operator>=(const iterator &lhs, const iterator &rhs)
>= operator
Definition: bitset.h:316
const_iterator cend()
cend
Definition: bitset.h:1111
bitset< N > & operator|=(const bitset< N > &other)
operator |=
Definition: bitset.h:916
iterator()
Constructor.
Definition: bitset.h:158
bool operator*() const
Definition: bitset.h:409
friend bool operator>(const const_iterator &lhs, const const_iterator &rhs)
operator
Definition: bitset.h:489
friend bool operator>(const iterator &lhs, const iterator &rhs)
operator
Definition: bitset.h:300
bool operator!=(const bitset< N > &lhs, const bitset< N > &rhs)
Definition: bitset.h:1190
iterator & operator+=(int i)
+= operator
Definition: bitset.h:228
size_t find_first(bool state) const
Definition: bitset.h:852
bit_reference operator*()
Definition: bitset.h:212
bitset< N > operator~() const
operator ~
Definition: bitset.h:942
bitset(unsigned long long value)
Construct from a value.
Definition: bitset.h:544
const_iterator & operator+=(int i)
+= operator
Definition: bitset.h:417
bitset< N > & set(const char *text)
Set from a string.
Definition: bitset.h:632
Definition: log.h:89
bool operator~() const
Return the logical inverse of the bit.
Definition: bitset.h:116
bitset< N > & operator>>=(size_t shift)
operator >>=
Definition: bitset.h:1035
const_iterator end() const
end
Definition: bitset.h:1103
Definition: algorithm.h:43
Definition: integral_limits.h:54
friend bool operator==(const const_iterator &lhs, const const_iterator &rhs)
== operator
Definition: bitset.h:465
reference back()
Returns a reference to the last element.
Definition: array.h:189
friend iterator operator-(const iterator &other, int i)
Definition: bitset.h:266
bitset< N > & flip(size_t position)
Flip the bit at the position.
Definition: bitset.h:700
const_iterator & operator-=(int i)
-= operator
Definition: bitset.h:426
bit_reference & operator=(bool b)
Assignment operator.
Definition: bitset.h:89
bitset< N > & set()
Set all of the bits.
Definition: bitset.h:587
bitset()
Default constructor.
Definition: bitset.h:528
iterator & operator++()
++ operator (pre)
Definition: bitset.h:174
const_iterator & operator--()
– operator (pre)
Definition: bitset.h:390
friend bool operator==(const bitset< N > &lhs, const bitset< N > &rhs)
operator ==
Definition: bitset.h:1120
friend bool operator!=(const iterator &lhs, const iterator &rhs)
!= operator
Definition: bitset.h:284
The reference type returned.
Definition: bitset.h:72
size_t size() const
The size of the bitset.
Definition: bitset.h:842
bool any() const
Are any of the bits set?
Definition: bitset.h:796
Definition: ibitset.h:38
bitset< N > operator|(const bitset< N > &lhs, const bitset< N > &rhs)
Definition: bitset.h:1166
void swap(bitset< N > &other)
swap
Definition: bitset.h:1063
bitset< N > & flip()
Flip all of the bits.
Definition: bitset.h:685
const_iterator & operator++()
++ operator (pre)
Definition: bitset.h:371
const_iterator & operator=(const const_iterator &other)
= operator
Definition: bitset.h:435
friend bool operator<(const const_iterator &lhs, const const_iterator &rhs)
< operator
Definition: bitset.h:481
bitset< N > & set(size_t position, bool value=true)
Set the bit at the position.
Definition: bitset.h:598
bitset< N > & reset()
Reset all of the bits.
Definition: bitset.h:649
bit_reference & flip()
Flip the bit.
Definition: bitset.h:107
size_t count() const
Count the number of bits set.
Definition: bitset.h:820
Definition: bitset.h:65
The const_iterator type.
Definition: bitset.h:338
bitset< N > & operator&=(const bitset< N > &other)
operator &=
Definition: bitset.h:903
const_iterator(const typename bitset< N >::iterator &other)
Copy constructor from iterator.
Definition: bitset.h:355
iterator end()
end
Definition: bitset.h:1095
friend bool operator<=(const iterator &lhs, const iterator &rhs)
<= operator
Definition: bitset.h:308
friend bool operator<=(const const_iterator &lhs, const const_iterator &rhs)
<= operator
Definition: bitset.h:497
const_iterator(const const_iterator &other)
Copy constructor.
Definition: bitset.h:363
The iterator type.
Definition: bitset.h:148
bitset(const char *text)
Construct from a string.
Definition: bitset.h:572
iterator & operator--()
– operator (pre)
Definition: bitset.h:193
void swap(array &other)
Definition: array.h:363
bool operator[](size_t position) const
Read [] operator.
Definition: bitset.h:727
bitset< N > & reset(size_t position)
Reset the bit at the position.
Definition: bitset.h:658
friend iterator operator+(const iterator &other, int i)
Definition: bitset.h:256
friend bool operator<(const iterator &lhs, const iterator &rhs)
< operator
Definition: bitset.h:292
friend const_iterator operator-(const const_iterator &other, int i)
Definition: bitset.h:455
iterator(const iterator &other)
Copy constructor.
Definition: bitset.h:166