libstdc++: dynamic_bitset Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29#ifndef _GLIBCXX_TR2_DYNAMIC_BITSET

30#define _GLIBCXX_TR2_DYNAMIC_BITSET 1

31

32#pragma GCC system_header

33

41

42namespace std _GLIBCXX_VISIBILITY(default)

43{

44_GLIBCXX_BEGIN_NAMESPACE_VERSION

45

46namespace tr2

47{

48

49

50

51

52

53

54

55

56

57

58

59

60 template<typename _WordT = unsigned long long,

63 {

65 "_WordT not an unsigned integral type");

66

67 typedef _WordT block_type;

68 typedef _Alloc allocator_type;

69 typedef size_t size_type;

70

71 static const size_type _S_bits_per_block = __CHAR_BIT__ * sizeof(block_type);

72 static const size_type npos = static_cast<size_type>(-1);

73

74

76

77 explicit

79 : _M_w(__alloc)

80 { }

81

88

89 explicit

91 const allocator_type& __alloc = allocator_type())

92 : _M_w(__nbits / _S_bits_per_block + (__nbits % _S_bits_per_block > 0),

93 block_type(0), __alloc)

94 {

96 __val &= ~(-1ULL << __nbits);

97 if (__val == 0)

98 return;

99

100 if _GLIBCXX17_CONSTEXPR (sizeof(__val) == sizeof(block_type))

101 _M_w[0] = __val;

102 else

103 {

104 const size_t __n

106 for (size_t __i = 0; __val && __i < __n; ++__i)

107 {

108 _M_w[__i] = static_cast<block_type>(__val);

109 __val >>= _S_bits_per_block;

110 }

111 }

112 }

113

114 void

115 _M_swap(__dynamic_bitset_base& __b) noexcept

116 { this->_M_w.swap(__b._M_w); }

117

118 void

119 _M_clear() noexcept

120 { this->_M_w.clear(); }

121

122 void

123 _M_resize(size_t __nbits, bool __value)

124 {

125 size_t __sz = __nbits / _S_bits_per_block;

126 if (__nbits % _S_bits_per_block > 0)

127 ++__sz;

128 if (__sz != this->_M_w.size())

129 {

130 block_type __val = 0;

131 if (__value)

133 this->_M_w.resize(__sz, __val);

134 }

135 }

136

137 allocator_type

138 _M_get_allocator() const noexcept

140

141 static size_type

142 _S_whichword(size_type __pos) noexcept

143 { return __pos / _S_bits_per_block; }

144

145 static size_type

146 _S_whichbyte(size_type __pos) noexcept

147 { return (__pos % _S_bits_per_block) / __CHAR_BIT__; }

148

149 static size_type

150 _S_whichbit(size_type __pos) noexcept

151 { return __pos % _S_bits_per_block; }

152

153 static block_type

154 _S_maskbit(size_type __pos) noexcept

155 { return (static_cast<block_type>(1)) << _S_whichbit(__pos); }

156

157 block_type&

158 _M_getword(size_type __pos) noexcept

159 { return this->_M_w[_S_whichword(__pos)]; }

160

161 block_type

162 _M_getword(size_type __pos) const noexcept

163 { return this->_M_w[_S_whichword(__pos)]; }

164

165 block_type&

166 _M_hiword() noexcept

167 { return this->_M_w[_M_w.size() - 1]; }

168

169 block_type

170 _M_hiword() const noexcept

171 { return this->_M_w[_M_w.size() - 1]; }

172

173 void

174 _M_do_and(const __dynamic_bitset_base& __x) noexcept

175 {

176 if (__x._M_w.size() == this->_M_w.size())

177 for (size_t __i = 0; __i < this->_M_w.size(); ++__i)

178 this->_M_w[__i] &= __x._M_w[__i];

179 else

180 return;

181 }

182

183 void

184 _M_do_or(const __dynamic_bitset_base& __x) noexcept

185 {

186 if (__x._M_w.size() == this->_M_w.size())

187 for (size_t __i = 0; __i < this->_M_w.size(); ++__i)

188 this->_M_w[__i] |= __x._M_w[__i];

189 else

190 return;

191 }

192

193 void

194 _M_do_xor(const __dynamic_bitset_base& __x) noexcept

195 {

196 if (__x._M_w.size() == this->_M_w.size())

197 for (size_t __i = 0; __i < this->_M_w.size(); ++__i)

198 this->_M_w[__i] ^= __x._M_w[__i];

199 else

200 return;

201 }

202

203 void

204 _M_do_dif(const __dynamic_bitset_base& __x) noexcept

205 {

206 if (__x._M_w.size() == this->_M_w.size())

207 for (size_t __i = 0; __i < this->_M_w.size(); ++__i)

208 this->_M_w[__i] &= ~__x._M_w[__i];

209 else

210 return;

211 }

212

213 void

214 _M_do_left_shift(size_t __shift);

215

216 void

217 _M_do_right_shift(size_t __shift);

218

219 void

220 _M_do_flip() noexcept

221 {

222 for (size_t __i = 0; __i < this->_M_w.size(); ++__i)

223 this->_M_w[__i] = ~this->_M_w[__i];

224 }

225

226 void

227 _M_do_set() noexcept

228 {

229 for (size_t __i = 0; __i < this->_M_w.size(); ++__i)

230 this->_M_w[__i] = static_cast<block_type>(-1);

231 }

232

233 void

234 _M_do_reset() noexcept

235 {

236 std::fill(_M_w.begin(), _M_w.end(), static_cast<block_type>(0));

237 }

238

239 bool

240 _M_is_equal(const __dynamic_bitset_base& __x) const noexcept

241 {

242 if (__x._M_w.size() == this->_M_w.size())

243 {

244 for (size_t __i = 0; __i < this->_M_w.size(); ++__i)

245 if (this->_M_w[__i] != __x._M_w[__i])

246 return false;

247 return true;

248 }

249 else

250 return false;

251 }

252

253 bool

254 _M_is_less(const __dynamic_bitset_base& __x) const noexcept

255 {

256 if (__x._M_w.size() == this->_M_w.size())

257 {

258 for (size_t __i = this->_M_w.size(); __i > 0; --__i)

259 {

260 if (this->_M_w[__i-1] < __x._M_w[__i-1])

261 return true;

262 else if (this->_M_w[__i-1] > __x._M_w[__i-1])

263 return false;

264 }

265 return false;

266 }

267 else

268 return false;

269 }

270

271 size_t

272 _M_are_all_aux() const noexcept

273 {

274 for (size_t __i = 0; __i < this->_M_w.size() - 1; ++__i)

275 if (_M_w[__i] != static_cast<block_type>(-1))

276 return 0;

277 return ((this->_M_w.size() - 1) * _S_bits_per_block

278 + __builtin_popcountll(this->_M_hiword()));

279 }

280

281 bool

282 _M_is_any() const noexcept

283 {

284 for (size_t __i = 0; __i < this->_M_w.size(); ++__i)

285 if (this->_M_w[__i] != static_cast<block_type>(0))

286 return true;

287 return false;

288 }

289

290 bool

291 _M_is_subset_of(const __dynamic_bitset_base& __b) noexcept

292 {

293 if (__b._M_w.size() == this->_M_w.size())

294 {

295 for (size_t __i = 0; __i < this->_M_w.size(); ++__i)

296 if (this->_M_w[__i] != (this->_M_w[__i] | __b._M_w[__i]))

297 return false;

298 return true;

299 }

300 else

301 return false;

302 }

303

304 bool

305 _M_is_proper_subset_of(const __dynamic_bitset_base& __b) const noexcept

306 {

307 if (this->_M_is_subset_of(__b))

308 {

309 if (*this == __b)

310 return false;

311 else

312 return true;

313 }

314 else

315 return false;

316 }

317

318 size_t

319 _M_do_count() const noexcept

320 {

321 size_t __result = 0;

322 for (size_t __i = 0; __i < this->_M_w.size(); ++__i)

323 __result += __builtin_popcountll(this->_M_w[__i]);

324 return __result;

325 }

326

327 size_type

328 _M_size() const noexcept

329 { return this->_M_w.size(); }

330

331 unsigned long

332 _M_do_to_ulong() const;

333

334 unsigned long long

335 _M_do_to_ullong() const;

336

337

338 size_type

339 _M_do_find_first(size_t __not_found) const;

340

341

342 size_type

343 _M_do_find_next(size_t __prev, size_t __not_found) const;

344

345

346 void

347 _M_do_append_block(block_type __block, size_type __pos)

348 {

349 size_t __offset = __pos % _S_bits_per_block;

350 if (__offset == 0)

352 else

353 {

354 this->_M_hiword() |= (__block << __offset);

355 this->_M_w.push_back(__block >> (_S_bits_per_block - __offset));

356 }

357 }

358 };

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417 template<typename _WordT = unsigned long long,

