stl_iterator.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. // Iterators -*- C++ -*-
  2. // Copyright (C) 2001-2019 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /*
  21. *
  22. * Copyright (c) 1994
  23. * Hewlett-Packard Company
  24. *
  25. * Permission to use, copy, modify, distribute and sell this software
  26. * and its documentation for any purpose is hereby granted without fee,
  27. * provided that the above copyright notice appear in all copies and
  28. * that both that copyright notice and this permission notice appear
  29. * in supporting documentation. Hewlett-Packard Company makes no
  30. * representations about the suitability of this software for any
  31. * purpose. It is provided "as is" without express or implied warranty.
  32. *
  33. *
  34. * Copyright (c) 1996-1998
  35. * Silicon Graphics Computer Systems, Inc.
  36. *
  37. * Permission to use, copy, modify, distribute and sell this software
  38. * and its documentation for any purpose is hereby granted without fee,
  39. * provided that the above copyright notice appear in all copies and
  40. * that both that copyright notice and this permission notice appear
  41. * in supporting documentation. Silicon Graphics makes no
  42. * representations about the suitability of this software for any
  43. * purpose. It is provided "as is" without express or implied warranty.
  44. */
  45. /** @file bits/stl_iterator.h
  46. * This is an internal header file, included by other library headers.
  47. * Do not attempt to use it directly. @headername{iterator}
  48. *
  49. * This file implements reverse_iterator, back_insert_iterator,
  50. * front_insert_iterator, insert_iterator, __normal_iterator, and their
  51. * supporting functions and overloaded operators.
  52. */
  53. #ifndef _STL_ITERATOR_H
  54. #define _STL_ITERATOR_H 1
  55. #include <bits/cpp_type_traits.h>
  56. #include <ext/type_traits.h>
  57. #include <bits/move.h>
  58. #include <bits/ptr_traits.h>
  59. #if __cplusplus >= 201103L
  60. # include <type_traits>
  61. #endif
  62. #if __cplusplus > 201402L
  63. # define __cpp_lib_array_constexpr 201603
  64. #endif
  65. namespace std _GLIBCXX_VISIBILITY(default)
  66. {
  67. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  68. /**
  69. * @addtogroup iterators
  70. * @{
  71. */
  72. // 24.4.1 Reverse iterators
  73. /**
  74. * Bidirectional and random access iterators have corresponding reverse
  75. * %iterator adaptors that iterate through the data structure in the
  76. * opposite direction. They have the same signatures as the corresponding
  77. * iterators. The fundamental relation between a reverse %iterator and its
  78. * corresponding %iterator @c i is established by the identity:
  79. * @code
  80. * &*(reverse_iterator(i)) == &*(i - 1)
  81. * @endcode
  82. *
  83. * <em>This mapping is dictated by the fact that while there is always a
  84. * pointer past the end of an array, there might not be a valid pointer
  85. * before the beginning of an array.</em> [24.4.1]/1,2
  86. *
  87. * Reverse iterators can be tricky and surprising at first. Their
  88. * semantics make sense, however, and the trickiness is a side effect of
  89. * the requirement that the iterators must be safe.
  90. */
  91. template<typename _Iterator>
  92. class reverse_iterator
  93. : public iterator<typename iterator_traits<_Iterator>::iterator_category,
  94. typename iterator_traits<_Iterator>::value_type,
  95. typename iterator_traits<_Iterator>::difference_type,
  96. typename iterator_traits<_Iterator>::pointer,
  97. typename iterator_traits<_Iterator>::reference>
  98. {
  99. protected:
  100. _Iterator current;
  101. typedef iterator_traits<_Iterator> __traits_type;
  102. public:
  103. typedef _Iterator iterator_type;
  104. typedef typename __traits_type::difference_type difference_type;
  105. typedef typename __traits_type::pointer pointer;
  106. typedef typename __traits_type::reference reference;
  107. /**
  108. * The default constructor value-initializes member @p current.
  109. * If it is a pointer, that means it is zero-initialized.
  110. */
  111. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  112. // 235 No specification of default ctor for reverse_iterator
  113. // 1012. reverse_iterator default ctor should value initialize
  114. _GLIBCXX17_CONSTEXPR
  115. reverse_iterator() : current() { }
  116. /**
  117. * This %iterator will move in the opposite direction that @p x does.
  118. */
  119. explicit _GLIBCXX17_CONSTEXPR
  120. reverse_iterator(iterator_type __x) : current(__x) { }
  121. /**
  122. * The copy constructor is normal.
  123. */
  124. _GLIBCXX17_CONSTEXPR
  125. reverse_iterator(const reverse_iterator& __x)
  126. : current(__x.current) { }
  127. #if __cplusplus >= 201103L
  128. reverse_iterator& operator=(const reverse_iterator&) = default;
  129. #endif
  130. /**
  131. * A %reverse_iterator across other types can be copied if the
  132. * underlying %iterator can be converted to the type of @c current.
  133. */
  134. template<typename _Iter>
  135. _GLIBCXX17_CONSTEXPR
  136. reverse_iterator(const reverse_iterator<_Iter>& __x)
  137. : current(__x.base()) { }
  138. /**
  139. * @return @c current, the %iterator used for underlying work.
  140. */
  141. _GLIBCXX17_CONSTEXPR iterator_type
  142. base() const
  143. { return current; }
  144. /**
  145. * @return A reference to the value at @c --current
  146. *
  147. * This requires that @c --current is dereferenceable.
  148. *
  149. * @warning This implementation requires that for an iterator of the
  150. * underlying iterator type, @c x, a reference obtained by
  151. * @c *x remains valid after @c x has been modified or
  152. * destroyed. This is a bug: http://gcc.gnu.org/PR51823
  153. */
  154. _GLIBCXX17_CONSTEXPR reference
  155. operator*() const
  156. {
  157. _Iterator __tmp = current;
  158. return *--__tmp;
  159. }
  160. /**
  161. * @return A pointer to the value at @c --current
  162. *
  163. * This requires that @c --current is dereferenceable.
  164. */
  165. _GLIBCXX17_CONSTEXPR pointer
  166. operator->() const
  167. {
  168. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  169. // 1052. operator-> should also support smart pointers
  170. _Iterator __tmp = current;
  171. --__tmp;
  172. return _S_to_pointer(__tmp);
  173. }
  174. /**
  175. * @return @c *this
  176. *
  177. * Decrements the underlying iterator.
  178. */
  179. _GLIBCXX17_CONSTEXPR reverse_iterator&
  180. operator++()
  181. {
  182. --current;
  183. return *this;
  184. }
  185. /**
  186. * @return The original value of @c *this
  187. *
  188. * Decrements the underlying iterator.
  189. */
  190. _GLIBCXX17_CONSTEXPR reverse_iterator
  191. operator++(int)
  192. {
  193. reverse_iterator __tmp = *this;
  194. --current;
  195. return __tmp;
  196. }
  197. /**
  198. * @return @c *this
  199. *
  200. * Increments the underlying iterator.
  201. */
  202. _GLIBCXX17_CONSTEXPR reverse_iterator&
  203. operator--()
  204. {
  205. ++current;
  206. return *this;
  207. }
  208. /**
  209. * @return A reverse_iterator with the previous value of @c *this
  210. *
  211. * Increments the underlying iterator.
  212. */
  213. _GLIBCXX17_CONSTEXPR reverse_iterator
  214. operator--(int)
  215. {
  216. reverse_iterator __tmp = *this;
  217. ++current;
  218. return __tmp;
  219. }
  220. /**
  221. * @return A reverse_iterator that refers to @c current - @a __n
  222. *
  223. * The underlying iterator must be a Random Access Iterator.
  224. */
  225. _GLIBCXX17_CONSTEXPR reverse_iterator
  226. operator+(difference_type __n) const
  227. { return reverse_iterator(current - __n); }
  228. /**
  229. * @return *this
  230. *
  231. * Moves the underlying iterator backwards @a __n steps.
  232. * The underlying iterator must be a Random Access Iterator.
  233. */
  234. _GLIBCXX17_CONSTEXPR reverse_iterator&
  235. operator+=(difference_type __n)
  236. {
  237. current -= __n;
  238. return *this;
  239. }
  240. /**
  241. * @return A reverse_iterator that refers to @c current - @a __n
  242. *
  243. * The underlying iterator must be a Random Access Iterator.
  244. */
  245. _GLIBCXX17_CONSTEXPR reverse_iterator
  246. operator-(difference_type __n) const
  247. { return reverse_iterator(current + __n); }
  248. /**
  249. * @return *this
  250. *
  251. * Moves the underlying iterator forwards @a __n steps.
  252. * The underlying iterator must be a Random Access Iterator.
  253. */
  254. _GLIBCXX17_CONSTEXPR reverse_iterator&
  255. operator-=(difference_type __n)
  256. {
  257. current += __n;
  258. return *this;
  259. }
  260. /**
  261. * @return The value at @c current - @a __n - 1
  262. *
  263. * The underlying iterator must be a Random Access Iterator.
  264. */
  265. _GLIBCXX17_CONSTEXPR reference
  266. operator[](difference_type __n) const
  267. { return *(*this + __n); }
  268. private:
  269. template<typename _Tp>
  270. static _GLIBCXX17_CONSTEXPR _Tp*
  271. _S_to_pointer(_Tp* __p)
  272. { return __p; }
  273. template<typename _Tp>
  274. static _GLIBCXX17_CONSTEXPR pointer
  275. _S_to_pointer(_Tp __t)
  276. { return __t.operator->(); }
  277. };
  278. //@{
  279. /**
  280. * @param __x A %reverse_iterator.
  281. * @param __y A %reverse_iterator.
  282. * @return A simple bool.
  283. *
  284. * Reverse iterators forward many operations to their underlying base()
  285. * iterators. Others are implemented in terms of one another.
  286. *
  287. */
  288. template<typename _Iterator>
  289. inline _GLIBCXX17_CONSTEXPR bool
  290. operator==(const reverse_iterator<_Iterator>& __x,
  291. const reverse_iterator<_Iterator>& __y)
  292. { return __x.base() == __y.base(); }
  293. template<typename _Iterator>
  294. inline _GLIBCXX17_CONSTEXPR bool
  295. operator<(const reverse_iterator<_Iterator>& __x,
  296. const reverse_iterator<_Iterator>& __y)
  297. { return __y.base() < __x.base(); }
  298. template<typename _Iterator>
  299. inline _GLIBCXX17_CONSTEXPR bool
  300. operator!=(const reverse_iterator<_Iterator>& __x,
  301. const reverse_iterator<_Iterator>& __y)
  302. { return !(__x == __y); }
  303. template<typename _Iterator>
  304. inline _GLIBCXX17_CONSTEXPR bool
  305. operator>(const reverse_iterator<_Iterator>& __x,
  306. const reverse_iterator<_Iterator>& __y)
  307. { return __y < __x; }
  308. template<typename _Iterator>
  309. inline _GLIBCXX17_CONSTEXPR bool
  310. operator<=(const reverse_iterator<_Iterator>& __x,
  311. const reverse_iterator<_Iterator>& __y)
  312. { return !(__y < __x); }
  313. template<typename _Iterator>
  314. inline _GLIBCXX17_CONSTEXPR bool
  315. operator>=(const reverse_iterator<_Iterator>& __x,
  316. const reverse_iterator<_Iterator>& __y)
  317. { return !(__x < __y); }
  318. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  319. // DR 280. Comparison of reverse_iterator to const reverse_iterator.
  320. template<typename _IteratorL, typename _IteratorR>
  321. inline _GLIBCXX17_CONSTEXPR bool
  322. operator==(const reverse_iterator<_IteratorL>& __x,
  323. const reverse_iterator<_IteratorR>& __y)
  324. { return __x.base() == __y.base(); }
  325. template<typename _IteratorL, typename _IteratorR>
  326. inline _GLIBCXX17_CONSTEXPR bool
  327. operator<(const reverse_iterator<_IteratorL>& __x,
  328. const reverse_iterator<_IteratorR>& __y)
  329. { return __y.base() < __x.base(); }
  330. template<typename _IteratorL, typename _IteratorR>
  331. inline _GLIBCXX17_CONSTEXPR bool
  332. operator!=(const reverse_iterator<_IteratorL>& __x,
  333. const reverse_iterator<_IteratorR>& __y)
  334. { return !(__x == __y); }
  335. template<typename _IteratorL, typename _IteratorR>
  336. inline _GLIBCXX17_CONSTEXPR bool
  337. operator>(const reverse_iterator<_IteratorL>& __x,
  338. const reverse_iterator<_IteratorR>& __y)
  339. { return __y < __x; }
  340. template<typename _IteratorL, typename _IteratorR>
  341. inline _GLIBCXX17_CONSTEXPR bool
  342. operator<=(const reverse_iterator<_IteratorL>& __x,
  343. const reverse_iterator<_IteratorR>& __y)
  344. { return !(__y < __x); }
  345. template<typename _IteratorL, typename _IteratorR>
  346. inline _GLIBCXX17_CONSTEXPR bool
  347. operator>=(const reverse_iterator<_IteratorL>& __x,
  348. const reverse_iterator<_IteratorR>& __y)
  349. { return !(__x < __y); }
  350. //@}
  351. #if __cplusplus < 201103L
  352. template<typename _Iterator>
  353. inline typename reverse_iterator<_Iterator>::difference_type
  354. operator-(const reverse_iterator<_Iterator>& __x,
  355. const reverse_iterator<_Iterator>& __y)
  356. { return __y.base() - __x.base(); }
  357. template<typename _IteratorL, typename _IteratorR>
  358. inline typename reverse_iterator<_IteratorL>::difference_type
  359. operator-(const reverse_iterator<_IteratorL>& __x,
  360. const reverse_iterator<_IteratorR>& __y)
  361. { return __y.base() - __x.base(); }
  362. #else
  363. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  364. // DR 685. reverse_iterator/move_iterator difference has invalid signatures
  365. template<typename _IteratorL, typename _IteratorR>
  366. inline _GLIBCXX17_CONSTEXPR auto
  367. operator-(const reverse_iterator<_IteratorL>& __x,
  368. const reverse_iterator<_IteratorR>& __y)
  369. -> decltype(__y.base() - __x.base())
  370. { return __y.base() - __x.base(); }
  371. #endif
  372. template<typename _Iterator>
  373. inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
  374. operator+(typename reverse_iterator<_Iterator>::difference_type __n,
  375. const reverse_iterator<_Iterator>& __x)
  376. { return reverse_iterator<_Iterator>(__x.base() - __n); }
  377. #if __cplusplus >= 201103L
  378. // Same as C++14 make_reverse_iterator but used in C++11 mode too.
  379. template<typename _Iterator>
  380. inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
  381. __make_reverse_iterator(_Iterator __i)
  382. { return reverse_iterator<_Iterator>(__i); }
  383. # if __cplusplus > 201103L
  384. # define __cpp_lib_make_reverse_iterator 201402
  385. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  386. // DR 2285. make_reverse_iterator
  387. /// Generator function for reverse_iterator.
  388. template<typename _Iterator>
  389. inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
  390. make_reverse_iterator(_Iterator __i)
  391. { return reverse_iterator<_Iterator>(__i); }
  392. # endif
  393. #endif
  394. #if __cplusplus >= 201103L
  395. template<typename _Iterator>
  396. auto
  397. __niter_base(reverse_iterator<_Iterator> __it)
  398. -> decltype(__make_reverse_iterator(__niter_base(__it.base())))
  399. { return __make_reverse_iterator(__niter_base(__it.base())); }
  400. template<typename _Iterator>
  401. struct __is_move_iterator<reverse_iterator<_Iterator> >
  402. : __is_move_iterator<_Iterator>
  403. { };
  404. template<typename _Iterator>
  405. auto
  406. __miter_base(reverse_iterator<_Iterator> __it)
  407. -> decltype(__make_reverse_iterator(__miter_base(__it.base())))
  408. { return __make_reverse_iterator(__miter_base(__it.base())); }
  409. #endif
  410. // 24.4.2.2.1 back_insert_iterator
  411. /**
  412. * @brief Turns assignment into insertion.
  413. *
  414. * These are output iterators, constructed from a container-of-T.
  415. * Assigning a T to the iterator appends it to the container using
  416. * push_back.
  417. *
  418. * Tip: Using the back_inserter function to create these iterators can
  419. * save typing.
  420. */
  421. template<typename _Container>
  422. class back_insert_iterator
  423. : public iterator<output_iterator_tag, void, void, void, void>
  424. {
  425. protected:
  426. _Container* container;
  427. public:
  428. /// A nested typedef for the type of whatever container you used.
  429. typedef _Container container_type;
  430. /// The only way to create this %iterator is with a container.
  431. explicit
  432. back_insert_iterator(_Container& __x)
  433. : container(std::__addressof(__x)) { }
  434. /**
  435. * @param __value An instance of whatever type
  436. * container_type::const_reference is; presumably a
  437. * reference-to-const T for container<T>.
  438. * @return This %iterator, for chained operations.
  439. *
  440. * This kind of %iterator doesn't really have a @a position in the
  441. * container (you can think of the position as being permanently at
  442. * the end, if you like). Assigning a value to the %iterator will
  443. * always append the value to the end of the container.
  444. */
  445. #if __cplusplus < 201103L
  446. back_insert_iterator&
  447. operator=(typename _Container::const_reference __value)
  448. {
  449. container->push_back(__value);
  450. return *this;
  451. }
  452. #else
  453. back_insert_iterator&
  454. operator=(const typename _Container::value_type& __value)
  455. {
  456. container->push_back(__value);
  457. return *this;
  458. }
  459. back_insert_iterator&
  460. operator=(typename _Container::value_type&& __value)
  461. {
  462. container->push_back(std::move(__value));
  463. return *this;
  464. }
  465. #endif
  466. /// Simply returns *this.
  467. back_insert_iterator&
  468. operator*()
  469. { return *this; }
  470. /// Simply returns *this. (This %iterator does not @a move.)
  471. back_insert_iterator&
  472. operator++()
  473. { return *this; }
  474. /// Simply returns *this. (This %iterator does not @a move.)
  475. back_insert_iterator
  476. operator++(int)
  477. { return *this; }
  478. };
  479. /**
  480. * @param __x A container of arbitrary type.
  481. * @return An instance of back_insert_iterator working on @p __x.
  482. *
  483. * This wrapper function helps in creating back_insert_iterator instances.
  484. * Typing the name of the %iterator requires knowing the precise full
  485. * type of the container, which can be tedious and impedes generic
  486. * programming. Using this function lets you take advantage of automatic
  487. * template parameter deduction, making the compiler match the correct
  488. * types for you.
  489. */
  490. template<typename _Container>
  491. inline back_insert_iterator<_Container>
  492. back_inserter(_Container& __x)
  493. { return back_insert_iterator<_Container>(__x); }
  494. /**
  495. * @brief Turns assignment into insertion.
  496. *
  497. * These are output iterators, constructed from a container-of-T.
  498. * Assigning a T to the iterator prepends it to the container using
  499. * push_front.
  500. *
  501. * Tip: Using the front_inserter function to create these iterators can
  502. * save typing.
  503. */
  504. template<typename _Container>
  505. class front_insert_iterator
  506. : public iterator<output_iterator_tag, void, void, void, void>
  507. {
  508. protected:
  509. _Container* container;
  510. public:
  511. /// A nested typedef for the type of whatever container you used.
  512. typedef _Container container_type;
  513. /// The only way to create this %iterator is with a container.
  514. explicit front_insert_iterator(_Container& __x)
  515. : container(std::__addressof(__x)) { }
  516. /**
  517. * @param __value An instance of whatever type
  518. * container_type::const_reference is; presumably a
  519. * reference-to-const T for container<T>.
  520. * @return This %iterator, for chained operations.
  521. *
  522. * This kind of %iterator doesn't really have a @a position in the
  523. * container (you can think of the position as being permanently at
  524. * the front, if you like). Assigning a value to the %iterator will
  525. * always prepend the value to the front of the container.
  526. */
  527. #if __cplusplus < 201103L
  528. front_insert_iterator&
  529. operator=(typename _Container::const_reference __value)
  530. {
  531. container->push_front(__value);
  532. return *this;
  533. }
  534. #else
  535. front_insert_iterator&
  536. operator=(const typename _Container::value_type& __value)
  537. {
  538. container->push_front(__value);
  539. return *this;
  540. }
  541. front_insert_iterator&
  542. operator=(typename _Container::value_type&& __value)
  543. {
  544. container->push_front(std::move(__value));
  545. return *this;
  546. }
  547. #endif
  548. /// Simply returns *this.
  549. front_insert_iterator&
  550. operator*()
  551. { return *this; }
  552. /// Simply returns *this. (This %iterator does not @a move.)
  553. front_insert_iterator&
  554. operator++()
  555. { return *this; }
  556. /// Simply returns *this. (This %iterator does not @a move.)
  557. front_insert_iterator
  558. operator++(int)
  559. { return *this; }
  560. };
  561. /**
  562. * @param __x A container of arbitrary type.
  563. * @return An instance of front_insert_iterator working on @p x.
  564. *
  565. * This wrapper function helps in creating front_insert_iterator instances.
  566. * Typing the name of the %iterator requires knowing the precise full
  567. * type of the container, which can be tedious and impedes generic
  568. * programming. Using this function lets you take advantage of automatic
  569. * template parameter deduction, making the compiler match the correct
  570. * types for you.
  571. */
  572. template<typename _Container>
  573. inline front_insert_iterator<_Container>
  574. front_inserter(_Container& __x)
  575. { return front_insert_iterator<_Container>(__x); }
  576. /**
  577. * @brief Turns assignment into insertion.
  578. *
  579. * These are output iterators, constructed from a container-of-T.
  580. * Assigning a T to the iterator inserts it in the container at the
  581. * %iterator's position, rather than overwriting the value at that
  582. * position.
  583. *
  584. * (Sequences will actually insert a @e copy of the value before the
  585. * %iterator's position.)
  586. *
  587. * Tip: Using the inserter function to create these iterators can
  588. * save typing.
  589. */
  590. template<typename _Container>
  591. class insert_iterator
  592. : public iterator<output_iterator_tag, void, void, void, void>
  593. {
  594. protected:
  595. _Container* container;
  596. typename _Container::iterator iter;
  597. public:
  598. /// A nested typedef for the type of whatever container you used.
  599. typedef _Container container_type;
  600. /**
  601. * The only way to create this %iterator is with a container and an
  602. * initial position (a normal %iterator into the container).
  603. */
  604. insert_iterator(_Container& __x, typename _Container::iterator __i)
  605. : container(std::__addressof(__x)), iter(__i) {}
  606. /**
  607. * @param __value An instance of whatever type
  608. * container_type::const_reference is; presumably a
  609. * reference-to-const T for container<T>.
  610. * @return This %iterator, for chained operations.
  611. *
  612. * This kind of %iterator maintains its own position in the
  613. * container. Assigning a value to the %iterator will insert the
  614. * value into the container at the place before the %iterator.
  615. *
  616. * The position is maintained such that subsequent assignments will
  617. * insert values immediately after one another. For example,
  618. * @code
  619. * // vector v contains A and Z
  620. *
  621. * insert_iterator i (v, ++v.begin());
  622. * i = 1;
  623. * i = 2;
  624. * i = 3;
  625. *
  626. * // vector v contains A, 1, 2, 3, and Z
  627. * @endcode
  628. */
  629. #if __cplusplus < 201103L
  630. insert_iterator&
  631. operator=(typename _Container::const_reference __value)
  632. {
  633. iter = container->insert(iter, __value);
  634. ++iter;
  635. return *this;
  636. }
  637. #else
  638. insert_iterator&
  639. operator=(const typename _Container::value_type& __value)
  640. {
  641. iter = container->insert(iter, __value);
  642. ++iter;
  643. return *this;
  644. }
  645. insert_iterator&
  646. operator=(typename _Container::value_type&& __value)
  647. {
  648. iter = container->insert(iter, std::move(__value));
  649. ++iter;
  650. return *this;
  651. }
  652. #endif
  653. /// Simply returns *this.
  654. insert_iterator&
  655. operator*()
  656. { return *this; }
  657. /// Simply returns *this. (This %iterator does not @a move.)
  658. insert_iterator&
  659. operator++()
  660. { return *this; }
  661. /// Simply returns *this. (This %iterator does not @a move.)
  662. insert_iterator&
  663. operator++(int)
  664. { return *this; }
  665. };
  666. /**
  667. * @param __x A container of arbitrary type.
  668. * @param __i An iterator into the container.
  669. * @return An instance of insert_iterator working on @p __x.
  670. *
  671. * This wrapper function helps in creating insert_iterator instances.
  672. * Typing the name of the %iterator requires knowing the precise full
  673. * type of the container, which can be tedious and impedes generic
  674. * programming. Using this function lets you take advantage of automatic
  675. * template parameter deduction, making the compiler match the correct
  676. * types for you.
  677. */
  678. template<typename _Container, typename _Iterator>
  679. inline insert_iterator<_Container>
  680. inserter(_Container& __x, _Iterator __i)
  681. {
  682. return insert_iterator<_Container>(__x,
  683. typename _Container::iterator(__i));
  684. }
  685. // @} group iterators
  686. _GLIBCXX_END_NAMESPACE_VERSION
  687. } // namespace
  688. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  689. {
  690. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  691. // This iterator adapter is @a normal in the sense that it does not
  692. // change the semantics of any of the operators of its iterator
  693. // parameter. Its primary purpose is to convert an iterator that is
  694. // not a class, e.g. a pointer, into an iterator that is a class.
  695. // The _Container parameter exists solely so that different containers
  696. // using this template can instantiate different types, even if the
  697. // _Iterator parameter is the same.
  698. using std::iterator_traits;
  699. using std::iterator;
  700. template<typename _Iterator, typename _Container>
  701. class __normal_iterator
  702. {
  703. protected:
  704. _Iterator _M_current;
  705. typedef iterator_traits<_Iterator> __traits_type;
  706. public:
  707. typedef _Iterator iterator_type;
  708. typedef typename __traits_type::iterator_category iterator_category;
  709. typedef typename __traits_type::value_type value_type;
  710. typedef typename __traits_type::difference_type difference_type;
  711. typedef typename __traits_type::reference reference;
  712. typedef typename __traits_type::pointer pointer;
  713. _GLIBCXX_CONSTEXPR __normal_iterator() _GLIBCXX_NOEXCEPT
  714. : _M_current(_Iterator()) { }
  715. explicit
  716. __normal_iterator(const _Iterator& __i) _GLIBCXX_NOEXCEPT
  717. : _M_current(__i) { }
  718. // Allow iterator to const_iterator conversion
  719. template<typename _Iter>
  720. __normal_iterator(const __normal_iterator<_Iter,
  721. typename __enable_if<
  722. (std::__are_same<_Iter, typename _Container::pointer>::__value),
  723. _Container>::__type>& __i) _GLIBCXX_NOEXCEPT
  724. : _M_current(__i.base()) { }
  725. // Forward iterator requirements
  726. reference
  727. operator*() const _GLIBCXX_NOEXCEPT
  728. { return *_M_current; }
  729. pointer
  730. operator->() const _GLIBCXX_NOEXCEPT
  731. { return _M_current; }
  732. __normal_iterator&
  733. operator++() _GLIBCXX_NOEXCEPT
  734. {
  735. ++_M_current;
  736. return *this;
  737. }
  738. __normal_iterator
  739. operator++(int) _GLIBCXX_NOEXCEPT
  740. { return __normal_iterator(_M_current++); }
  741. // Bidirectional iterator requirements
  742. __normal_iterator&
  743. operator--() _GLIBCXX_NOEXCEPT
  744. {
  745. --_M_current;
  746. return *this;
  747. }
  748. __normal_iterator
  749. operator--(int) _GLIBCXX_NOEXCEPT
  750. { return __normal_iterator(_M_current--); }
  751. // Random access iterator requirements
  752. reference
  753. operator[](difference_type __n) const _GLIBCXX_NOEXCEPT
  754. { return _M_current[__n]; }
  755. __normal_iterator&
  756. operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
  757. { _M_current += __n; return *this; }
  758. __normal_iterator
  759. operator+(difference_type __n) const _GLIBCXX_NOEXCEPT
  760. { return __normal_iterator(_M_current + __n); }
  761. __normal_iterator&
  762. operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
  763. { _M_current -= __n; return *this; }
  764. __normal_iterator
  765. operator-(difference_type __n) const _GLIBCXX_NOEXCEPT
  766. { return __normal_iterator(_M_current - __n); }
  767. const _Iterator&
  768. base() const _GLIBCXX_NOEXCEPT
  769. { return _M_current; }
  770. };
  771. // Note: In what follows, the left- and right-hand-side iterators are
  772. // allowed to vary in types (conceptually in cv-qualification) so that
  773. // comparison between cv-qualified and non-cv-qualified iterators be
  774. // valid. However, the greedy and unfriendly operators in std::rel_ops
  775. // will make overload resolution ambiguous (when in scope) if we don't
  776. // provide overloads whose operands are of the same type. Can someone
  777. // remind me what generic programming is about? -- Gaby
  778. // Forward iterator requirements
  779. template<typename _IteratorL, typename _IteratorR, typename _Container>
  780. inline bool
  781. operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
  782. const __normal_iterator<_IteratorR, _Container>& __rhs)
  783. _GLIBCXX_NOEXCEPT
  784. { return __lhs.base() == __rhs.base(); }
  785. template<typename _Iterator, typename _Container>
  786. inline bool
  787. operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
  788. const __normal_iterator<_Iterator, _Container>& __rhs)
  789. _GLIBCXX_NOEXCEPT
  790. { return __lhs.base() == __rhs.base(); }
  791. template<typename _IteratorL, typename _IteratorR, typename _Container>
  792. inline bool
  793. operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs,
  794. const __normal_iterator<_IteratorR, _Container>& __rhs)
  795. _GLIBCXX_NOEXCEPT
  796. { return __lhs.base() != __rhs.base(); }
  797. template<typename _Iterator, typename _Container>
  798. inline bool
  799. operator!=(const __normal_iterator<_Iterator, _Container>& __lhs,
  800. const __normal_iterator<_Iterator, _Container>& __rhs)
  801. _GLIBCXX_NOEXCEPT
  802. { return __lhs.base() != __rhs.base(); }
  803. // Random access iterator requirements
  804. template<typename _IteratorL, typename _IteratorR, typename _Container>
  805. inline bool
  806. operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
  807. const __normal_iterator<_IteratorR, _Container>& __rhs)
  808. _GLIBCXX_NOEXCEPT
  809. { return __lhs.base() < __rhs.base(); }
  810. template<typename _Iterator, typename _Container>
  811. inline bool
  812. operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
  813. const __normal_iterator<_Iterator, _Container>& __rhs)
  814. _GLIBCXX_NOEXCEPT
  815. { return __lhs.base() < __rhs.base(); }
  816. template<typename _IteratorL, typename _IteratorR, typename _Container>
  817. inline bool
  818. operator>(const __normal_iterator<_IteratorL, _Container>& __lhs,
  819. const __normal_iterator<_IteratorR, _Container>& __rhs)
  820. _GLIBCXX_NOEXCEPT
  821. { return __lhs.base() > __rhs.base(); }
  822. template<typename _Iterator, typename _Container>
  823. inline bool
  824. operator>(const __normal_iterator<_Iterator, _Container>& __lhs,
  825. const __normal_iterator<_Iterator, _Container>& __rhs)
  826. _GLIBCXX_NOEXCEPT
  827. { return __lhs.base() > __rhs.base(); }
  828. template<typename _IteratorL, typename _IteratorR, typename _Container>
  829. inline bool
  830. operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
  831. const __normal_iterator<_IteratorR, _Container>& __rhs)
  832. _GLIBCXX_NOEXCEPT
  833. { return __lhs.base() <= __rhs.base(); }
  834. template<typename _Iterator, typename _Container>
  835. inline bool
  836. operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
  837. const __normal_iterator<_Iterator, _Container>& __rhs)
  838. _GLIBCXX_NOEXCEPT
  839. { return __lhs.base() <= __rhs.base(); }
  840. template<typename _IteratorL, typename _IteratorR, typename _Container>
  841. inline bool
  842. operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs,
  843. const __normal_iterator<_IteratorR, _Container>& __rhs)
  844. _GLIBCXX_NOEXCEPT
  845. { return __lhs.base() >= __rhs.base(); }
  846. template<typename _Iterator, typename _Container>
  847. inline bool
  848. operator>=(const __normal_iterator<_Iterator, _Container>& __lhs,
  849. const __normal_iterator<_Iterator, _Container>& __rhs)
  850. _GLIBCXX_NOEXCEPT
  851. { return __lhs.base() >= __rhs.base(); }
  852. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  853. // According to the resolution of DR179 not only the various comparison
  854. // operators but also operator- must accept mixed iterator/const_iterator
  855. // parameters.
  856. template<typename _IteratorL, typename _IteratorR, typename _Container>
  857. #if __cplusplus >= 201103L
  858. // DR 685.
  859. inline auto
  860. operator-(const __normal_iterator<_IteratorL, _Container>& __lhs,
  861. const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept
  862. -> decltype(__lhs.base() - __rhs.base())
  863. #else
  864. inline typename __normal_iterator<_IteratorL, _Container>::difference_type
  865. operator-(const __normal_iterator<_IteratorL, _Container>& __lhs,
  866. const __normal_iterator<_IteratorR, _Container>& __rhs)
  867. #endif
  868. { return __lhs.base() - __rhs.base(); }
  869. template<typename _Iterator, typename _Container>
  870. inline typename __normal_iterator<_Iterator, _Container>::difference_type
  871. operator-(const __normal_iterator<_Iterator, _Container>& __lhs,
  872. const __normal_iterator<_Iterator, _Container>& __rhs)
  873. _GLIBCXX_NOEXCEPT
  874. { return __lhs.base() - __rhs.base(); }
  875. template<typename _Iterator, typename _Container>
  876. inline __normal_iterator<_Iterator, _Container>
  877. operator+(typename __normal_iterator<_Iterator, _Container>::difference_type
  878. __n, const __normal_iterator<_Iterator, _Container>& __i)
  879. _GLIBCXX_NOEXCEPT
  880. { return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
  881. _GLIBCXX_END_NAMESPACE_VERSION
  882. } // namespace
  883. namespace std _GLIBCXX_VISIBILITY(default)
  884. {
  885. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  886. template<typename _Iterator, typename _Container>
  887. _Iterator
  888. __niter_base(__gnu_cxx::__normal_iterator<_Iterator, _Container> __it)
  889. _GLIBCXX_NOEXCEPT_IF(std::is_nothrow_copy_constructible<_Iterator>::value)
  890. { return __it.base(); }
  891. #if __cplusplus >= 201103L
  892. /**
  893. * @addtogroup iterators
  894. * @{
  895. */
  896. // 24.4.3 Move iterators
  897. /**
  898. * Class template move_iterator is an iterator adapter with the same
  899. * behavior as the underlying iterator except that its dereference
  900. * operator implicitly converts the value returned by the underlying
  901. * iterator's dereference operator to an rvalue reference. Some
  902. * generic algorithms can be called with move iterators to replace
  903. * copying with moving.
  904. */
  905. template<typename _Iterator>
  906. class move_iterator
  907. {
  908. protected:
  909. _Iterator _M_current;
  910. typedef iterator_traits<_Iterator> __traits_type;
  911. typedef typename __traits_type::reference __base_ref;
  912. public:
  913. typedef _Iterator iterator_type;
  914. typedef typename __traits_type::iterator_category iterator_category;
  915. typedef typename __traits_type::value_type value_type;
  916. typedef typename __traits_type::difference_type difference_type;
  917. // NB: DR 680.
  918. typedef _Iterator pointer;
  919. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  920. // 2106. move_iterator wrapping iterators returning prvalues
  921. typedef typename conditional<is_reference<__base_ref>::value,
  922. typename remove_reference<__base_ref>::type&&,
  923. __base_ref>::type reference;
  924. _GLIBCXX17_CONSTEXPR
  925. move_iterator()
  926. : _M_current() { }
  927. explicit _GLIBCXX17_CONSTEXPR
  928. move_iterator(iterator_type __i)
  929. : _M_current(__i) { }
  930. template<typename _Iter>
  931. _GLIBCXX17_CONSTEXPR
  932. move_iterator(const move_iterator<_Iter>& __i)
  933. : _M_current(__i.base()) { }
  934. _GLIBCXX17_CONSTEXPR iterator_type
  935. base() const
  936. { return _M_current; }
  937. _GLIBCXX17_CONSTEXPR reference
  938. operator*() const
  939. { return static_cast<reference>(*_M_current); }
  940. _GLIBCXX17_CONSTEXPR pointer
  941. operator->() const
  942. { return _M_current; }
  943. _GLIBCXX17_CONSTEXPR move_iterator&
  944. operator++()
  945. {
  946. ++_M_current;
  947. return *this;
  948. }
  949. _GLIBCXX17_CONSTEXPR move_iterator
  950. operator++(int)
  951. {
  952. move_iterator __tmp = *this;
  953. ++_M_current;
  954. return __tmp;
  955. }
  956. _GLIBCXX17_CONSTEXPR move_iterator&
  957. operator--()
  958. {
  959. --_M_current;
  960. return *this;
  961. }
  962. _GLIBCXX17_CONSTEXPR move_iterator
  963. operator--(int)
  964. {
  965. move_iterator __tmp = *this;
  966. --_M_current;
  967. return __tmp;
  968. }
  969. _GLIBCXX17_CONSTEXPR move_iterator
  970. operator+(difference_type __n) const
  971. { return move_iterator(_M_current + __n); }
  972. _GLIBCXX17_CONSTEXPR move_iterator&
  973. operator+=(difference_type __n)
  974. {
  975. _M_current += __n;
  976. return *this;
  977. }
  978. _GLIBCXX17_CONSTEXPR move_iterator
  979. operator-(difference_type __n) const
  980. { return move_iterator(_M_current - __n); }
  981. _GLIBCXX17_CONSTEXPR move_iterator&
  982. operator-=(difference_type __n)
  983. {
  984. _M_current -= __n;
  985. return *this;
  986. }
  987. _GLIBCXX17_CONSTEXPR reference
  988. operator[](difference_type __n) const
  989. { return std::move(_M_current[__n]); }
  990. };
  991. // Note: See __normal_iterator operators note from Gaby to understand
  992. // why there are always 2 versions for most of the move_iterator
  993. // operators.
  994. template<typename _IteratorL, typename _IteratorR>
  995. inline _GLIBCXX17_CONSTEXPR bool
  996. operator==(const move_iterator<_IteratorL>& __x,
  997. const move_iterator<_IteratorR>& __y)
  998. { return __x.base() == __y.base(); }
  999. template<typename _Iterator>
  1000. inline _GLIBCXX17_CONSTEXPR bool
  1001. operator==(const move_iterator<_Iterator>& __x,
  1002. const move_iterator<_Iterator>& __y)
  1003. { return __x.base() == __y.base(); }
  1004. template<typename _IteratorL, typename _IteratorR>
  1005. inline _GLIBCXX17_CONSTEXPR bool
  1006. operator!=(const move_iterator<_IteratorL>& __x,
  1007. const move_iterator<_IteratorR>& __y)
  1008. { return !(__x == __y); }
  1009. template<typename _Iterator>
  1010. inline _GLIBCXX17_CONSTEXPR bool
  1011. operator!=(const move_iterator<_Iterator>& __x,
  1012. const move_iterator<_Iterator>& __y)
  1013. { return !(__x == __y); }
  1014. template<typename _IteratorL, typename _IteratorR>
  1015. inline _GLIBCXX17_CONSTEXPR bool
  1016. operator<(const move_iterator<_IteratorL>& __x,
  1017. const move_iterator<_IteratorR>& __y)
  1018. { return __x.base() < __y.base(); }
  1019. template<typename _Iterator>
  1020. inline _GLIBCXX17_CONSTEXPR bool
  1021. operator<(const move_iterator<_Iterator>& __x,
  1022. const move_iterator<_Iterator>& __y)
  1023. { return __x.base() < __y.base(); }
  1024. template<typename _IteratorL, typename _IteratorR>
  1025. inline _GLIBCXX17_CONSTEXPR bool
  1026. operator<=(const move_iterator<_IteratorL>& __x,
  1027. const move_iterator<_IteratorR>& __y)
  1028. { return !(__y < __x); }
  1029. template<typename _Iterator>
  1030. inline _GLIBCXX17_CONSTEXPR bool
  1031. operator<=(const move_iterator<_Iterator>& __x,
  1032. const move_iterator<_Iterator>& __y)
  1033. { return !(__y < __x); }
  1034. template<typename _IteratorL, typename _IteratorR>
  1035. inline _GLIBCXX17_CONSTEXPR bool
  1036. operator>(const move_iterator<_IteratorL>& __x,
  1037. const move_iterator<_IteratorR>& __y)
  1038. { return __y < __x; }
  1039. template<typename _Iterator>
  1040. inline _GLIBCXX17_CONSTEXPR bool
  1041. operator>(const move_iterator<_Iterator>& __x,
  1042. const move_iterator<_Iterator>& __y)
  1043. { return __y < __x; }
  1044. template<typename _IteratorL, typename _IteratorR>
  1045. inline _GLIBCXX17_CONSTEXPR bool
  1046. operator>=(const move_iterator<_IteratorL>& __x,
  1047. const move_iterator<_IteratorR>& __y)
  1048. { return !(__x < __y); }
  1049. template<typename _Iterator>
  1050. inline _GLIBCXX17_CONSTEXPR bool
  1051. operator>=(const move_iterator<_Iterator>& __x,
  1052. const move_iterator<_Iterator>& __y)
  1053. { return !(__x < __y); }
  1054. // DR 685.
  1055. template<typename _IteratorL, typename _IteratorR>
  1056. inline _GLIBCXX17_CONSTEXPR auto
  1057. operator-(const move_iterator<_IteratorL>& __x,
  1058. const move_iterator<_IteratorR>& __y)
  1059. -> decltype(__x.base() - __y.base())
  1060. { return __x.base() - __y.base(); }
  1061. template<typename _Iterator>
  1062. inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
  1063. operator+(typename move_iterator<_Iterator>::difference_type __n,
  1064. const move_iterator<_Iterator>& __x)
  1065. { return __x + __n; }
  1066. template<typename _Iterator>
  1067. inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
  1068. make_move_iterator(_Iterator __i)
  1069. { return move_iterator<_Iterator>(__i); }
  1070. template<typename _Iterator, typename _ReturnType
  1071. = typename conditional<__move_if_noexcept_cond
  1072. <typename iterator_traits<_Iterator>::value_type>::value,
  1073. _Iterator, move_iterator<_Iterator>>::type>
  1074. inline _GLIBCXX17_CONSTEXPR _ReturnType
  1075. __make_move_if_noexcept_iterator(_Iterator __i)
  1076. { return _ReturnType(__i); }
  1077. // Overload for pointers that matches std::move_if_noexcept more closely,
  1078. // returning a constant iterator when we don't want to move.
  1079. template<typename _Tp, typename _ReturnType
  1080. = typename conditional<__move_if_noexcept_cond<_Tp>::value,
  1081. const _Tp*, move_iterator<_Tp*>>::type>
  1082. inline _GLIBCXX17_CONSTEXPR _ReturnType
  1083. __make_move_if_noexcept_iterator(_Tp* __i)
  1084. { return _ReturnType(__i); }
  1085. // @} group iterators
  1086. template<typename _Iterator>
  1087. auto
  1088. __niter_base(move_iterator<_Iterator> __it)
  1089. -> decltype(make_move_iterator(__niter_base(__it.base())))
  1090. { return make_move_iterator(__niter_base(__it.base())); }
  1091. template<typename _Iterator>
  1092. struct __is_move_iterator<move_iterator<_Iterator> >
  1093. {
  1094. enum { __value = 1 };
  1095. typedef __true_type __type;
  1096. };
  1097. template<typename _Iterator>
  1098. auto
  1099. __miter_base(move_iterator<_Iterator> __it)
  1100. -> decltype(__miter_base(__it.base()))
  1101. { return __miter_base(__it.base()); }
  1102. #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter)
  1103. #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) \
  1104. std::__make_move_if_noexcept_iterator(_Iter)
  1105. #else
  1106. #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter)
  1107. #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) (_Iter)
  1108. #endif // C++11
  1109. #if __cpp_deduction_guides >= 201606
  1110. // These helper traits are used for deduction guides
  1111. // of associative containers.
  1112. template<typename _InputIterator>
  1113. using __iter_key_t = remove_const_t<
  1114. typename iterator_traits<_InputIterator>::value_type::first_type>;
  1115. template<typename _InputIterator>
  1116. using __iter_val_t =
  1117. typename iterator_traits<_InputIterator>::value_type::second_type;
  1118. template<typename _T1, typename _T2>
  1119. struct pair;
  1120. template<typename _InputIterator>
  1121. using __iter_to_alloc_t =
  1122. pair<add_const_t<__iter_key_t<_InputIterator>>,
  1123. __iter_val_t<_InputIterator>>;
  1124. #endif
  1125. _GLIBCXX_END_NAMESPACE_VERSION
  1126. } // namespace
  1127. #ifdef _GLIBCXX_DEBUG
  1128. # include <debug/stl_iterator.h>
  1129. #endif
  1130. #endif