stl_iterator.h 41 KB

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