421 {

423 "_WordT not an unsigned integral type");

424

425 public:

426

428 typedef _WordT block_type;

429 typedef _Alloc allocator_type;

430 typedef size_t size_type;

431

432 static const size_type bits_per_block = __CHAR_BIT__ * sizeof(block_type);

433

434 static const size_type npos = static_cast<size_type>(-1);

435

436 private:

437

438

439 void

440 _M_do_sanitize()

441 {

442 size_type __shift = this->_M_Nb % bits_per_block;

443 if (__shift > 0)

444 this->_M_hiword() &= block_type(~(block_type(-1) << __shift));

445 }

446

447

448 void

449 _M_do_fill()

450 {

451 size_type __shift = this->_M_Nb % bits_per_block;

452 if (__shift > 0)

453 this->_M_hiword() |= block_type(block_type(-1) << __shift);

454 }

455

456

457

458

459

461 _M_unchecked_set(size_type __pos) noexcept

462 {

463 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);

464 return *this;

465 }

466

468 _M_unchecked_set(size_type __pos, int __val) noexcept

469 {

470 if (__val)

471 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);

472 else

473 this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);

474 return *this;

475 }

476

478 _M_unchecked_reset(size_type __pos) noexcept

479 {

480 this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);

481 return *this;

482 }

483

