2014-01-17 00:58:45 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-07-17 03:08:36 +08:00
|
|
|
#ifndef ITERATORS_H
|
|
|
|
#define ITERATORS_H
|
|
|
|
|
|
|
|
#include <iterator>
|
2016-01-14 05:54:34 +08:00
|
|
|
#include <stdexcept>
|
2016-05-28 07:43:29 +08:00
|
|
|
#include <cstddef>
|
2014-09-17 12:09:35 +08:00
|
|
|
#include <cassert>
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2016-01-14 05:54:34 +08:00
|
|
|
#include "test_macros.h"
|
|
|
|
|
2017-01-07 04:58:25 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2014-10-28 04:26:25 +08:00
|
|
|
#define DELETE_FUNCTION = delete
|
|
|
|
#else
|
|
|
|
#define DELETE_FUNCTION
|
|
|
|
#endif
|
|
|
|
|
2010-08-15 02:14:02 +08:00
|
|
|
template <class It>
|
|
|
|
class output_iterator
|
|
|
|
{
|
|
|
|
It it_;
|
|
|
|
|
|
|
|
template <class U> friend class output_iterator;
|
|
|
|
public:
|
|
|
|
typedef std::output_iterator_tag iterator_category;
|
2013-01-10 01:20:02 +08:00
|
|
|
typedef void value_type;
|
2010-08-15 02:14:02 +08:00
|
|
|
typedef typename std::iterator_traits<It>::difference_type difference_type;
|
|
|
|
typedef It pointer;
|
|
|
|
typedef typename std::iterator_traits<It>::reference reference;
|
|
|
|
|
|
|
|
It base() const {return it_;}
|
|
|
|
|
2013-01-03 10:29:29 +08:00
|
|
|
output_iterator () {}
|
2010-08-15 02:14:02 +08:00
|
|
|
explicit output_iterator(It it) : it_(it) {}
|
|
|
|
template <class U>
|
|
|
|
output_iterator(const output_iterator<U>& u) :it_(u.it_) {}
|
|
|
|
|
|
|
|
reference operator*() const {return *it_;}
|
|
|
|
|
|
|
|
output_iterator& operator++() {++it_; return *this;}
|
|
|
|
output_iterator operator++(int)
|
|
|
|
{output_iterator tmp(*this); ++(*this); return tmp;}
|
2014-10-28 03:28:20 +08:00
|
|
|
|
|
|
|
template <class T>
|
2014-10-28 04:26:25 +08:00
|
|
|
void operator,(T const &) DELETE_FUNCTION;
|
2010-08-15 02:14:02 +08:00
|
|
|
};
|
|
|
|
|
2016-08-29 05:26:01 +08:00
|
|
|
template <class It,
|
|
|
|
class ItTraits = It>
|
2010-07-17 03:08:36 +08:00
|
|
|
class input_iterator
|
|
|
|
{
|
2016-08-29 06:14:37 +08:00
|
|
|
typedef std::iterator_traits<ItTraits> Traits;
|
2010-07-17 03:08:36 +08:00
|
|
|
It it_;
|
|
|
|
|
2016-08-29 05:26:01 +08:00
|
|
|
template <class U, class T> friend class input_iterator;
|
2010-07-17 03:08:36 +08:00
|
|
|
public:
|
|
|
|
typedef std::input_iterator_tag iterator_category;
|
2016-08-29 05:26:01 +08:00
|
|
|
typedef typename Traits::value_type value_type;
|
|
|
|
typedef typename Traits::difference_type difference_type;
|
2010-07-17 03:08:36 +08:00
|
|
|
typedef It pointer;
|
2016-08-29 05:26:01 +08:00
|
|
|
typedef typename Traits::reference reference;
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 It base() const {return it_;}
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 input_iterator() : it_() {}
|
|
|
|
explicit TEST_CONSTEXPR_CXX14 input_iterator(It it) : it_(it) {}
|
2016-08-29 05:26:01 +08:00
|
|
|
template <class U, class T>
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 input_iterator(const input_iterator<U, T>& u) :it_(u.it_) {}
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 reference operator*() const {return *it_;}
|
|
|
|
TEST_CONSTEXPR_CXX14 pointer operator->() const {return it_;}
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 input_iterator& operator++() {++it_; return *this;}
|
|
|
|
TEST_CONSTEXPR_CXX14 input_iterator operator++(int)
|
2010-07-17 03:08:36 +08:00
|
|
|
{input_iterator tmp(*this); ++(*this); return tmp;}
|
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
friend TEST_CONSTEXPR_CXX14 bool operator==(const input_iterator& x, const input_iterator& y)
|
2010-07-17 03:08:36 +08:00
|
|
|
{return x.it_ == y.it_;}
|
2017-05-18 02:51:36 +08:00
|
|
|
friend TEST_CONSTEXPR_CXX14 bool operator!=(const input_iterator& x, const input_iterator& y)
|
2010-07-17 03:08:36 +08:00
|
|
|
{return !(x == y);}
|
2014-10-28 03:28:20 +08:00
|
|
|
|
|
|
|
template <class T>
|
2014-10-28 04:26:25 +08:00
|
|
|
void operator,(T const &) DELETE_FUNCTION;
|
2010-07-17 03:08:36 +08:00
|
|
|
};
|
|
|
|
|
2016-08-29 05:26:01 +08:00
|
|
|
template <class T, class TV, class U, class UV>
|
2010-07-17 03:08:36 +08:00
|
|
|
inline
|
|
|
|
bool
|
2016-08-29 05:26:01 +08:00
|
|
|
operator==(const input_iterator<T, TV>& x, const input_iterator<U, UV>& y)
|
2010-07-17 03:08:36 +08:00
|
|
|
{
|
|
|
|
return x.base() == y.base();
|
|
|
|
}
|
|
|
|
|
2016-08-29 05:26:01 +08:00
|
|
|
template <class T, class TV, class U, class UV>
|
2010-07-17 03:08:36 +08:00
|
|
|
inline
|
|
|
|
bool
|
2016-08-29 05:26:01 +08:00
|
|
|
operator!=(const input_iterator<T, TV>& x, const input_iterator<U, UV>& y)
|
2010-07-17 03:08:36 +08:00
|
|
|
{
|
|
|
|
return !(x == y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class It>
|
|
|
|
class forward_iterator
|
|
|
|
{
|
|
|
|
It it_;
|
|
|
|
|
|
|
|
template <class U> friend class forward_iterator;
|
|
|
|
public:
|
|
|
|
typedef std::forward_iterator_tag iterator_category;
|
|
|
|
typedef typename std::iterator_traits<It>::value_type value_type;
|
|
|
|
typedef typename std::iterator_traits<It>::difference_type difference_type;
|
|
|
|
typedef It pointer;
|
|
|
|
typedef typename std::iterator_traits<It>::reference reference;
|
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 It base() const {return it_;}
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 forward_iterator() : it_() {}
|
|
|
|
explicit TEST_CONSTEXPR_CXX14 forward_iterator(It it) : it_(it) {}
|
2010-07-17 03:08:36 +08:00
|
|
|
template <class U>
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 forward_iterator(const forward_iterator<U>& u) :it_(u.it_) {}
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 reference operator*() const {return *it_;}
|
|
|
|
TEST_CONSTEXPR_CXX14 pointer operator->() const {return it_;}
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 forward_iterator& operator++() {++it_; return *this;}
|
|
|
|
TEST_CONSTEXPR_CXX14 forward_iterator operator++(int)
|
2010-07-17 03:08:36 +08:00
|
|
|
{forward_iterator tmp(*this); ++(*this); return tmp;}
|
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
friend TEST_CONSTEXPR_CXX14 bool operator==(const forward_iterator& x, const forward_iterator& y)
|
2010-07-17 03:08:36 +08:00
|
|
|
{return x.it_ == y.it_;}
|
2017-05-18 02:51:36 +08:00
|
|
|
friend TEST_CONSTEXPR_CXX14 bool operator!=(const forward_iterator& x, const forward_iterator& y)
|
2010-07-17 03:08:36 +08:00
|
|
|
{return !(x == y);}
|
2014-10-28 03:28:20 +08:00
|
|
|
|
|
|
|
template <class T>
|
2014-10-28 04:26:25 +08:00
|
|
|
void operator,(T const &) DELETE_FUNCTION;
|
2010-07-17 03:08:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline
|
2017-05-18 02:51:36 +08:00
|
|
|
bool TEST_CONSTEXPR_CXX14
|
2010-07-17 03:08:36 +08:00
|
|
|
operator==(const forward_iterator<T>& x, const forward_iterator<U>& y)
|
|
|
|
{
|
|
|
|
return x.base() == y.base();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline
|
2017-05-18 02:51:36 +08:00
|
|
|
bool TEST_CONSTEXPR_CXX14
|
2010-07-17 03:08:36 +08:00
|
|
|
operator!=(const forward_iterator<T>& x, const forward_iterator<U>& y)
|
|
|
|
{
|
|
|
|
return !(x == y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class It>
|
|
|
|
class bidirectional_iterator
|
|
|
|
{
|
|
|
|
It it_;
|
|
|
|
|
|
|
|
template <class U> friend class bidirectional_iterator;
|
|
|
|
public:
|
|
|
|
typedef std::bidirectional_iterator_tag iterator_category;
|
|
|
|
typedef typename std::iterator_traits<It>::value_type value_type;
|
|
|
|
typedef typename std::iterator_traits<It>::difference_type difference_type;
|
|
|
|
typedef It pointer;
|
|
|
|
typedef typename std::iterator_traits<It>::reference reference;
|
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 It base() const {return it_;}
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 bidirectional_iterator() : it_() {}
|
|
|
|
explicit TEST_CONSTEXPR_CXX14 bidirectional_iterator(It it) : it_(it) {}
|
2010-07-17 03:08:36 +08:00
|
|
|
template <class U>
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 bidirectional_iterator(const bidirectional_iterator<U>& u) :it_(u.it_) {}
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 reference operator*() const {return *it_;}
|
|
|
|
TEST_CONSTEXPR_CXX14 pointer operator->() const {return it_;}
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 bidirectional_iterator& operator++() {++it_; return *this;}
|
|
|
|
TEST_CONSTEXPR_CXX14 bidirectional_iterator operator++(int)
|
2010-07-17 03:08:36 +08:00
|
|
|
{bidirectional_iterator tmp(*this); ++(*this); return tmp;}
|
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 bidirectional_iterator& operator--() {--it_; return *this;}
|
|
|
|
TEST_CONSTEXPR_CXX14 bidirectional_iterator operator--(int)
|
2010-07-17 03:08:36 +08:00
|
|
|
{bidirectional_iterator tmp(*this); --(*this); return tmp;}
|
2014-10-28 03:28:20 +08:00
|
|
|
|
|
|
|
template <class T>
|
2014-10-28 04:26:25 +08:00
|
|
|
void operator,(T const &) DELETE_FUNCTION;
|
2010-07-17 03:08:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline
|
2017-05-18 02:51:36 +08:00
|
|
|
bool TEST_CONSTEXPR_CXX14
|
2010-07-17 03:08:36 +08:00
|
|
|
operator==(const bidirectional_iterator<T>& x, const bidirectional_iterator<U>& y)
|
|
|
|
{
|
|
|
|
return x.base() == y.base();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline
|
2017-05-18 02:51:36 +08:00
|
|
|
bool TEST_CONSTEXPR_CXX14
|
2010-07-17 03:08:36 +08:00
|
|
|
operator!=(const bidirectional_iterator<T>& x, const bidirectional_iterator<U>& y)
|
|
|
|
{
|
|
|
|
return !(x == y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class It>
|
|
|
|
class random_access_iterator
|
|
|
|
{
|
|
|
|
It it_;
|
|
|
|
|
|
|
|
template <class U> friend class random_access_iterator;
|
|
|
|
public:
|
|
|
|
typedef std::random_access_iterator_tag iterator_category;
|
|
|
|
typedef typename std::iterator_traits<It>::value_type value_type;
|
|
|
|
typedef typename std::iterator_traits<It>::difference_type difference_type;
|
|
|
|
typedef It pointer;
|
|
|
|
typedef typename std::iterator_traits<It>::reference reference;
|
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 It base() const {return it_;}
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 random_access_iterator() : it_() {}
|
|
|
|
explicit TEST_CONSTEXPR_CXX14 random_access_iterator(It it) : it_(it) {}
|
|
|
|
template <class U>
|
|
|
|
TEST_CONSTEXPR_CXX14 random_access_iterator(const random_access_iterator<U>& u) :it_(u.it_) {}
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 reference operator*() const {return *it_;}
|
|
|
|
TEST_CONSTEXPR_CXX14 pointer operator->() const {return it_;}
|
2010-07-17 03:08:36 +08:00
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 random_access_iterator& operator++() {++it_; return *this;}
|
|
|
|
TEST_CONSTEXPR_CXX14 random_access_iterator operator++(int)
|
2010-07-17 03:08:36 +08:00
|
|
|
{random_access_iterator tmp(*this); ++(*this); return tmp;}
|
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 random_access_iterator& operator--() {--it_; return *this;}
|
|
|
|
TEST_CONSTEXPR_CXX14 random_access_iterator operator--(int)
|
2010-07-17 03:08:36 +08:00
|
|
|
{random_access_iterator tmp(*this); --(*this); return tmp;}
|
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 random_access_iterator& operator+=(difference_type n) {it_ += n; return *this;}
|
|
|
|
TEST_CONSTEXPR_CXX14 random_access_iterator operator+(difference_type n) const
|
2010-07-17 03:08:36 +08:00
|
|
|
{random_access_iterator tmp(*this); tmp += n; return tmp;}
|
2017-05-18 02:51:36 +08:00
|
|
|
friend TEST_CONSTEXPR_CXX14 random_access_iterator operator+(difference_type n, random_access_iterator x)
|
2010-07-17 03:08:36 +08:00
|
|
|
{x += n; return x;}
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 random_access_iterator& operator-=(difference_type n) {return *this += -n;}
|
|
|
|
TEST_CONSTEXPR_CXX14 random_access_iterator operator-(difference_type n) const
|
2010-07-17 03:08:36 +08:00
|
|
|
{random_access_iterator tmp(*this); tmp -= n; return tmp;}
|
|
|
|
|
2017-05-18 02:51:36 +08:00
|
|
|
TEST_CONSTEXPR_CXX14 reference operator[](difference_type n) const {return it_[n];}
|
2014-10-28 03:28:20 +08:00
|
|
|
|
|
|
|
template <class T>
|
2014-10-28 04:26:25 +08:00
|
|
|
void operator,(T const &) DELETE_FUNCTION;
|
2010-07-17 03:08:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline
|
2017-05-18 02:51:36 +08:00
|
|
|
bool TEST_CONSTEXPR_CXX14
|
2010-07-17 03:08:36 +08:00
|
|
|
operator==(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
|
|
|
{
|
|
|
|
return x.base() == y.base();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline
|
2017-05-18 02:51:36 +08:00
|
|
|
bool TEST_CONSTEXPR_CXX14
|
2010-07-17 03:08:36 +08:00
|
|
|
operator!=(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
|
|
|
{
|
|
|
|
return !(x == y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline
|
2017-05-18 02:51:36 +08:00
|
|
|
bool TEST_CONSTEXPR_CXX14
|
2010-07-17 03:08:36 +08:00
|
|
|
operator<(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
|
|
|
{
|
|
|
|
return x.base() < y.base();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline
|
2017-05-18 02:51:36 +08:00
|
|
|
bool TEST_CONSTEXPR_CXX14
|
2010-07-17 03:08:36 +08:00
|
|
|
operator<=(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
|
|
|
{
|
|
|
|
return !(y < x);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline
|
2017-05-18 02:51:36 +08:00
|
|
|
bool TEST_CONSTEXPR_CXX14
|
2010-07-17 03:08:36 +08:00
|
|
|
operator>(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
|
|
|
{
|
|
|
|
return y < x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline
|
2017-05-18 02:51:36 +08:00
|
|
|
bool TEST_CONSTEXPR_CXX14
|
2010-07-17 03:08:36 +08:00
|
|
|
operator>=(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
|
|
|
{
|
|
|
|
return !(x < y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
2017-05-18 02:51:36 +08:00
|
|
|
inline TEST_CONSTEXPR_CXX14
|
2010-07-17 03:08:36 +08:00
|
|
|
typename std::iterator_traits<T>::difference_type
|
|
|
|
operator-(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
|
|
|
{
|
|
|
|
return x.base() - y.base();
|
|
|
|
}
|
|
|
|
|
2013-01-05 02:24:04 +08:00
|
|
|
template <class Iter>
|
2017-05-18 02:51:36 +08:00
|
|
|
inline TEST_CONSTEXPR_CXX14 Iter base(output_iterator<Iter> i) { return i.base(); }
|
2013-01-05 02:24:04 +08:00
|
|
|
|
|
|
|
template <class Iter>
|
2017-05-18 02:51:36 +08:00
|
|
|
inline TEST_CONSTEXPR_CXX14 Iter base(input_iterator<Iter> i) { return i.base(); }
|
2013-01-05 02:24:04 +08:00
|
|
|
|
|
|
|
template <class Iter>
|
2017-05-18 02:51:36 +08:00
|
|
|
inline TEST_CONSTEXPR_CXX14 Iter base(forward_iterator<Iter> i) { return i.base(); }
|
2013-01-05 02:24:04 +08:00
|
|
|
|
|
|
|
template <class Iter>
|
2017-05-18 02:51:36 +08:00
|
|
|
inline TEST_CONSTEXPR_CXX14 Iter base(bidirectional_iterator<Iter> i) { return i.base(); }
|
2013-01-05 02:24:04 +08:00
|
|
|
|
|
|
|
template <class Iter>
|
2017-05-18 02:51:36 +08:00
|
|
|
inline TEST_CONSTEXPR_CXX14 Iter base(random_access_iterator<Iter> i) { return i.base(); }
|
2013-01-05 02:24:04 +08:00
|
|
|
|
2013-07-09 05:06:38 +08:00
|
|
|
template <class Iter> // everything else
|
2017-05-18 02:51:36 +08:00
|
|
|
inline TEST_CONSTEXPR_CXX14 Iter base(Iter i) { return i; }
|
2013-01-05 02:24:04 +08:00
|
|
|
|
2016-01-14 05:54:34 +08:00
|
|
|
template <typename T>
|
|
|
|
struct ThrowingIterator {
|
|
|
|
typedef std::bidirectional_iterator_tag iterator_category;
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef const T value_type;
|
|
|
|
typedef const T * pointer;
|
|
|
|
typedef const T & reference;
|
|
|
|
|
2016-01-20 11:37:46 +08:00
|
|
|
enum ThrowingAction { TAIncrement, TADecrement, TADereference, TAAssignment, TAComparison };
|
|
|
|
|
|
|
|
// Constructors
|
|
|
|
ThrowingIterator ()
|
|
|
|
: begin_(nullptr), end_(nullptr), current_(nullptr), action_(TADereference), index_(0) {}
|
|
|
|
ThrowingIterator (const T *first, const T *last, size_t index = 0, ThrowingAction action = TADereference)
|
|
|
|
: begin_(first), end_(last), current_(first), action_(action), index_(index) {}
|
|
|
|
ThrowingIterator (const ThrowingIterator &rhs)
|
|
|
|
: begin_(rhs.begin_), end_(rhs.end_), current_(rhs.current_), action_(rhs.action_), index_(rhs.index_) {}
|
|
|
|
ThrowingIterator & operator= (const ThrowingIterator &rhs)
|
|
|
|
{
|
|
|
|
if (action_ == TAAssignment)
|
|
|
|
{
|
|
|
|
if (index_ == 0)
|
2016-01-20 11:19:15 +08:00
|
|
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
2016-01-20 11:37:46 +08:00
|
|
|
throw std::runtime_error ("throw from iterator assignment");
|
2016-01-20 11:19:15 +08:00
|
|
|
#else
|
2016-01-20 11:37:46 +08:00
|
|
|
assert(false);
|
2016-01-20 11:19:15 +08:00
|
|
|
#endif
|
|
|
|
|
2016-01-20 11:37:46 +08:00
|
|
|
else
|
|
|
|
--index_;
|
|
|
|
}
|
|
|
|
begin_ = rhs.begin_;
|
|
|
|
end_ = rhs.end_;
|
|
|
|
current_ = rhs.current_;
|
|
|
|
action_ = rhs.action_;
|
|
|
|
index_ = rhs.index_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// iterator operations
|
|
|
|
reference operator*() const
|
|
|
|
{
|
|
|
|
if (action_ == TADereference)
|
|
|
|
{
|
|
|
|
if (index_ == 0)
|
2016-01-20 11:19:15 +08:00
|
|
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
2016-01-20 11:37:46 +08:00
|
|
|
throw std::runtime_error ("throw from iterator dereference");
|
2016-01-20 11:19:15 +08:00
|
|
|
#else
|
2016-01-20 11:37:46 +08:00
|
|
|
assert(false);
|
2016-01-20 11:19:15 +08:00
|
|
|
#endif
|
2016-01-20 11:37:46 +08:00
|
|
|
else
|
|
|
|
--index_;
|
|
|
|
}
|
|
|
|
return *current_;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowingIterator & operator++()
|
|
|
|
{
|
|
|
|
if (action_ == TAIncrement)
|
|
|
|
{
|
|
|
|
if (index_ == 0)
|
2016-01-20 11:19:15 +08:00
|
|
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
2016-01-20 11:37:46 +08:00
|
|
|
throw std::runtime_error ("throw from iterator increment");
|
2016-01-20 11:19:15 +08:00
|
|
|
#else
|
2016-01-20 11:37:46 +08:00
|
|
|
assert(false);
|
2016-01-20 11:19:15 +08:00
|
|
|
#endif
|
2016-01-20 11:37:46 +08:00
|
|
|
else
|
|
|
|
--index_;
|
|
|
|
}
|
|
|
|
++current_;
|
|
|
|
return *this;
|
|
|
|
}
|
2016-06-02 05:35:39 +08:00
|
|
|
|
2016-01-20 11:37:46 +08:00
|
|
|
ThrowingIterator operator++(int)
|
|
|
|
{
|
|
|
|
ThrowingIterator temp = *this;
|
|
|
|
++(*this);
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowingIterator & operator--()
|
|
|
|
{
|
|
|
|
if (action_ == TADecrement)
|
|
|
|
{
|
|
|
|
if (index_ == 0)
|
2016-01-20 11:19:15 +08:00
|
|
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
2016-01-20 11:37:46 +08:00
|
|
|
throw std::runtime_error ("throw from iterator decrement");
|
2016-01-20 11:19:15 +08:00
|
|
|
#else
|
2016-01-20 11:37:46 +08:00
|
|
|
assert(false);
|
2016-01-20 11:19:15 +08:00
|
|
|
#endif
|
2016-01-20 11:37:46 +08:00
|
|
|
else
|
|
|
|
--index_;
|
|
|
|
}
|
|
|
|
--current_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrowingIterator operator--(int) {
|
|
|
|
ThrowingIterator temp = *this;
|
|
|
|
--(*this);
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator== (const ThrowingIterator &rhs) const
|
|
|
|
{
|
|
|
|
if (action_ == TAComparison)
|
|
|
|
{
|
|
|
|
if (index_ == 0)
|
2016-01-20 11:19:15 +08:00
|
|
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
2016-01-20 11:37:46 +08:00
|
|
|
throw std::runtime_error ("throw from iterator comparison");
|
2016-01-20 11:19:15 +08:00
|
|
|
#else
|
2016-01-20 11:37:46 +08:00
|
|
|
assert(false);
|
2016-01-20 11:19:15 +08:00
|
|
|
#endif
|
2016-01-20 11:37:46 +08:00
|
|
|
else
|
|
|
|
--index_;
|
|
|
|
}
|
|
|
|
bool atEndL = current_ == end_;
|
|
|
|
bool atEndR = rhs.current_ == rhs.end_;
|
|
|
|
if (atEndL != atEndR) return false; // one is at the end (or empty), the other is not.
|
|
|
|
if (atEndL) return true; // both are at the end (or empty)
|
|
|
|
return current_ == rhs.current_;
|
|
|
|
}
|
2016-01-14 05:54:34 +08:00
|
|
|
|
|
|
|
private:
|
2016-01-20 11:37:46 +08:00
|
|
|
const T* begin_;
|
|
|
|
const T* end_;
|
|
|
|
const T* current_;
|
|
|
|
ThrowingAction action_;
|
|
|
|
mutable size_t index_;
|
2016-01-14 05:54:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool operator== (const ThrowingIterator<T>& a, const ThrowingIterator<T>& b)
|
2016-01-20 11:37:46 +08:00
|
|
|
{ return a.operator==(b); }
|
2016-01-14 05:54:34 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool operator!= (const ThrowingIterator<T>& a, const ThrowingIterator<T>& b)
|
2016-01-20 11:37:46 +08:00
|
|
|
{ return !a.operator==(b); }
|
2016-06-02 05:35:39 +08:00
|
|
|
|
2016-01-14 05:54:34 +08:00
|
|
|
template <typename T>
|
|
|
|
struct NonThrowingIterator {
|
|
|
|
typedef std::bidirectional_iterator_tag iterator_category;
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef const T value_type;
|
|
|
|
typedef const T * pointer;
|
|
|
|
typedef const T & reference;
|
|
|
|
|
2016-01-20 11:37:46 +08:00
|
|
|
// Constructors
|
|
|
|
NonThrowingIterator ()
|
|
|
|
: begin_(nullptr), end_(nullptr), current_(nullptr) {}
|
|
|
|
NonThrowingIterator (const T *first, const T* last)
|
|
|
|
: begin_(first), end_(last), current_(first) {}
|
|
|
|
NonThrowingIterator (const NonThrowingIterator &rhs)
|
|
|
|
: begin_(rhs.begin_), end_(rhs.end_), current_(rhs.current_) {}
|
|
|
|
NonThrowingIterator & operator= (const NonThrowingIterator &rhs) TEST_NOEXCEPT
|
|
|
|
{
|
|
|
|
begin_ = rhs.begin_;
|
|
|
|
end_ = rhs.end_;
|
|
|
|
current_ = rhs.current_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// iterator operations
|
|
|
|
reference operator*() const TEST_NOEXCEPT
|
|
|
|
{
|
|
|
|
return *current_;
|
|
|
|
}
|
|
|
|
|
|
|
|
NonThrowingIterator & operator++() TEST_NOEXCEPT
|
|
|
|
{
|
|
|
|
++current_;
|
|
|
|
return *this;
|
|
|
|
}
|
2016-06-02 05:35:39 +08:00
|
|
|
|
2016-01-20 11:37:46 +08:00
|
|
|
NonThrowingIterator operator++(int) TEST_NOEXCEPT
|
|
|
|
{
|
|
|
|
NonThrowingIterator temp = *this;
|
|
|
|
++(*this);
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
NonThrowingIterator & operator--() TEST_NOEXCEPT
|
|
|
|
{
|
|
|
|
--current_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
NonThrowingIterator operator--(int) TEST_NOEXCEPT
|
|
|
|
{
|
|
|
|
NonThrowingIterator temp = *this;
|
|
|
|
--(*this);
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator== (const NonThrowingIterator &rhs) const TEST_NOEXCEPT
|
|
|
|
{
|
|
|
|
bool atEndL = current_ == end_;
|
|
|
|
bool atEndR = rhs.current_ == rhs.end_;
|
|
|
|
if (atEndL != atEndR) return false; // one is at the end (or empty), the other is not.
|
|
|
|
if (atEndL) return true; // both are at the end (or empty)
|
|
|
|
return current_ == rhs.current_;
|
|
|
|
}
|
2016-01-14 05:54:34 +08:00
|
|
|
|
|
|
|
private:
|
2016-01-20 11:37:46 +08:00
|
|
|
const T* begin_;
|
|
|
|
const T* end_;
|
|
|
|
const T* current_;
|
2016-01-14 05:54:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool operator== (const NonThrowingIterator<T>& a, const NonThrowingIterator<T>& b) TEST_NOEXCEPT
|
2016-01-20 11:37:46 +08:00
|
|
|
{ return a.operator==(b); }
|
2016-01-14 05:54:34 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool operator!= (const NonThrowingIterator<T>& a, const NonThrowingIterator<T>& b) TEST_NOEXCEPT
|
2016-01-20 11:37:46 +08:00
|
|
|
{ return !a.operator==(b); }
|
2016-01-14 05:54:34 +08:00
|
|
|
|
2014-10-28 04:26:25 +08:00
|
|
|
#undef DELETE_FUNCTION
|
|
|
|
|
2010-08-22 08:45:01 +08:00
|
|
|
#endif // ITERATORS_H
|