iterator 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // HP/SGI iterator extensions -*- C++ -*-
  2. // Copyright (C) 2001-2022 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 ext/iterator
  46. * This file is a GNU extension to the Standard C++ Library (possibly
  47. * containing extensions from the HP/SGI STL subset).
  48. */
  49. #ifndef _EXT_ITERATOR
  50. #define _EXT_ITERATOR 1
  51. #pragma GCC system_header
  52. #include <bits/concept_check.h>
  53. #include <iterator>
  54. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  55. {
  56. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  57. // There are two signatures for distance. In addition to the one
  58. // taking two iterators and returning a result, there is another
  59. // taking two iterators and a reference-to-result variable, and
  60. // returning nothing. The latter seems to be an SGI extension.
  61. // -- pedwards
  62. template<typename _InputIterator, typename _Distance>
  63. inline void
  64. __distance(_InputIterator __first, _InputIterator __last,
  65. _Distance& __n, std::input_iterator_tag)
  66. {
  67. // concept requirements
  68. __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
  69. while (__first != __last)
  70. {
  71. ++__first;
  72. ++__n;
  73. }
  74. }
  75. template<typename _RandomAccessIterator, typename _Distance>
  76. inline void
  77. __distance(_RandomAccessIterator __first, _RandomAccessIterator __last,
  78. _Distance& __n, std::random_access_iterator_tag)
  79. {
  80. // concept requirements
  81. __glibcxx_function_requires(_RandomAccessIteratorConcept<
  82. _RandomAccessIterator>)
  83. __n += __last - __first;
  84. }
  85. /**
  86. * This is an SGI extension.
  87. * @ingroup SGIextensions
  88. * @doctodo
  89. */
  90. template<typename _InputIterator, typename _Distance>
  91. inline void
  92. distance(_InputIterator __first, _InputIterator __last,
  93. _Distance& __n)
  94. {
  95. // concept requirements -- taken care of in __distance
  96. __distance(__first, __last, __n, std::__iterator_category(__first));
  97. }
  98. _GLIBCXX_END_NAMESPACE_VERSION
  99. } // namespace
  100. #endif