485 _M_unchecked_flip(size_type __pos) noexcept

486 {

487 this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);

488 return *this;

489 }

490

491 bool

492 _M_unchecked_test(size_type __pos) const noexcept

493 { return ((this->_M_getword(__pos) & _Base::_S_maskbit(__pos))

494 != static_cast<_WordT>(0)); }

495

496 size_type _M_Nb = 0;

497

498 public:

499

500

501

502

503

504

505

506

507

508

509

510

511

512

514 {

516

517 block_type *_M_wp;

518 size_type _M_bpos;

519

520 public:

522 {

523 this->_M_wp = &__b._M_getword(__pos);

524 this->_M_bpos = _Base::_S_whichbit(__pos);

525 }

526

527

529 operator=(bool __x) noexcept

530 {

531 if (__x)

532 *this->_M_wp |= _Base::_S_maskbit(this->_M_bpos);

533 else

534 *this->_M_wp &= ~_Base::_S_maskbit(this->_M_bpos);

535 return *this;

536 }

537

538

540 operator=(const reference& __j) noexcept

541 {

542 if ((*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)))

543 *this->_M_wp |= _Base::_S_maskbit(this->_M_bpos);

544 else

545 *this->_M_wp &= ~_Base::_S_maskbit(this->_M_bpos);

546 return *this;

547 }

548

549

550 bool

551 operator~() const noexcept

552 { return (*(_M_wp) & _Base::_S_maskbit(this->_M_bpos)) == 0; }

553

554

555 operator bool() const noexcept

556 { return (*(this->_M_wp) & _Base::_S_maskbit(this->_M_bpos)) != 0; }

557

558

560 flip() noexcept

561 {

562 *this->_M_wp ^= _Base::_S_maskbit(this->_M_bpos);

563 return *this;

564 }

565 };

566

568

569 typedef bool const_reference;

570

571

572

573

575

576

577 explicit

580 { }

581

582

583 explicit

584 dynamic_bitset(size_type __nbits, unsigned long long __val = 0ULL,

585 const allocator_type& __alloc = allocator_type())

586 : _Base(__nbits, __val, __alloc),

587 _M_Nb(__nbits)

588 { }

589

591 const allocator_type& __alloc = allocator_type())

592 : _Base(__alloc)

593 { this->append(__il); }

594

595

596

597

598

599

600

601

602

603

604

605

606

607 template<typename _CharT, typename _Traits, typename _Alloc1>

608 explicit

610 typename basic_string<_CharT,_Traits,_Alloc1>::size_type

611 __pos = 0,

612 typename basic_string<_CharT,_Traits,_Alloc1>::size_type

614 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'),

