Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

958 lines
23 KiB

  1. #pragma once
  2. #ifndef _STLVEC_H_
  3. #define _STLVEC_H_
  4. //#include <climits>
  5. //#include <memory>
  6. //#include <stdexcept>
  7. #include <limits.h>
  8. #include <stlmem.h>
  9. #include <stlxutil.h>
  10. #ifdef _MSC_VER
  11. #pragma pack(push,8)
  12. #endif /* _MSC_VER */
  13. _STD_BEGIN
  14. // TEMPLATE CLASS vector
  15. template<class _Ty, class _A = allocator<_Ty> >
  16. class vector
  17. {
  18. public:
  19. typedef vector<_Ty, _A> _Myt;
  20. typedef _A allocator_type;
  21. typedef _A::size_type size_type;
  22. typedef _A::difference_type difference_type;
  23. typedef _A::pointer _Tptr;
  24. typedef _A::const_pointer _Ctptr;
  25. typedef _A::reference reference;
  26. typedef _A::const_reference const_reference;
  27. typedef _A::value_type value_type;
  28. typedef _Tptr iterator;
  29. typedef _Ctptr const_iterator;
  30. typedef reverse_iterator<const_iterator, value_type, const_reference,
  31. _Ctptr, difference_type>
  32. const_reverse_iterator;
  33. typedef reverse_iterator<iterator, value_type,reference, _Tptr,
  34. difference_type>
  35. reverse_iterator;
  36. explicit vector(const _A& _Al = _A())
  37. : allocator(_Al), _First(0), _Last(0), _End(0)
  38. {
  39. }
  40. explicit vector(size_type _N, const _Ty& _V = _Ty(),
  41. const _A& _Al = _A())
  42. : allocator(_Al)
  43. {
  44. _First = allocator.allocate(_N, (void *)0);
  45. _Ufill(_First, _N, _V);
  46. _Last = _First + _N;
  47. _End = _Last;
  48. }
  49. vector(const _Myt& _X)
  50. : allocator(_X.allocator)
  51. {
  52. _First = allocator.allocate(_X.size(), (void *)0);
  53. _Last = _Ucopy(_X.begin(), _X.end(), _First);
  54. _End = _Last;
  55. }
  56. typedef const_iterator _It;
  57. vector(_It _F, _It _L, const _A& _Al = _A())
  58. : allocator(_Al), _First(0), _Last(0), _End(0)
  59. {
  60. insert(begin(), _F, _L);
  61. }
  62. ~vector()
  63. {
  64. _Destroy(_First, _Last);
  65. allocator.deallocate(_First, _End - _First);
  66. _First = 0, _Last = 0, _End = 0;
  67. }
  68. _Myt& operator=(const _Myt& _X)
  69. {
  70. if (this == &_X)
  71. ;
  72. else if (_X.size() <= size())
  73. {
  74. iterator _S = copy(_X.begin(), _X.end(), _First);
  75. _Destroy(_S, _Last);
  76. _Last = _First + _X.size();
  77. }
  78. else if (_X.size() <= capacity())
  79. {
  80. const_iterator _S = _X.begin() + size();
  81. copy(_X.begin(), _S, _First);
  82. _Ucopy(_S, _X.end(), _Last);
  83. _Last = _First + _X.size();
  84. }
  85. else
  86. {
  87. _Destroy(_First, _Last);
  88. allocator.deallocate(_First, _End - _First);
  89. _First = allocator.allocate(_X.size(), (void *)0);
  90. _Last = _Ucopy(_X.begin(), _X.end(),
  91. _First);
  92. _End = _Last;
  93. }
  94. return (*this);
  95. }
  96. void reserve(size_type _N)
  97. {
  98. if (capacity() < _N)
  99. {
  100. iterator _S = allocator.allocate(_N, (void *)0);
  101. _Ucopy(_First, _Last, _S);
  102. _Destroy(_First, _Last);
  103. allocator.deallocate(_First, _End - _First);
  104. _End = _S + _N;
  105. _Last = _S + size();
  106. _First = _S;
  107. }
  108. }
  109. size_type capacity() const
  110. {
  111. return (_First == 0 ? 0 : _End - _First);
  112. }
  113. iterator begin()
  114. {
  115. return (_First);
  116. }
  117. const_iterator begin() const
  118. {
  119. return ((const_iterator)_First);
  120. }
  121. iterator end()
  122. {
  123. return (_Last);
  124. }
  125. const_iterator end() const
  126. {
  127. return ((const_iterator)_Last);
  128. }
  129. reverse_iterator rbegin()
  130. {
  131. return (reverse_iterator(end()));
  132. }
  133. const_reverse_iterator rbegin() const
  134. {
  135. return (const_reverse_iterator(end()));
  136. }
  137. reverse_iterator rend()
  138. {
  139. return (reverse_iterator(begin()));
  140. }
  141. const_reverse_iterator rend() const
  142. {
  143. return (const_reverse_iterator(begin()));
  144. }
  145. void resize(size_type _N, const _Ty& _X = _Ty())
  146. {
  147. if (size() < _N)
  148. insert(end(), _N - size(), _X);
  149. else if (_N < size())
  150. erase(begin() + _N, end());
  151. }
  152. size_type size() const
  153. {
  154. return (_First == 0 ? 0 : _Last - _First);
  155. }
  156. size_type max_size() const
  157. {
  158. return (allocator.max_size());
  159. }
  160. bool empty() const
  161. {
  162. return (size() == 0);
  163. }
  164. _A get_allocator() const
  165. {
  166. return (allocator);
  167. }
  168. const_reference at(size_type _P) const
  169. {
  170. ASSERT (_P < size());
  171. return (*(begin() + _P));
  172. }
  173. reference at(size_type _P)
  174. {
  175. ASSERT (_P < size());
  176. return (*(begin() + _P));
  177. }
  178. const_reference operator[](size_type _P) const
  179. {
  180. return (*(begin() + _P));
  181. }
  182. reference operator[](size_type _P)
  183. {
  184. return (*(begin() + _P));
  185. }
  186. reference front()
  187. {
  188. return (*begin());
  189. }
  190. const_reference front() const
  191. {
  192. return (*begin());
  193. }
  194. reference back()
  195. {
  196. return (*(end() - 1));
  197. }
  198. const_reference back() const
  199. {
  200. return (*(end() - 1));
  201. }
  202. void push_back(const _Ty& _X)
  203. {
  204. insert(end(), _X);
  205. }
  206. void pop_back()
  207. {
  208. erase(end() - 1);
  209. }
  210. void assign(_It _F, _It _L)
  211. {
  212. erase(begin(), end());
  213. insert(begin(), _F, _L);
  214. }
  215. void assign(size_type _N, const _Ty& _X = _Ty())
  216. {
  217. erase(begin(), end());
  218. insert(begin(), _N, _X);
  219. }
  220. iterator insert(iterator _P, const _Ty& _X = _Ty())
  221. {
  222. size_type _O = _P - begin();
  223. insert(_P, 1, _X);
  224. return (begin() + _O);
  225. }
  226. void insert(iterator _P, size_type _M, const _Ty& _X)
  227. {
  228. if ((size_type)(_End - _Last) < _M)
  229. {
  230. size_type _N = size() + (_M < size() ? size() : _M);
  231. iterator _S = allocator.allocate(_N, (void *)0);
  232. iterator _Q = _Ucopy(_First, _P, _S);
  233. _Ufill(_Q, _M, _X);
  234. _Ucopy(_P, _Last, _Q + _M);
  235. _Destroy(_First, _Last);
  236. allocator.deallocate(_First, _End - _First);
  237. _End = _S + _N;
  238. _Last = _S + size() + _M;
  239. _First = _S;
  240. }
  241. else if ((size_type)(_Last - _P) < _M)
  242. {
  243. _Ucopy(_P, _Last, _P + _M);
  244. _Ufill(_Last, _M - (_Last - _P), _X);
  245. fill(_P, _Last, _X);
  246. _Last += _M;
  247. }
  248. else if (0 < _M)
  249. {
  250. _Ucopy(_Last - _M, _Last, _Last);
  251. copy_backward(_P, _Last - _M, _Last);
  252. fill(_P, _P + _M, _X);
  253. _Last += _M;
  254. }
  255. }
  256. void insert(iterator _P, _It _F, _It _L)
  257. {
  258. difference_type _M = 0;
  259. _Distance(_F, _L, _M);
  260. if (_End - _Last < _M)
  261. {
  262. size_type _N = size() + (_M < (difference_type)size() ? size() : _M);
  263. iterator _S = allocator.allocate(_N, (void *)0);
  264. iterator _Q = _Ucopy(_First, _P, _S);
  265. _Q = _Ucopy(_F, _L, _Q);
  266. _Ucopy(_P, _Last, _Q);
  267. _Destroy(_First, _Last);
  268. allocator.deallocate(_First, _End - _First);
  269. _End = _S + _N;
  270. _Last = _S + size() + _M;
  271. _First = _S;
  272. }
  273. else if (_Last - _P < _M)
  274. {
  275. _Ucopy(_P, _Last, _P + _M);
  276. _Ucopy(_F + (_Last - _P), _L, _Last);
  277. copy(_F, _F + (_Last - _P), _P);
  278. _Last += _M;
  279. }
  280. else if (0 < _M)
  281. {
  282. _Ucopy(_Last - _M, _Last, _Last);
  283. copy_backward(_P, _Last - _M, _Last);
  284. copy(_F, _L, _P);
  285. _Last += _M;
  286. }
  287. }
  288. iterator erase(iterator _P)
  289. {
  290. copy(_P + 1, end(), _P);
  291. _Destroy(_Last - 1, _Last);
  292. --_Last;
  293. return (_P);
  294. }
  295. iterator erase(iterator _F, iterator _L)
  296. {
  297. iterator _S = copy(_L, end(), _F);
  298. _Destroy(_S, end());
  299. _Last = _S;
  300. return (_F);
  301. }
  302. void clear()
  303. {
  304. erase(begin(), end());
  305. }
  306. /*
  307. bool operator==(const _Myt& _X) const
  308. {
  309. return (size() == _X.size()
  310. && equal(begin(), end(), _X.begin()));
  311. }
  312. bool operator!=(const _Myt& _X) const
  313. {
  314. return (!(*this == _X));
  315. }
  316. bool operator<(const _Myt& _X) const
  317. {
  318. return (lexicographical_compare(begin(), end(),
  319. _X.begin(), _X.end()));
  320. }
  321. bool operator>(const _Myt& _X) const
  322. {
  323. return (_X < *this);
  324. }
  325. bool operator<=(const _Myt& _X) const
  326. {
  327. return (!(_X < *this));
  328. }
  329. bool operator>=(const _Myt& _X) const
  330. {
  331. return (!(*this < _X));
  332. }
  333. */
  334. void swap(_Myt& _X)
  335. {
  336. if (allocator == _X.allocator)
  337. {
  338. std::swap(_First, _X._First);
  339. std::swap(_Last, _X._Last);
  340. std::swap(_End, _X._End);
  341. }
  342. else
  343. {
  344. _Myt _Ts = *this; *this = _X, _X = _Ts;
  345. }
  346. }
  347. friend void swap(_Myt& _X, _Myt& _Y)
  348. {
  349. _X.swap(_Y);
  350. }
  351. protected:
  352. void _Destroy(iterator _F, iterator _L)
  353. {
  354. for (; _F != _L; ++_F)
  355. allocator.destroy(_F);
  356. }
  357. iterator _Ucopy(const_iterator _F, const_iterator _L,
  358. iterator _P)
  359. {
  360. for (; _F != _L; ++_P, ++_F)
  361. allocator.construct(_P, *_F);
  362. return (_P);
  363. }
  364. void _Ufill(iterator _F, size_type _N, const _Ty &_X)
  365. {
  366. for (; 0 < _N; --_N, ++_F)
  367. allocator.construct(_F, _X);
  368. }
  369. _A allocator;
  370. iterator _First, _Last, _End;
  371. };
  372. /*
  373. // CLASS vector<_Bool, allocator>
  374. typedef unsigned int _Vbase;
  375. const int _VBITS = CHAR_BIT * sizeof (_Vbase);
  376. typedef allocator<_Vbase> _Bool_allocator;
  377. class vector<_Bool, _Bool_allocator>
  378. {
  379. public:
  380. typedef _Bool_allocator _A;
  381. typedef _Bool _Ty;
  382. typedef vector<_Ty, _A> _Myt;
  383. typedef vector<_Vbase, _A> _Vbtype;
  384. typedef _A allocator_type;
  385. typedef _A::size_type size_type;
  386. typedef _A::difference_type difference_type;
  387. // CLASS reference
  388. class reference
  389. {
  390. public:
  391. reference()
  392. : _Mask(0), _Ptr(0)
  393. {
  394. }
  395. reference(size_t _O, _Vbase *_P)
  396. : _Mask((_Vbase)1 << _O), _Ptr(_P)
  397. {
  398. }
  399. reference& operator=(const reference& _X)
  400. {
  401. return (*this = bool(_X));
  402. }
  403. reference& operator=(bool _V)
  404. {
  405. if (_V)
  406. *_Ptr |= _Mask;
  407. else
  408. *_Ptr &= ~_Mask;
  409. return (*this);
  410. }
  411. void flip()
  412. {
  413. *_Ptr ^= _Mask;
  414. }
  415. bool operator~() const
  416. {
  417. return (!bool(*this));
  418. }
  419. operator bool() const
  420. {
  421. return ((*_Ptr & _Mask) != 0);
  422. }
  423. protected:
  424. _Vbase _Mask, *_Ptr;
  425. };
  426. typedef const reference const_reference;
  427. typedef bool value_type;
  428. // CLASS iterator
  429. class iterator : public _Ranit<_Bool, difference_type>
  430. {
  431. public:
  432. iterator()
  433. : _Off(0), _Ptr(0)
  434. {
  435. }
  436. iterator(size_t _O, _Vbase *_P)
  437. : _Off(_O), _Ptr(_P)
  438. {
  439. }
  440. reference operator*() const
  441. {
  442. return (reference(_Off, _Ptr));
  443. }
  444. iterator& operator++()
  445. {
  446. _Inc();
  447. return (*this);
  448. }
  449. iterator operator++(int)
  450. {
  451. iterator _Tmp = *this;
  452. _Inc();
  453. return (_Tmp);
  454. }
  455. iterator& operator--()
  456. {
  457. _Dec();
  458. return (*this);
  459. }
  460. iterator operator--(int)
  461. {
  462. iterator _Tmp = *this;
  463. _Dec();
  464. return (_Tmp);
  465. }
  466. iterator& operator+=(difference_type _N)
  467. {
  468. _Off += (size_t)_N;
  469. _Ptr += _Off / _VBITS;
  470. _Off %= _VBITS;
  471. return (*this);
  472. }
  473. iterator& operator-=(difference_type _N)
  474. {
  475. return (*this += -_N);
  476. }
  477. iterator operator+(difference_type _N) const
  478. {
  479. iterator _Tmp = *this;
  480. return (_Tmp += _N);
  481. }
  482. iterator operator-(difference_type _N) const
  483. {
  484. iterator _Tmp = *this;
  485. return (_Tmp -= _N);
  486. }
  487. difference_type operator-(const iterator _X) const
  488. {
  489. return (_VBITS * (_Ptr - _X._Ptr)
  490. + (difference_type)_Off
  491. - (difference_type)_X._Off);
  492. }
  493. reference operator[](difference_type _N) const
  494. {
  495. return (*(*this + _N));
  496. }
  497. bool operator==(const iterator& _X) const
  498. {
  499. return (_Ptr == _X._Ptr && _Off == _X._Off);
  500. }
  501. bool operator!=(const iterator& _X) const
  502. {
  503. return (!(*this == _X));
  504. }
  505. bool operator<(const iterator& _X) const
  506. {
  507. return (_Ptr < _X._Ptr
  508. || _Ptr == _X._Ptr && _Off < _X._Off);
  509. }
  510. bool operator>(const iterator& _X) const
  511. {
  512. return (_X < *this);
  513. }
  514. bool operator<=(const iterator& _X) const
  515. {
  516. return (!(_X < *this));
  517. }
  518. bool operator>=(const iterator& _X) const
  519. {
  520. return (!(*this < _X));
  521. }
  522. protected:
  523. void _Dec()
  524. {
  525. if (_Off != 0)
  526. --_Off;
  527. else
  528. _Off = _VBITS - 1, --_Ptr;
  529. }
  530. void _Inc()
  531. {
  532. if (_Off < _VBITS - 1)
  533. ++_Off;
  534. else
  535. _Off = 0, ++_Ptr;
  536. }
  537. size_t _Off;
  538. _Vbase *_Ptr;
  539. };
  540. // CLASS const_iterator
  541. class const_iterator : public iterator
  542. {
  543. public:
  544. const_iterator()
  545. : iterator()
  546. {
  547. }
  548. const_iterator(size_t _O, const _Vbase *_P)
  549. : iterator(_O, (_Vbase *)_P)
  550. {
  551. }
  552. const_iterator(const iterator& _X)
  553. : iterator(_X)
  554. {
  555. }
  556. const_reference operator*() const
  557. {
  558. return (reference(_Off, _Ptr));
  559. }
  560. const_iterator& operator++()
  561. {
  562. _Inc();
  563. return (*this);
  564. }
  565. const_iterator operator++(int)
  566. {
  567. const_iterator _Tmp = *this;
  568. _Inc();
  569. return (_Tmp);
  570. }
  571. const_iterator& operator--()
  572. {
  573. _Dec();
  574. return (*this);
  575. }
  576. const_iterator operator--(int)
  577. {
  578. const_iterator _Tmp = *this;
  579. _Dec();
  580. return (_Tmp);
  581. }
  582. const_iterator& operator+=(difference_type _N)
  583. {
  584. _Off += (size_t)_N;
  585. _Ptr += _Off / _VBITS;
  586. _Off %= _VBITS;
  587. return (*this);
  588. }
  589. const_iterator& operator-=(difference_type _N)
  590. {
  591. return (*this += -_N);
  592. }
  593. const_iterator operator+(difference_type _N) const
  594. {
  595. const_iterator _Tmp = *this;
  596. return (_Tmp += _N);
  597. }
  598. const_iterator operator-(difference_type _N) const
  599. {
  600. const_iterator _Tmp = *this;
  601. return (_Tmp -= _N);
  602. }
  603. difference_type operator-(const const_iterator _X) const
  604. {
  605. return (_VBITS * (_Ptr - _X._Ptr)
  606. + (difference_type)_Off
  607. - (difference_type)_X._Off);
  608. }
  609. const_reference operator[](difference_type _N) const
  610. {
  611. return (*(*this + _N));
  612. }
  613. bool operator==(const const_iterator& _X) const
  614. {
  615. return (_Ptr == _X._Ptr && _Off == _X._Off);
  616. }
  617. bool operator!=(const const_iterator& _X) const
  618. {
  619. return (!(*this == _X));
  620. }
  621. bool operator<(const const_iterator& _X) const
  622. {
  623. return (_Ptr < _X._Ptr
  624. || _Ptr == _X._Ptr && _Off < _X._Off);
  625. }
  626. bool operator>(const const_iterator& _X) const
  627. {
  628. return (_X < *this);
  629. }
  630. bool operator<=(const const_iterator& _X) const
  631. {
  632. return (!(_X < *this));
  633. }
  634. bool operator>=(const const_iterator& _X) const
  635. {
  636. return (!(*this < _X));
  637. }
  638. };
  639. typedef reverse_iterator<const_iterator, value_type,
  640. const_reference, const_reference *, difference_type>
  641. const_reverse_iterator;
  642. typedef reverse_iterator<iterator, value_type,
  643. reference, reference *, difference_type>
  644. reverse_iterator;
  645. explicit vector(const _A& _Al = _A())
  646. : _Size(0), _Vec(_Al)
  647. {
  648. }
  649. explicit vector(size_type _N, const bool _V = false,
  650. const _A& _Al = _A())
  651. : _Vec(_Nw(_N), _V ? -1 : 0, _Al)
  652. {
  653. _Trim(_N);
  654. }
  655. typedef const_iterator _It;
  656. vector(_It _F, _It _L, const _A& _Al = _A())
  657. : _Size(0), _Vec(_Al)
  658. {
  659. insert(begin(), _F, _L);
  660. }
  661. ~vector()
  662. {
  663. _Size = 0;
  664. }
  665. void reserve(size_type _N)
  666. {
  667. _Vec.reserve(_Nw(_N));
  668. }
  669. size_type capacity() const
  670. {
  671. return (_Vec.capacity() * _VBITS);
  672. }
  673. iterator begin()
  674. {
  675. return (iterator(0, _Vec.begin()));
  676. }
  677. const_iterator begin() const
  678. {
  679. return (const_iterator(0, _Vec.begin()));
  680. }
  681. iterator end()
  682. {
  683. iterator _Tmp = begin();
  684. if (0 < _Size)
  685. _Tmp += _Size;
  686. return (_Tmp);
  687. }
  688. const_iterator end() const
  689. {
  690. const_iterator _Tmp = begin();
  691. if (0 < _Size)
  692. _Tmp += _Size;
  693. return (_Tmp);
  694. }
  695. reverse_iterator rbegin()
  696. {
  697. return (reverse_iterator(end()));
  698. }
  699. const_reverse_iterator rbegin() const
  700. {
  701. return (const_reverse_iterator(end()));
  702. }
  703. reverse_iterator rend()
  704. {
  705. return (reverse_iterator(begin()));
  706. }
  707. const_reverse_iterator rend() const
  708. {
  709. return (const_reverse_iterator(begin()));
  710. }
  711. void resize(size_type _N, bool _X = false)
  712. {
  713. if (size() < _N)
  714. insert(end(), _N - size(), _X);
  715. else if (_N < size())
  716. erase(begin() + _N, end());
  717. }
  718. size_type size() const
  719. {
  720. return (_Size);
  721. }
  722. size_type max_size() const
  723. {
  724. return (_Vec.max_size() * _VBITS);
  725. }
  726. bool empty() const
  727. {
  728. return (size() == 0);
  729. }
  730. _A get_allocator() const
  731. {
  732. return (_Vec.get_allocator());
  733. }
  734. const_reference at(size_type _P) const
  735. {
  736. if (size() <= _P)
  737. _Xran();
  738. return (*(begin() + _P));
  739. }
  740. reference at(size_type _P)
  741. {
  742. if (size() <= _P)
  743. _Xran();
  744. return (*(begin() + _P));
  745. }
  746. const_reference operator[](size_type _P) const
  747. {
  748. return (*(begin() + _P));
  749. }
  750. reference operator[](size_type _P)
  751. {
  752. return (*(begin() + _P));
  753. }
  754. reference front()
  755. {
  756. return (*begin());
  757. }
  758. const_reference front() const
  759. {
  760. return (*begin());
  761. }
  762. reference back()
  763. {
  764. return (*(end() - 1));
  765. }
  766. const_reference back() const
  767. {
  768. return (*(end() - 1));
  769. }
  770. void push_back(const bool _X)
  771. {
  772. insert(end(), _X);
  773. }
  774. void pop_back()
  775. {
  776. erase(end() - 1);
  777. }
  778. void assign(_It _F, _It _L)
  779. {
  780. erase(begin(), end());
  781. insert(begin(), _F, _L);
  782. }
  783. void assign(size_type _N, const bool _X = false)
  784. {
  785. erase(begin(), end());
  786. insert(begin(), _N, _X);
  787. }
  788. iterator insert(iterator _P, const bool _X = false)
  789. {
  790. size_type _O = _P - begin();
  791. insert(_P, 1, _X);
  792. return (begin() + _O);
  793. }
  794. void insert(iterator _P, size_type _M, const bool _X)
  795. {
  796. if (0 < _M)
  797. {
  798. if (capacity() - size() < _M)
  799. {
  800. size_type _O = _P - begin();
  801. _Vec.resize(_Nw(size() + _M), 0);
  802. _P = begin() + _O;
  803. }
  804. copy_backward(_P, end(), end() + _M);
  805. fill(_P, _P + _M, _X);
  806. _Size += _M;
  807. }
  808. }
  809. void insert(iterator _P, _It _F, _It _L)
  810. {
  811. size_type _M = 0;
  812. _Distance(_F, _L, _M);
  813. if (0 < _M)
  814. {
  815. if (capacity() - size() < _M)
  816. {
  817. size_type _O = _P - begin();
  818. _Vec.resize(_Nw(size() + _M), 0);
  819. _P = begin() + _O;
  820. }
  821. copy_backward(_P, end(), end() + _M);
  822. copy(_F, _L, _P);
  823. _Size += _M;
  824. }
  825. }
  826. iterator erase(iterator _P)
  827. {
  828. copy(_P + 1, end(), _P);
  829. _Trim(_Size - 1);
  830. return (_P);
  831. }
  832. iterator erase(iterator _F, iterator _L)
  833. {
  834. iterator _S = copy(_L, end(), _F);
  835. _Trim(_S - begin());
  836. return (_F);
  837. }
  838. void clear()
  839. {
  840. erase(begin(), end());
  841. }
  842. void flip()
  843. {
  844. for (_Vbtype::iterator _S = _Vec.begin();
  845. _S != _Vec.end(); ++_S)
  846. *_S = ~*_S;
  847. _Trim(_Size);
  848. }
  849. bool operator==(const _Myt& _X) const
  850. {
  851. return (_Size == _X._Size && _Vec == _X._Vec);
  852. }
  853. bool operator!=(const _Myt& _X) const
  854. {
  855. return (!(*this == _X));
  856. }
  857. bool operator<(const _Myt& _X) const
  858. {
  859. return (_Size < _X._Size
  860. || _Size == _X._Size && _Vec < _X._Vec);
  861. }
  862. bool operator>(const _Myt& _X) const
  863. {
  864. return (_X < *this);
  865. }
  866. bool operator<=(const _Myt& _X) const
  867. {
  868. return (!(_X < *this));
  869. }
  870. bool operator>=(const _Myt& _X) const
  871. {
  872. return (!(*this < _X));
  873. }
  874. void swap(_Myt& _X)
  875. {
  876. std::swap(_Size, _X._Size);
  877. _Vec.swap(_X._Vec);
  878. }
  879. friend void swap(_Myt& _X, _Myt& _Y)
  880. {
  881. _X.swap(_Y);
  882. }
  883. static void swap(reference _X, reference _Y)
  884. {
  885. bool _V = _X;
  886. _X = _Y;
  887. _Y = _V;
  888. }
  889. protected:
  890. static size_type _Nw(size_type _N)
  891. {
  892. return ((_N + _VBITS - 1) / _VBITS);
  893. }
  894. void _Trim(size_type _N)
  895. {
  896. size_type _M = _Nw(_N);
  897. if (_M < _Vec.size())
  898. _Vec.erase(_Vec.begin() + _M, _Vec.end());
  899. _Size = _N;
  900. _N %= _VBITS;
  901. if (0 < _N)
  902. _Vec[_M - 1] &= ((_Vbase)1 << _N) - 1;
  903. }
  904. void _Xran() const
  905. {
  906. _THROW(out_of_range, "invalid vector<bool> subscript");
  907. }
  908. size_type _Size;
  909. _Vbtype _Vec;
  910. };
  911. typedef vector<_Bool, _Bool_allocator> _Bvector;
  912. */
  913. _STD_END
  914. #ifdef _MSC_VER
  915. #pragma pack(pop)
  916. #endif /* _MSC_VER */
  917. #endif /* _STLVEC_H_ */
  918. /*
  919. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  920. * Consult your license regarding permissions and restrictions.
  921. */
  922. /*
  923. * This file is derived from software bearing the following
  924. * restrictions:
  925. *
  926. * Copyright (c) 1994
  927. * Hewlett-Packard Company
  928. *
  929. * Permission to use, copy, modify, distribute and sell this
  930. * software and its documentation for any purpose is hereby
  931. * granted without fee, provided that the above copyright notice
  932. * appear in all copies and that both that copyright notice and
  933. * this permission notice appear in supporting documentation.
  934. * Hewlett-Packard Company makes no representations about the
  935. * suitability of this software for any purpose. It is provided
  936. * "as is" without express or implied warranty.
  937. */