8#ifndef INCLUDED_BSLSTL_ITERATOR
9#define INCLUDED_BSLSTL_ITERATOR
216#include <bslscm_version.h>
225#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
229#ifdef BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
230 #include <type_traits>
233#ifdef BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS
234 #include <initializer_list>
239#ifdef BSLS_LIBRARYFEATURES_STDCPP_LIBCSTD
240 #define BSLSTL_ITERATOR_IMPLEMENT_CPP11_REVERSE_ITERATOR 1
241 #define BSLSTL_ITERATOR_PROVIDE_SUN_CPP98_FIXES 1
248using std::input_iterator_tag;
249using std::output_iterator_tag;
250using std::forward_iterator_tag;
251using std::bidirectional_iterator_tag;
252using std::random_access_iterator_tag;
259using std::back_insert_iterator;
260using std::back_inserter;
261using std::front_insert_iterator;
262using std::front_inserter;
263using std::insert_iterator;
266#ifdef BSLS_LIBRARYFEATURES_HAS_CPP20_BASELINE_LIBRARY
269using std::incrementable;
270using std::incrementable_traits;
271using std::iter_difference_t;
274using std::indirectly_readable_traits;
275using std::iter_value_t;
278using std::iter_reference_t;
279using std::iter_rvalue_reference_t;
282using std::iter_common_reference_t;
285using std::indirectly_readable;
286using std::indirectly_writable;
289using std::weakly_incrementable;
292using std::input_or_output_iterator;
295using std::sentinel_for;
298using std::sized_sentinel_for;
301using std::input_iterator;
304using std::output_iterator;
307using std::forward_iterator;
310using std::bidirectional_iterator;
313using std::random_access_iterator;
316using std::contiguous_iterator;
319using std::indirect_binary_predicate;
320using std::indirect_equivalence_relation;
321using std::indirect_result_t;
322using std::indirect_strict_weak_order;
323using std::indirect_unary_predicate;
324using std::indirectly_regular_unary_invocable;
325using std::indirectly_unary_invocable;
331using std::indirectly_movable;
332using std::indirectly_movable_storable;
335using std::indirectly_copyable;
336using std::indirectly_copyable_storable;
339using std::indirectly_swappable;
342using std::indirectly_comparable;
345using std::permutable;
354using std::contiguous_iterator_tag;
357using std::move_sentinel;
360using std::common_iterator;
363using std::default_sentinel_t;
366using std::counted_iterator;
369using std::unreachable_sentinel_t;
373#ifdef BSLS_LIBRARYFEATURES_HAS_CPP14_BASELINE_LIBRARY
375using std::make_reverse_iterator;
379using std::istream_iterator;
380using std::ostream_iterator;
381using std::istreambuf_iterator;
382using std::ostreambuf_iterator;
384#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
386using std::move_iterator;
387using std::make_move_iterator;
393#ifdef BSLSTL_ITERATOR_PROVIDE_SUN_CPP98_FIXES
402struct iterator_traits {
406 typedef typename ITER::iterator_category iterator_category;
407 typedef typename ITER::value_type value_type;
408 typedef typename ITER::difference_type difference_type;
409 typedef typename ITER::pointer pointer;
410 typedef typename ITER::reference reference;
415struct iterator_traits<const TYPE *> {
420 typedef std::random_access_iterator_tag iterator_category;
421 typedef TYPE value_type;
422 typedef std::ptrdiff_t difference_type;
423 typedef const TYPE* pointer;
424 typedef const TYPE& reference;
428struct iterator_traits<TYPE *> {
433 typedef std::random_access_iterator_tag iterator_category;
434 typedef TYPE value_type;
435 typedef std::ptrdiff_t difference_type;
436 typedef TYPE* pointer;
437 typedef TYPE& reference;
441using std::iterator_traits;
444#ifdef BSLSTL_ITERATOR_IMPLEMENT_CPP11_REVERSE_ITERATOR
464class reverse_iterator :
465 public std::reverse_iterator<
467 typename iterator_traits<ITER>::iterator_category,
468 typename iterator_traits<ITER>::value_type,
469 typename iterator_traits<ITER>::reference,
470 typename iterator_traits<ITER>::pointer> {
484 typedef std::reverse_iterator<
486 typename iterator_traits<ITER>::iterator_category,
487 typename iterator_traits<ITER>::value_type,
488 typename iterator_traits<ITER>::reference,
489 typename iterator_traits<ITER>::pointer> Base;
494 typedef typename reverse_iterator::difference_type difference_type;
503 explicit reverse_iterator(ITER base);
507 template <
class OTHER_ITER>
508 reverse_iterator(
const reverse_iterator<OTHER_ITER>& original);
527 reverse_iterator& operator+=(difference_type n);
550 reverse_iterator& operator-=(difference_type n);
560 reverse_iterator
operator+(difference_type n)
const;
569 reverse_iterator
operator-(difference_type n)
const;
582bool operator==(
const reverse_iterator<ITER>& lhs,
583 const reverse_iterator<ITER>& rhs);
591template <
class ITER1,
class ITER2>
593bool operator==(
const reverse_iterator<ITER1>& lhs,
594 const reverse_iterator<ITER2>& rhs);
606bool operator!=(
const reverse_iterator<ITER>& lhs,
607 const reverse_iterator<ITER>& rhs);
616template <
class ITER1,
class ITER2>
618bool operator!=(
const reverse_iterator<ITER1>& lhs,
619 const reverse_iterator<ITER2>& rhs);
631bool operator<(
const reverse_iterator<ITER>& lhs,
632 const reverse_iterator<ITER>& rhs);
641template <
class ITER1,
class ITER2>
643bool operator<(
const reverse_iterator<ITER1>& lhs,
644 const reverse_iterator<ITER2>& rhs);
656bool operator>(
const reverse_iterator<ITER>& lhs,
657 const reverse_iterator<ITER>& rhs);
666template <
class ITER1,
class ITER2>
668bool operator>(
const reverse_iterator<ITER1>& lhs,
669 const reverse_iterator<ITER2>& rhs);
681bool operator<=(
const reverse_iterator<ITER>& lhs,
682 const reverse_iterator<ITER>& rhs);
692template <
class ITER1,
class ITER2>
694bool operator<=(
const reverse_iterator<ITER1>& lhs,
695 const reverse_iterator<ITER2>& rhs);
708bool operator>=(
const reverse_iterator<ITER>& lhs,
709 const reverse_iterator<ITER>& rhs);
719template <
class ITER1,
class ITER2>
721bool operator>=(
const reverse_iterator<ITER1>& lhs,
722 const reverse_iterator<ITER2>& rhs);
735typename reverse_iterator<ITER>::difference_type
736operator-(
const reverse_iterator<ITER>& lhs,
737 const reverse_iterator<ITER>& rhs);
745template <
class ITER,
class DIFF_TYPE>
747reverse_iterator<ITER>
748operator+(DIFF_TYPE n,
const reverse_iterator<ITER>& rhs);
756using std::reverse_iterator;
759#ifdef BSLSTL_ITERATOR_PROVIDE_SUN_CPP98_FIXES
765struct IteratorDistanceImp {
770 template <
class FWD_ITER,
class DIFFERENCE_TYPE>
771 static void getDistance(DIFFERENCE_TYPE *ret,
781 template <
class FWD_ITER,
class DIFFERENCE_TYPE>
782 static void getDistance(DIFFERENCE_TYPE *ret,
785 forward_iterator_tag);
792 template <
class RANDOM_ITER,
class DIFFERENCE_TYPE>
793 static void getDistance(DIFFERENCE_TYPE *ret,
796 random_access_iterator_tag);
805typename iterator_traits<ITER>::difference_type
806distance(ITER start, ITER finish);
817#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_RANGE_FUNCTIONS
825typename T::iterator
begin(T& container);
830typename T::const_iterator
begin(
const T& container);
834template<
class T,
size_t N>
835T *
begin(T (&array)[N]);
839template<
class T,
size_t N>
840const T *
begin(
const T (&array)[N]);
845typename T::iterator
end(T& container);
850typename T::const_iterator
end(
const T& container);
854template<
class T,
size_t N>
855T *
end(T (&array)[N]);
859template<
class T,
size_t N>
860const T *
end(
const T (&array)[N]);
864#ifdef BSLS_LIBRARYFEATURES_HAS_CPP14_RANGE_FUNCTIONS
876typename T::const_iterator
cbegin(
const T& container);
880template<
class T,
size_t N>
881const T *
cbegin(
const T (&array)[N]);
886typename T::reverse_iterator
rbegin(T& container);
891typename T::const_reverse_iterator
rbegin(
const T& container);
895template <
class T,
size_t N>
896reverse_iterator<T *>
rbegin(T (&array)[N]);
898#ifdef BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS
900reverse_iterator<const T *>
rbegin(std::initializer_list<T> initializerList);
908typename T::const_reverse_iterator
crbegin(
const T& container);
912template <
class T,
size_t N>
913reverse_iterator<const T *>
crbegin(
const T (&array)[N]);
918typename T::const_iterator
cend(
const T& container);
922template<
class T,
size_t N>
923const T *
cend(
const T (&array)[N]);
928typename T::reverse_iterator
rend(T& container);
934typename T::const_reverse_iterator
rend(
const T& container);
938template <
class T,
size_t N>
939reverse_iterator<T *>
rend(T (&array)[N]);
941#ifdef BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS
943reverse_iterator<const T *>
rend(std::initializer_list<T> initializerList);
952typename T::const_reverse_iterator
crend(
const T& container);
956template <
class T,
size_t N>
957reverse_iterator<const T *>
crend(
const T (&array)[N]);
960#ifdef BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES
963using std::ranges::distance;
964using std::ranges::iter_swap;
973#ifdef BSLSTL_ITERATOR_IMPLEMENT_CPP11_REVERSE_ITERATOR
982reverse_iterator<ITER>::reverse_iterator()
989reverse_iterator<ITER>::reverse_iterator(ITER base)
995template <
class OTHER_ITER>
997reverse_iterator<ITER>::reverse_iterator(
998 const reverse_iterator<OTHER_ITER>& original)
999: Base(original.base())
1004template <
class ITER>
1006reverse_iterator<ITER>&
1007reverse_iterator<ITER>::operator++()
1013template <
class ITER>
1015reverse_iterator<ITER>
1016reverse_iterator<ITER>::operator++(
int)
1018 const reverse_iterator tmp(*
this);
1023template <
class ITER>
1025reverse_iterator<ITER>&
1026reverse_iterator<ITER>::operator+=(difference_type n)
1028 Base::operator+=(n);
1032template <
class ITER>
1034reverse_iterator<ITER>&
1035reverse_iterator<ITER>::operator--()
1041template <
class ITER>
1043reverse_iterator<ITER>
1044reverse_iterator<ITER>::operator--(
int)
1046 reverse_iterator tmp(*
this);
1051template <
class ITER>
1053reverse_iterator<ITER>&
1054reverse_iterator<ITER>::operator-=(difference_type n)
1056 Base::operator-=(n);
1061template <
class ITER>
1063reverse_iterator<ITER>
1064reverse_iterator<ITER>::operator+(difference_type n)
const
1066 reverse_iterator tmp(*
this);
1071template <
class ITER>
1073reverse_iterator<ITER>
1074reverse_iterator<ITER>::operator-(difference_type n)
const
1076 reverse_iterator tmp(*
this);
1082template <
class ITER>
1084bool operator==(
const reverse_iterator<ITER>& lhs,
1085 const reverse_iterator<ITER>& rhs)
1087 typedef std::reverse_iterator<
1089 typename iterator_traits<ITER>::iterator_category,
1090 typename iterator_traits<ITER>::value_type,
1091 typename iterator_traits<ITER>::reference,
1092 typename iterator_traits<ITER>::pointer> Base;
1094 return std::operator==(
static_cast<const Base&
>(lhs),
1095 static_cast<const Base&
>(rhs));
1098template <
class ITER1,
class ITER2>
1100bool operator==(
const reverse_iterator<ITER1>& lhs,
1101 const reverse_iterator<ITER2>& rhs)
1105 return lhs.base() == rhs.base();
1108template <
class ITER>
1110bool operator!=(
const reverse_iterator<ITER>& lhs,
1111 const reverse_iterator<ITER>& rhs)
1113 return ! (lhs == rhs);
1116template <
class ITER1,
class ITER2>
1118bool operator!=(
const reverse_iterator<ITER1>& lhs,
1119 const reverse_iterator<ITER2>& rhs)
1123 return ! (lhs == rhs);
1126template <
class ITER>
1128bool operator<(
const reverse_iterator<ITER>& lhs,
1129 const reverse_iterator<ITER>& rhs)
1131 return rhs.base() < lhs.base();
1134template <
class ITER1,
class ITER2>
1136bool operator<(
const reverse_iterator<ITER1>& lhs,
1137 const reverse_iterator<ITER2>& rhs)
1141 return rhs.base() < lhs.base();
1144template <
class ITER>
1146bool operator>(
const reverse_iterator<ITER>& lhs,
1147 const reverse_iterator<ITER>& rhs)
1152template <
class ITER1,
class ITER2>
1154bool operator>(
const reverse_iterator<ITER1>& lhs,
1155 const reverse_iterator<ITER2>& rhs)
1160template <
class ITER>
1162bool operator<=(
const reverse_iterator<ITER>& lhs,
1163 const reverse_iterator<ITER>& rhs)
1165 return !(rhs < lhs);
1168template <
class ITER1,
class ITER2>
1170bool operator<=(
const reverse_iterator<ITER1>& lhs,
1171 const reverse_iterator<ITER2>& rhs)
1173 return !(rhs < lhs);
1176template <
class ITER>
1178bool operator>=(
const reverse_iterator<ITER>& lhs,
1179 const reverse_iterator<ITER>& rhs)
1181 return !(lhs < rhs);
1184template <
class ITER1,
class ITER2>
1186bool operator>=(
const reverse_iterator<ITER1>& lhs,
1187 const reverse_iterator<ITER2>& rhs)
1189 return !(lhs < rhs);
1192template <
class ITER>
1194typename reverse_iterator<ITER>::difference_type
1195operator-(
const reverse_iterator<ITER>& lhs,
1196 const reverse_iterator<ITER>& rhs)
1198 typedef std::reverse_iterator<
1200 typename iterator_traits<ITER>::iterator_category,
1201 typename iterator_traits<ITER>::value_type,
1202 typename iterator_traits<ITER>::reference,
1203 typename iterator_traits<ITER>::pointer> Base;
1205 return std::operator-(
static_cast<const Base&
>(lhs),
1206 static_cast<const Base&
>(rhs));
1209template <
class ITER,
class DIFF_TYPE>
1211reverse_iterator<ITER>
1212operator+(DIFF_TYPE n,
const reverse_iterator<ITER>& rhs)
1214 return rhs.operator+(n);
1223#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_RANGE_FUNCTIONS
1226template <
class CONTAINER>
1228#ifdef BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE
1229auto data(CONTAINER& container) ->
decltype(container.data())
1231typename CONTAINER::value_type *
data(CONTAINER& container)
1238 return container.data();
1244template <
class CONTAINER>
1246#ifdef BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE
1247auto data(
const CONTAINER& container) ->
decltype(container.data())
1249typename CONTAINER::value_type
const *
data(
const CONTAINER& container)
1252 return container.data();
1260#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_RANGE_FUNCTIONS
1263# ifdef BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE
1264template <
class CONTAINER>
1267 decltype(container.empty())
1271 return container.empty();
1277template <
class CONTAINER>
1281 return container.empty();
1286template <
class TYPE,
size_t DIMENSION>
1293#ifdef BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS
1294template <
class TYPE>
1301 return 0 == initializerList.size();
1319#if defined(BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY) || \
1320 defined(BSLS_PLATFORM_CMP_MSVC)
1329template <
class TYPE,
size_t DIMENSION>
1341#if defined(BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE) && \
1342 201103L <= BSLS_COMPILERFEATURES_SUPPORT_CPLUSPLUS
1346template <
class CONTAINER>
1349 decltype(container.size())
1353 return container.size();
1361template <
class CONTAINER>
1365 return container.size();
1382#if 201703L < BSLS_COMPILERFEATURES_CPLUSPLUS && \
1383 defined(__cpp_lib_ssize) && __cpp_lib_ssize >= 201902L
1392template <
class TYPE, std::ptrdiff_t DIMENSION>
1404#if defined(BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE) && \
1405 201103L <= BSLS_COMPILERFEATURES_SUPPORT_CPLUSPLUS
1409template <
class CONTAINER>
1414 std::make_signed_t<
decltype(container.size())>>
1418 return container.size();
1426template <
class CONTAINER>
1430 return container.size();
1435#ifdef BSLSTL_ITERATOR_PROVIDE_SUN_CPP98_FIXES
1441template <
class FWD_ITER,
class DIFFERENCE_TYPE>
1442void IteratorDistanceImp::getDistance(DIFFERENCE_TYPE *ret,
1447 DIFFERENCE_TYPE count = 0;
1448 for ( ; start != finish; ++start) {
1455template <
class FWD_ITER,
class DIFFERENCE_TYPE>
1456void IteratorDistanceImp::getDistance(DIFFERENCE_TYPE *ret,
1459 forward_iterator_tag)
1461 DIFFERENCE_TYPE count = 0;
1462 for ( ; start != finish; ++start) {
1469template <
class RANDOM_ITER,
class DIFFERENCE_TYPE>
1471void IteratorDistanceImp::getDistance(DIFFERENCE_TYPE *ret,
1474 random_access_iterator_tag)
1476 *ret = DIFFERENCE_TYPE(finish - start);
1479template <
class ITER>
1481typename iterator_traits<ITER>::difference_type
1482distance(ITER start, ITER finish)
1484 typedef typename bsl::iterator_traits<ITER>::iterator_category tag;
1486 typename iterator_traits<ITER>::difference_type ret;
1487 IteratorDistanceImp::getDistance(&ret, start, finish, tag());
1492#ifndef BSLS_LIBRARYFEATURES_HAS_CPP11_RANGE_FUNCTIONS
1497 return container.begin();
1502typename T::const_iterator
begin(
const T& container)
1504 return container.begin();
1507template<
class T,
size_t N>
1514template<
class T,
size_t N>
1523typename T::iterator
end(T& container)
1525 return container.end();
1530typename T::const_iterator
end(
const T& container)
1532 return container.end();
1535template<
class T,
size_t N>
1542template<
class T,
size_t N>
1550#ifndef BSLS_LIBRARYFEATURES_HAS_CPP14_RANGE_FUNCTIONS
1553typename T::const_iterator
cbegin(
const T& container)
1555 return begin(container);
1558template<
class T,
size_t N>
1567typename T::reverse_iterator
rbegin(T& container)
1569 return container.rbegin();
1574typename T::const_reverse_iterator
rbegin(
const T& container)
1576 return container.rbegin();
1579template <
class T,
size_t N>
1583 return reverse_iterator<T *>(
array + N);
1586#ifdef BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS
1589reverse_iterator<const T *> rbegin(std::initializer_list<T> initializerList)
1591 return reverse_iterator<const T *>(initializerList.end());
1597typename T::const_reverse_iterator
crbegin(
const T& container)
1599 return rbegin(container);
1602template <
class T,
size_t N>
1606 return reverse_iterator<const T *>(
array + N);
1611typename T::const_iterator
cend(
const T& container)
1613 return end(container);
1616template<
class T,
size_t N>
1625typename T::reverse_iterator
rend(T& container)
1627 return container.rend();
1632typename T::const_reverse_iterator
rend(
const T& container)
1634 return container.rend();
1637template <
class T,
size_t N>
1641 return reverse_iterator<T *>(
array);
1644#ifdef BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS
1647reverse_iterator<const T *> rend(std::initializer_list<T> initializerList)
1649 return reverse_iterator<const T *>(initializerList.begin());
1654typename T::const_reverse_iterator
crend(
const T& container)
1656 return rend(container);
1659template <
class T,
size_t N>
1663 return reverse_iterator<const T *>(
array);
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:588
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
bool operator!=(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
bool operator==(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
bool operator<(const MetricId &lhs, const MetricId &rhs)
TransformIterator< FUNCTOR, ITERATOR > operator--(TransformIterator< FUNCTOR, ITERATOR > &iterator, int)
bool operator>=(const Guid &lhs, const Guid &rhs)
FunctionOutputIterator< FUNCTION > & operator++(FunctionOutputIterator< FUNCTION > &iterator)
Do nothing and return specified iterator.
Definition bdlb_functionoutputiterator.h:405
TransformIterator< FUNCTOR, ITERATOR > operator+(const TransformIterator< FUNCTOR, ITERATOR > &iterator, typename TransformIterator< FUNCTOR, ITERATOR >::difference_type offset)
bool operator<=(const Guid &lhs, const Guid &rhs)
bool operator>(const Guid &lhs, const Guid &rhs)
TransformIterator< FUNCTOR, ITERATOR > operator-(const TransformIterator< FUNCTOR, ITERATOR > &iterator, typename TransformIterator< FUNCTOR, ITERATOR >::difference_type offset)
Definition bdlb_printmethods.h:283
T::reverse_iterator rend(T &container)
Definition bslstl_iterator.h:1625
T::const_iterator cend(const T &container)
Definition bslstl_iterator.h:1611
T::const_reverse_iterator crbegin(const T &container)
Definition bslstl_iterator.h:1597
T::reverse_iterator rbegin(T &container)
Definition bslstl_iterator.h:1567
BSLS_KEYWORD_CONSTEXPR std::ptrdiff_t ssize(const TYPE(&)[DIMENSION]) BSLS_KEYWORD_NOEXCEPT
Return the dimension of the specified array argument.
Definition bslstl_iterator.h:1394
T::iterator begin(T &container)
Definition bslstl_iterator.h:1495
T::const_iterator cbegin(const T &container)
Definition bslstl_iterator.h:1553
basic_string< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR > operator+(const basic_string< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR > &lhs, const basic_string< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR > &rhs)
T::iterator end(T &container)
Definition bslstl_iterator.h:1523
BSLS_KEYWORD_CONSTEXPR CONTAINER::value_type * data(CONTAINER &container)
Definition bslstl_iterator.h:1231
BSLS_KEYWORD_CONSTEXPR bool empty(const CONTAINER &container)
Definition bslstl_iterator.h:1279
T::const_reverse_iterator crend(const T &container)
Definition bslstl_iterator.h:1654
Definition bslstl_array.h:290