615 const allocator_type& __alloc = allocator_type())

617 {

618 if (__pos > __str.size())

619 __throw_out_of_range(__N("dynamic_bitset::bitset initial position "

620 "not valid"));

621

622

623 this->_M_Nb = (__n > __str.size() ? __str.size() - __pos : __n);

624 this->resize(this->_M_Nb);

625 this->_M_copy_from_string(__str, __pos, __n, __zero, __one);

626 }

627

628

629

630

631

632

633

634

635 explicit

637 const allocator_type& __alloc = allocator_type())

638 : _Base(__builtin_strlen(__str), 0ULL, __alloc),

639 _M_Nb(__builtin_strlen(__str))

640 {

641 this->_M_copy_from_ptr(__str, _M_Nb, 0, _M_Nb);

642 }

643

644

646

647

650 { __b.clear(); }

651

652

653 void

655 {

656 this->_M_swap(__b);

657 std::swap(this->_M_Nb, __b._M_Nb);

658 }

659

660

662

663

667 {

668 static_cast<_Base&>(*this) = static_cast<_Base&&>(__b);

669 _M_Nb = __b._M_Nb;

671 __b._M_Nb = 0;

673 __b._M_Nb = 0;

674 return *this;

675 }

676

677

678

679

680 allocator_type

682 { return this->_M_get_allocator(); }

683

684

685

686

687 void

688 resize(size_type __nbits, bool __value = false)

689 {

690 if (__value)

691 this->_M_do_fill();

692 this->_M_resize(__nbits, __value);

693 this->_M_Nb = __nbits;

694 this->_M_do_sanitize();

695 }

696

697

698

699

700 void

702 {

703 this->_M_clear();

704 this->_M_Nb = 0;

705 }

706

707

708

709

710 void

712 {

713 if (this->size() % bits_per_block == 0)

714 this->_M_do_append_block(block_type(__bit), this->_M_Nb);

715 else

716 this->_M_unchecked_set(this->_M_Nb, __bit);

717 ++this->_M_Nb;

718 }

719

720

721

722

723

724

725 void

727 {

728 this->_M_do_append_block(__block, this->_M_Nb);

729 this->_M_Nb += bits_per_block;

730 }

731

732

733

734

735 void

737 { this->append(__il.begin(), __il.end()); }

738

739

740

741

742 template <typename _BlockInputIterator>

743 void

744 append(_BlockInputIterator __first, _BlockInputIterator __last)

745 {

746 for (; __first != __last; ++__first)

747 this->append(*__first);

748 }

749

750

751

752

753

754

755

756

757

760 {

761 this->_M_do_and(__rhs);

762 return *this;

763 }

764

767 {

768 this->_M_do_and(std::move(__rhs));

769 return *this;

770 }

771

774 {

775 this->_M_do_or(__rhs);

776 return *this;

777 }

778

781 {

782 this->_M_do_xor(__rhs);

783 return *this;

784 }

785

788 {

789 this->_M_do_dif(__rhs);

790 return *this;

791 }

792

793

794

795

796

797

798

799

800

803 {

804 if (__builtin_expect(__pos < this->_M_Nb, 1))

805 {

806 this->_M_do_left_shift(__pos);

807 this->_M_do_sanitize();

808 }

809 else

810 this->_M_do_reset();

811 return *this;

812 }

813

816 {

817 if (__builtin_expect(__pos < this->_M_Nb, 1))

818 this->_M_do_right_shift(__pos);

819 else

820 this->_M_do_reset();

821 return *this;

822 }

823

824

825

826

827

828

831 {

832 this->_M_do_set();

833 this->_M_do_sanitize();

834 return *this;

835 }

836

837

838

839

840

841

842

844 set(size_type __pos, bool __val = true)

845 {

846 if (__pos >= _M_Nb)

847 __throw_out_of_range(__N("dynamic_bitset::set"));

848 return this->_M_unchecked_set(__pos, __val);

849 }

850

851

852

853

856 {

857 this->_M_do_reset();

858 return *this;

859 }

860

861

862

863

864

865

866

867

870 {

871 if (__pos >= _M_Nb)

872 __throw_out_of_range(__N("dynamic_bitset::reset"));

873 return this->_M_unchecked_reset(__pos);

874 }

875

876

877

878

881 {

882 this->_M_do_flip();

883 this->_M_do_sanitize();

884 return *this;

885 }

886

887

888

889

890

891

894 {

895 if (__pos >= _M_Nb)

896 __throw_out_of_range(__N("dynamic_bitset::flip"));

897 return this->_M_unchecked_flip(__pos);

898 }

899

900

904

905

906

907

908

909

910

911

912

913

914 reference

916 { return reference(*this,__pos); }

917

918 const_reference

920 { return _M_unchecked_test(__pos); }

921

922

923

924

925

926

927

928

929 unsigned long

931 { return this->_M_do_to_ulong(); }

932

933

934

935

936

937

938

939 unsigned long long

941 { return this->_M_do_to_ullong(); }

942

943

944

945

946

947

948

949

950

951 template<typename _CharT = char,

955 to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const

956 {

958 _M_copy_to_string(__result, __zero, __one);

959 return __result;

960 }

961

962

963 template<typename _Traits = std::char_traits<char>,

964 typename _CharT = typename _Traits::char_type>

965 void

966 _M_copy_from_ptr(const _CharT*, size_t, size_t, size_t,

967 _CharT __zero = _CharT('0'),

968 _CharT __one = _CharT('1'));

969

970 template<typename _CharT, typename _Traits, typename _Alloc1>

971 void

973 size_t __pos, size_t __n,

974 _CharT __zero = _CharT('0'),

975 _CharT __one = _CharT('1'))

976 {

977 _M_copy_from_ptr<_Traits>(__str.data(), __str.size(), __pos, __n,

978 __zero, __one);

979 }

980

981 template<typename _CharT, typename _Traits, typename _Alloc1>

982 void

984 _CharT __zero = _CharT('0'),

985 _CharT __one = _CharT('1')) const;

986

987

988 size_type

990 { return this->_M_do_count(); }

991

992

993 size_type

995 { return this->_M_Nb; }

996

997

998 size_type

1000 { return this->_M_size(); }

1001

1002

1003 _GLIBCXX_NODISCARD bool

1005 { return (this->_M_Nb == 0); }

1006

1007

1008

1009

1010 constexpr size_type

1013

1014

1015

1016

1017

1018

1019

1020 bool

1022 {

1023 if (__pos >= _M_Nb)

1024 __throw_out_of_range(__N("dynamic_bitset::test"));

1025 return _M_unchecked_test(__pos);

1026 }

1027

1028

1029

1030

1031

1032 bool

1034 { return this->_M_are_all_aux() == _M_Nb; }

1035

1036

1037

1038

1039

1040 bool

1042 { return this->_M_is_any(); }

1043

1044

1045

1046

1047

1048 bool

1050 { return !this->_M_is_any(); }

1051

1052

1053

1057

1061

1062

1063

1064

1065

1066

1067

1068 size_type

1070 { return this->_M_do_find_first(this->_M_Nb); }

1071

1072

1073

1074

1075

1076

1077

1078 size_type

1080 { return this->_M_do_find_next(__prev, this->_M_Nb); }

1081

1082 bool

1084 { return this->_M_is_subset_of(__b); }

1085

1086 bool

1087 is_proper_subset_of(const dynamic_bitset& __b) const

1088 { return this->_M_is_proper_subset_of(__b); }

1089

1090 friend bool

1093 { return __lhs._M_Nb == __rhs._M_Nb && __lhs._M_is_equal(__rhs); }

1094

1095 friend bool

1098 { return __lhs._M_is_less(__rhs) || __lhs._M_Nb < __rhs._M_Nb; }

1099 };

1100

1101 template<typename _WordT, typename _Alloc>

1102 template<typename _CharT, typename _Traits, typename _Alloc1>

1103 inline void

1104 dynamic_bitset<_WordT, _Alloc>::

1106 _CharT __zero, _CharT __one) const

1107 {

1108 __str.assign(_M_Nb, __zero);

1109 for (size_t __i = _M_Nb; __i > 0; --__i)

1110 if (_M_unchecked_test(__i - 1))

1111 _Traits::assign(__str[_M_Nb - __i], __one);

1112 }

1113

1114

1115

1116

1117

1118 template<typename _WordT, typename _Alloc>

1119 inline bool

1122 { return !(__lhs == __rhs); }

1123

1124 template<typename _WordT, typename _Alloc>

1128 { return !(__lhs > __rhs); }

1129

1130 template<typename _WordT, typename _Alloc>

1131 inline bool

1134 { return __rhs < __lhs; }

1135

1136 template<typename _WordT, typename _Alloc>

1137 inline bool

1140 { return !(__lhs < __rhs); }

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153 template<typename _WordT, typename _Alloc>

1154 inline dynamic_bitset<_WordT, _Alloc>

1157 {

1159 __result &= __y;

1160 return __result;

1161 }

1162

1163 template<typename _WordT, typename _Alloc>

1164 inline dynamic_bitset<_WordT, _Alloc>

1167 {

1169 __result |= __y;

1170 return __result;

1171 }

1172

1173 template <typename _WordT, typename _Alloc>

1174 inline dynamic_bitset<_WordT, _Alloc>

1177 {

1179 __result ^= __y;

1180 return __result;

1181 }

1182

1183 template <typename _WordT, typename _Alloc>

1184 inline dynamic_bitset<_WordT, _Alloc>

1187 {

1189 __result -= __y;

1190 return __result;

1191 }

1192

1193

1194

1195 template <typename _CharT, typename _Traits,

1196 typename _WordT, typename _Alloc>

1199 const dynamic_bitset<_WordT, _Alloc>& __x)

1200 {

1202

1204 __x._M_copy_to_string(__tmp, __ct.widen('0'), __ct.widen('1'));

1205 return __os << __tmp;

1206 }

1207

1208

1209

1210}

1211

1212_GLIBCXX_END_NAMESPACE_VERSION

1213}

1214

1216

1217#endif

constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept

Convert a value to an rvalue.

constexpr const _Tp & min(const _Tp &, const _Tp &)

This does what you think it does.

bool operator>=(const dynamic_bitset< _WordT, _Alloc > &__lhs, const dynamic_bitset< _WordT, _Alloc > &__rhs)

These comparisons for equality/inequality are, well, bitwise.

std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const dynamic_bitset< _WordT, _Alloc > &__x)

Stream output operator for dynamic_bitset.

bool operator>(const dynamic_bitset< _WordT, _Alloc > &__lhs, const dynamic_bitset< _WordT, _Alloc > &__rhs)

These comparisons for equality/inequality are, well, bitwise.

bool operator<=(const dynamic_bitset< _WordT, _Alloc > &__lhs, const dynamic_bitset< _WordT, _Alloc > &__rhs)

These comparisons for equality/inequality are, well, bitwise.

dynamic_bitset< _WordT, _Alloc > operator-(const dynamic_bitset< _WordT, _Alloc > &__x, const dynamic_bitset< _WordT, _Alloc > &__y)

Global bitwise operations on bitsets.

ISO C++ entities toplevel namespace is std.

constexpr bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept

Global bitwise operations on bitsets.

constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept

Global bitwise operations on bitsets.

constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept

Global bitwise operations on bitsets.

Template class basic_ostream.

Properties of fundamental types.

static constexpr _Tp max() noexcept

is_nothrow_move_assignable

The standard allocator, as per C++03 [20.4.1].

Basis for explicit traits specializations.

Managing sequences of characters and character-like objects.

const _CharT * data() const noexcept

Return const pointer to contents.

basic_string & assign(const basic_string &__str)

Set value to contents of another string.

size_type size() const noexcept

Returns the number of characters in the string, not including any null-termination.

locale getloc() const

Locale access.

char_type widen(char __c) const

Widen char to char_type.

Primary class template ctype facet.

A standard container which offers fixed time access to individual elements in any order.

constexpr void push_back(const value_type &__x)

Add data to the end of the vector.

constexpr iterator end() noexcept

constexpr iterator begin() noexcept

constexpr void swap(vector &__x) noexcept

Swaps data with another vector.

constexpr void resize(size_type __new_size)

Resizes the vector to the specified number of elements.

constexpr void clear() noexcept

constexpr allocator_type get_allocator() const noexcept

Get a copy of the memory allocation object.

constexpr size_type size() const noexcept

std::vector< block_type, allocator_type > _M_w

0 is the least significant word.

The dynamic_bitset class represents a sequence of bits.

size_type find_next(size_t __prev) const

Finds the index of the next "on" bit after prev.

dynamic_bitset & reset()

Sets every bit to false.

dynamic_bitset & operator>>=(size_type __pos)

Operations on dynamic_bitsets.

dynamic_bitset(size_type __nbits, unsigned long long __val=0ULL, const allocator_type &__alloc=allocator_type())

Initial bits bitwise-copied from a single word (others set to zero).

dynamic_bitset(const dynamic_bitset &)=default

Copy constructor.

dynamic_bitset & operator<<=(size_type __pos)

Operations on dynamic_bitsets.

dynamic_bitset(const allocator_type &__alloc)

All bits set to zero.

void append(block_type __block)

Append a block.

unsigned long to_ulong() const

Returns a numerical interpretation of the dynamic_bitset.

dynamic_bitset & set()

Sets every bit to true.

dynamic_bitset & flip(size_type __pos)

Toggles a given bit to its opposite value.

dynamic_bitset & operator=(dynamic_bitset &&__b) noexcept(std::is_nothrow_move_assignable< _Base >::value)

Move assignment operator.

void swap(dynamic_bitset &__b) noexcept

Swap with another bitset.

dynamic_bitset & operator-=(const dynamic_bitset &__rhs)

Operations on dynamic_bitsets.

void push_back(bool __bit)

Push a bit onto the high end of the bitset.

dynamic_bitset()=default

All bits set to zero.

void resize(size_type __nbits, bool __value=false)

Resize the bitset.

dynamic_bitset operator<<(size_type __pos) const

Self-explanatory.

dynamic_bitset(const char *__str, const allocator_type &__alloc=allocator_type())

Construct from a string.

bool none() const

Tests whether any of the bits are on.

allocator_type get_allocator() const noexcept

Return the allocator for the bitset.

constexpr size_type max_size() noexcept

Returns the maximum size of a dynamic_bitset object having the same type as *this....

const_reference operator[](size_type __pos) const

Array-indexing support.

reference operator[](size_type __pos)

Array-indexing support.

dynamic_bitset & operator|=(const dynamic_bitset &__rhs)

Operations on dynamic_bitsets.

dynamic_bitset(const std::basic_string< _CharT, _Traits, _Alloc1 > &__str, typename basic_string< _CharT, _Traits, _Alloc1 >::size_type __pos=0, typename basic_string< _CharT, _Traits, _Alloc1 >::size_type __n=std::basic_string< _CharT, _Traits, _Alloc1 >::npos, _CharT __zero=_CharT('0'), _CharT __one=_CharT('1'), const allocator_type &__alloc=allocator_type())

Use a subset of a string.

size_type num_blocks() const noexcept

Returns the total number of blocks.

dynamic_bitset & operator&=(dynamic_bitset &&__rhs)

Operations on dynamic_bitsets.

dynamic_bitset & operator&=(const dynamic_bitset &__rhs)

Operations on dynamic_bitsets.

size_type find_first() const

Finds the index of the first "on" bit.

size_type count() const noexcept

Returns the number of bits which are set.

size_type size() const noexcept

Returns the total number of bits.

dynamic_bitset(dynamic_bitset &&__b) noexcept

Move constructor.

void append(_BlockInputIterator __first, _BlockInputIterator __last)

Append an iterator range of blocks.

dynamic_bitset & reset(size_type __pos)

Sets a given bit to false.

std::basic_string< _CharT, _Traits, _Alloc1 > to_string(_CharT __zero=_CharT('0'), _CharT __one=_CharT('1')) const

Returns a character interpretation of the dynamic_bitset.

unsigned long long to_ullong() const

Returns a numerical interpretation of the dynamic_bitset.

dynamic_bitset & flip()

Toggles every bit to its opposite value.

bool any() const

Tests whether any of the bits are on.

bool test(size_type __pos) const

Tests the value of a bit.

bool empty() const noexcept

Returns true if the dynamic_bitset is empty.

dynamic_bitset & set(size_type __pos, bool __val=true)

Sets a given bit to a particular value.

dynamic_bitset & operator^=(const dynamic_bitset &__rhs)

Operations on dynamic_bitsets.

dynamic_bitset operator>>(size_type __pos) const

Self-explanatory.

void clear()

Clear the bitset.

dynamic_bitset operator~() const

See the no-argument flip().

dynamic_bitset & operator=(const dynamic_bitset &)=default

Copy assignment operator.

bool all() const

Tests whether all the bits are on.