1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

fix iterator implementation

This commit is contained in:
bolero-MURAKAMI 2013-02-23 15:21:27 +09:00
parent 4c996bd47b
commit 7c706381d4
65 changed files with 494 additions and 313 deletions

View file

@ -109,7 +109,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR ForwardIterator
adjacent_find(
ForwardIterator first, ForwardIterator last, BinaryPredicate pred,
void*
std::forward_iterator_tag*
)
{
typedef sprout::pair<ForwardIterator, ForwardIterator> type;

View file

@ -84,7 +84,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR bool
all_of(
InputIterator first, InputIterator last, Predicate pred,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, bool> type;

View file

@ -84,7 +84,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR bool
all_of_equal(
InputIterator first, InputIterator last, T const& value,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, bool> type;

View file

@ -84,7 +84,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR bool
any_of(
InputIterator first, InputIterator last, Predicate pred,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, bool> type;

View file

@ -84,7 +84,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR bool
any_of_equal(
InputIterator first, InputIterator last, T const& value,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, bool> type;

View file

@ -84,7 +84,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
count(
InputIterator first, InputIterator last, T const& value,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;

View file

@ -84,7 +84,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
count_if(
InputIterator first, InputIterator last, Predicate pred,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;

View file

@ -91,7 +91,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR bool
equal(
InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred,
void*
std::input_iterator_tag*
)
{
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, bool> type;

View file

@ -86,7 +86,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR InputIterator
find(
InputIterator first, InputIterator last, T const& value,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, bool> type;

View file

@ -134,7 +134,7 @@ namespace sprout {
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred,
void*
std::forward_iterator_tag*
)
{
typedef sprout::pair<ForwardIterator1, ForwardIterator1> type;

View file

@ -102,7 +102,7 @@ namespace sprout {
InputIterator1 first1, InputIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator1, bool> type;

View file

@ -86,7 +86,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR InputIterator
find_if(
InputIterator first, InputIterator last, Predicate pred,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, bool> type;

View file

@ -86,7 +86,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR InputIterator
find_if_not(
InputIterator first, InputIterator last, Predicate pred,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, bool> type;

View file

@ -105,7 +105,7 @@ namespace sprout {
typename std::iterator_traits<InputIterator>::value_type const& low,
typename std::iterator_traits<InputIterator>::value_type const& high,
Compare comp,
void*
std::input_iterator_tag*
)
{
return sprout::fixed::detail::clamp_range_copy_impl(first, last, result, low, high, comp, sprout::size(result));

View file

@ -83,7 +83,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
copy(
InputIterator first, InputIterator last, Result const& result,
void*
std::input_iterator_tag*
)
{
return sprout::fixed::detail::copy_impl(first, last, result, sprout::size(result));

View file

@ -82,7 +82,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
copy_backward(
BidirectionalIterator first, BidirectionalIterator last, Result const& result,
void*
std::bidirectional_iterator_tag*
)
{
return sprout::fixed::detail::copy_backward_impl(

View file

@ -59,7 +59,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
copy_n(
InputIterator first, Size n, Result const& result,
void*
std::input_iterator_tag*
)
{
return sprout::fixed::detail::copy_n_impl(first, n, result, sprout::size(result));

View file

@ -61,7 +61,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
copy_until(
InputIterator first, InputIterator last, Result const& result, Predicate pred,
void*
std::input_iterator_tag*
)
{
return sprout::fixed::detail::copy_until_impl(first, last, result, pred, sprout::size(result));

View file

@ -60,7 +60,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
copy_while(
InputIterator first, InputIterator last, Result const& result, Predicate pred,
void*
std::input_iterator_tag*
)
{
return sprout::fixed::detail::copy_while_impl(first, last, result, pred, sprout::size(result));

View file

@ -93,7 +93,7 @@ namespace sprout {
replace_copy(
InputIterator first, InputIterator last,
Result const& result, T const& old_value, T const& new_value,
void*
std::input_iterator_tag*
)
{
return sprout::fixed::detail::replace_copy_impl(first, last, result, old_value, new_value, sprout::size(result));

View file

@ -92,7 +92,7 @@ namespace sprout {
replace_copy_if(
InputIterator first, InputIterator last,
Result const& result, Predicate pred, T const& new_value,
void*
std::input_iterator_tag*
)
{
return sprout::fixed::detail::replace_copy_if_impl(first, last, result, pred, new_value, sprout::size(result));

View file

@ -84,7 +84,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
reverse_copy(
BidirectionalIterator first, BidirectionalIterator last, Result const& result,
void*
std::bidirectional_iterator_tag*
)
{
return sprout::fixed::detail::reverse_copy_impl(first, last, result, sprout::size(result));

View file

@ -125,7 +125,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
rotate_copy(
ForwardIterator first, ForwardIterator middle, ForwardIterator last, Result const& result,
void*
std::forward_iterator_tag*
)
{
return sprout::fixed::detail::rotate_copy_impl(first, middle, last, result, sprout::size(result));

View file

@ -102,7 +102,7 @@ namespace sprout {
ForwardIterator first, ForwardIterator last,
Result const& result,
ForwardIterator pos1, ForwardIterator pos2,
void*
std::forward_iterator_tag*
)
{
return sprout::fixed::detail::swap_element_copy_impl(first, last, result, sprout::size(result));

View file

@ -90,7 +90,7 @@ namespace sprout {
transform(
InputIterator first, InputIterator last,
Result const& result, UnaryOperation op,
void*
std::input_iterator_tag*
)
{
return sprout::fixed::detail::transform_impl(first, last, result, op, sprout::size(result));
@ -207,7 +207,7 @@ namespace sprout {
transform(
InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
Result const& result, BinaryOperation op,
void*
std::input_iterator_tag*
)
{
return sprout::fixed::detail::transform_impl(first1, last1, first2, result, op, sprout::size(result));

View file

@ -99,7 +99,7 @@ namespace sprout {
InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
Compare comp,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator1, InputIterator2> type;

View file

@ -78,7 +78,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR bool
is_partitioned(
InputIterator first, InputIterator last, Predicate pred,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;

View file

@ -99,7 +99,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR bool
is_permutation(
ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate pred,
void*
std::forward_iterator_tag*
)
{
typedef sprout::pair<ForwardIterator1, bool> type;

View file

@ -52,7 +52,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR bool
is_sorted(
ForwardIterator first, ForwardIterator last, Compare comp,
void*
std::forward_iterator_tag*
)
{
return sprout::is_sorted_until(first, last, comp) == last;

View file

@ -94,7 +94,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR ForwardIterator
is_sorted_until(
ForwardIterator first, ForwardIterator last, Compare comp,
void*
std::forward_iterator_tag*
)
{
typedef sprout::pair<ForwardIterator, ForwardIterator> type;

View file

@ -126,7 +126,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR bool
lexicographical_compare(
InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator1, InputIterator2> type;

View file

@ -97,7 +97,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR ForwardIterator
max_element(
ForwardIterator first, ForwardIterator last, Compare comp,
void*
std::forward_iterator_tag*
)
{
typedef sprout::pair<ForwardIterator, ForwardIterator> type;

View file

@ -97,7 +97,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR ForwardIterator
min_element(
ForwardIterator first, ForwardIterator last, Compare comp,
void*
std::forward_iterator_tag*
)
{
typedef sprout::pair<ForwardIterator, ForwardIterator> type;

View file

@ -109,7 +109,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
minmax_element(
ForwardIterator first, ForwardIterator last, Compare comp,
void*
std::forward_iterator_tag*
)
{
typedef sprout::pair<ForwardIterator, sprout::pair<ForwardIterator, ForwardIterator> > type;

View file

@ -112,7 +112,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
mismatch(
InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred,
void*
std::input_iterator_tag*
)
{
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, bool> type;

View file

@ -84,7 +84,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR bool
none_of(
InputIterator first, InputIterator last, Predicate pred,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, bool> type;

View file

@ -84,7 +84,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR bool
none_of_equal(
InputIterator first, InputIterator last, T const& value,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, bool> type;

View file

@ -108,7 +108,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR bool
one_of(
InputIterator first, InputIterator last, Predicate pred,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;

View file

@ -108,7 +108,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR bool
one_of_equal(
InputIterator first, InputIterator last, T const& value,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;

View file

@ -110,7 +110,7 @@ namespace sprout {
ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred,
void*
std::forward_iterator_tag*
)
{
typedef sprout::pair<ForwardIterator1, bool> type;

View file

@ -18,9 +18,10 @@ namespace sprout {
inline SPROUT_CONSTEXPR ForwardIterator
search_n(ForwardIterator first, ForwardIterator last, Size count, T const& value, BinaryPredicate pred) {
typedef sprout::value_iterator<T const&> iterator;
typedef typename std::iterator_traits<iterator>::difference_type difference_type;
return sprout::search(
first, last,
iterator(value, static_cast<typename std::iterator_traits<iterator>::difference_type>(count)), iterator(value, 0),
iterator(value, static_cast<difference_type>(count)), iterator(value, 0),
pred
);
}

View file

@ -129,7 +129,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR int
tristate_lexicographical_compare(
InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator1, InputIterator2> type;
@ -298,7 +298,7 @@ namespace sprout {
InputIterator1 first1, InputIterator1 last1, T1 const& delim1,
InputIterator2 first2, InputIterator2 last2, T2 const& delim2,
Compare comp,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator1, InputIterator2> type;

View file

@ -46,7 +46,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
count_n(
InputIterator first, typename std::iterator_traits<InputIterator>::difference_type n, T const& value,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;

View file

@ -46,7 +46,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
count_n_if(
InputIterator first, typename std::iterator_traits<InputIterator>::difference_type n, Predicate pred,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;

View file

@ -91,7 +91,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
overlap_count(
InputIterator first, InputIterator last, BinaryPredicate pred,
void*
std::input_iterator_tag*
)
{
typedef sprout::tuples::tuple<InputIterator, typename std::iterator_traits<InputIterator>::value_type, typename std::iterator_traits<InputIterator>::difference_type> type;

View file

@ -86,7 +86,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR ForwardIterator1
search_one(
ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred,
void*
std::forward_iterator_tag*
)
{
typedef sprout::tuples::tuple<ForwardIterator1, ForwardIterator2, bool> type;

View file

@ -28,7 +28,7 @@ namespace sprout {
>
{
public:
typedef Iterator base_type;
typedef Iterator iterator_type;
typedef Traits traits_type;
private:
typedef std::iterator<
@ -37,34 +37,34 @@ namespace sprout {
std::ptrdiff_t,
void,
unsigned char
> iterator_type;
> base_type;
public:
typedef typename iterator_type::iterator_category iterator_category;
typedef typename iterator_type::value_type value_type;
typedef typename iterator_type::difference_type difference_type;
typedef typename iterator_type::pointer pointer;
typedef typename iterator_type::reference reference;
typedef typename base_type::iterator_category iterator_category;
typedef typename base_type::value_type value_type;
typedef typename base_type::difference_type difference_type;
typedef typename base_type::pointer pointer;
typedef typename base_type::reference reference;
private:
struct next_tag {};
struct prev_tag {};
struct ra_tag {};
private:
base_type it_;
iterator_type it_;
difference_type i_;
private:
SPROUT_CONSTEXPR bytes_iterator(base_type it, difference_type i)
SPROUT_CONSTEXPR bytes_iterator(iterator_type it, difference_type i)
: it_(it)
, i_(i)
{}
SPROUT_CONSTEXPR bytes_iterator(base_type it, difference_type i, next_tag)
SPROUT_CONSTEXPR bytes_iterator(iterator_type it, difference_type i, next_tag)
: it_(i / traits_type::size() == 0 ? it : sprout::next(it))
, i_(i % traits_type::size())
{}
SPROUT_CONSTEXPR bytes_iterator(base_type it, difference_type i, prev_tag)
SPROUT_CONSTEXPR bytes_iterator(iterator_type it, difference_type i, prev_tag)
: it_((i + 1 - traits_type::size()) / traits_type::size() == 0 ? it : sprout::prev(it))
, i_(i % traits_type::size() + traits_type::size())
{}
SPROUT_CONSTEXPR bytes_iterator(base_type it, difference_type i, ra_tag)
SPROUT_CONSTEXPR bytes_iterator(iterator_type it, difference_type i, ra_tag)
: it_(i >= 0
? sprout::next(it, i / traits_type::size())
: sprout::next(it, (i + 1 - traits_type::size()) / traits_type::size())
@ -76,14 +76,18 @@ namespace sprout {
{}
public:
SPROUT_CONSTEXPR bytes_iterator()
: it_()
, i_()
: it_(), i_()
{}
bytes_iterator(bytes_iterator const&) = default;
explicit SPROUT_CONSTEXPR bytes_iterator(base_type it)
: it_(it)
, i_()
explicit SPROUT_CONSTEXPR bytes_iterator(iterator_type it)
: it_(it), i_()
{}
SPROUT_CONSTEXPR iterator_type const& base() const {
return it_;
}
SPROUT_CONSTEXPR difference_type index() const {
return i_;
}
SPROUT_CONSTEXPR bytes_iterator next() const {
return bytes_iterator(it_, i_ + 1, next_tag());
}
@ -96,24 +100,6 @@ namespace sprout {
sprout::swap(it_, other.it_);
sprout::swap(i_, other.i_);
}
friend SPROUT_CONSTEXPR bool operator==(bytes_iterator const& lhs, bytes_iterator const& rhs) {
return lhs.it_ == rhs.it_ && lhs.i_ == rhs.i_;
}
friend SPROUT_CONSTEXPR bool operator!=(bytes_iterator const& lhs, bytes_iterator const& rhs) {
return !(lhs == rhs);
}
friend SPROUT_CONSTEXPR bool operator<(bytes_iterator const& lhs, bytes_iterator const& rhs) {
return lhs.it_ < rhs.it_ || (lhs.it_ == rhs.it_ && lhs.i_ < rhs.i_);
}
friend SPROUT_CONSTEXPR bool operator>(bytes_iterator const& lhs, bytes_iterator const& rhs) {
return rhs < lhs;
}
friend SPROUT_CONSTEXPR bool operator<=(bytes_iterator const& lhs, bytes_iterator const& rhs) {
return !(rhs < lhs);
}
friend SPROUT_CONSTEXPR bool operator>=(bytes_iterator const& lhs, bytes_iterator const& rhs) {
return !(lhs < rhs);
}
SPROUT_CONSTEXPR reference operator*() const {
return traits_type::get_byte(*it_, i_);
}
@ -156,14 +142,60 @@ namespace sprout {
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
return *(*this + n);
}
friend SPROUT_CONSTEXPR difference_type operator-(bytes_iterator const& lhs, bytes_iterator const& rhs) {
return (lhs.it_ - rhs.it_) * traits_type::size() + (lhs.i_ - rhs.i_);
}
friend SPROUT_CONSTEXPR bytes_iterator operator+(difference_type n, bytes_iterator const& it) {
return it + n;
}
};
template<typename Iterator1, typename Iterator2, typename Traits>
inline SPROUT_CONSTEXPR bool
operator==(sprout::bytes_iterator<Iterator1, Traits> const& lhs, sprout::bytes_iterator<Iterator2, Traits> const& rhs) {
return lhs.base() == rhs.base() && lhs.index() == rhs.index();
}
template<typename Iterator1, typename Iterator2, typename Traits>
inline SPROUT_CONSTEXPR bool
operator!=(sprout::bytes_iterator<Iterator1, Traits> const& lhs, sprout::bytes_iterator<Iterator2, Traits> const& rhs) {
return !(lhs == rhs);
}
template<typename Iterator1, typename Iterator2, typename Traits>
inline SPROUT_CONSTEXPR bool
operator<(sprout::bytes_iterator<Iterator1, Traits> const& lhs, sprout::bytes_iterator<Iterator2, Traits> const& rhs) {
return lhs.base() < rhs.base() || (lhs.base() == rhs.base() && lhs.index() < rhs.index());
}
template<typename Iterator1, typename Iterator2, typename Traits>
inline SPROUT_CONSTEXPR bool
operator>(sprout::bytes_iterator<Iterator1, Traits> const& lhs, sprout::bytes_iterator<Iterator2, Traits> const& rhs) {
return rhs < lhs;
}
template<typename Iterator1, typename Iterator2, typename Traits>
inline SPROUT_CONSTEXPR bool
operator<=(sprout::bytes_iterator<Iterator1, Traits> const& lhs, sprout::bytes_iterator<Iterator2, Traits> const& rhs) {
return !(rhs < lhs);
}
template<typename Iterator1, typename Iterator2, typename Traits>
inline SPROUT_CONSTEXPR bool
operator>=(sprout::bytes_iterator<Iterator1, Traits> const& lhs, sprout::bytes_iterator<Iterator2, Traits> const& rhs) {
return !(lhs < rhs);
}
template<typename Iterator1, typename Iterator2, typename Traits>
inline SPROUT_CONSTEXPR decltype(std::declval<Iterator1>() - std::declval<Iterator2>())
operator-(sprout::bytes_iterator<Iterator1, Traits> const& lhs, sprout::bytes_iterator<Iterator2, Traits> const& rhs) {
return (lhs.base() - rhs.base()) * Traits::size() + (lhs.index() - rhs.index());
}
template<typename Iterator, typename Traits>
inline SPROUT_CONSTEXPR sprout::bytes_iterator<Iterator, Traits>
operator+(typename sprout::bytes_iterator<Iterator, Traits>::difference_type n, sprout::bytes_iterator<Iterator, Traits> const& it) {
return it + n;
}
//
// swap
//
template<typename Iterator, typename Traits>
inline void
swap(sprout::bytes_iterator<Iterator, Traits>& lhs, sprout::bytes_iterator<Iterator, Traits>& rhs)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
{
lhs.swap(rhs);
}
//
// make_bytes_iterator
//
@ -179,14 +211,18 @@ namespace sprout {
}
//
// swap
// make_big_bytes_iterator
// make_little_bytes_iterator
//
template<typename Iterator, typename Traits>
inline void
swap(sprout::bytes_iterator<Iterator, Traits>& lhs, sprout::bytes_iterator<Iterator, Traits>& rhs)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
{
lhs.swap(rhs);
template<typename Iterator>
inline SPROUT_CONSTEXPR sprout::bytes_iterator<Iterator, sprout::big_endian_traits<typename std::iterator_traits<Iterator>::value_type> >
make_big_bytes_iterator(Iterator it) {
return sprout::bytes_iterator<Iterator, sprout::big_endian_traits<typename std::iterator_traits<Iterator>::value_type> >(it);
}
template<typename Iterator>
inline SPROUT_CONSTEXPR sprout::bytes_iterator<Iterator, sprout::little_endian_traits<typename std::iterator_traits<Iterator>::value_type> >
make_little_bytes_iterator(Iterator it) {
return sprout::bytes_iterator<Iterator, sprout::little_endian_traits<typename std::iterator_traits<Iterator>::value_type> >(it);
}
//

View file

@ -76,24 +76,6 @@ namespace sprout {
sprout::swap(index_, other.index_);
sprout::swap(size_, other.size_);
}
friend SPROUT_CONSTEXPR bool operator==(dft_iterator const& lhs, dft_iterator const& rhs) {
return lhs.index_ == rhs.index_;
}
friend SPROUT_CONSTEXPR bool operator!=(dft_iterator const& lhs, dft_iterator const& rhs) {
return !(lhs == rhs);
}
friend SPROUT_CONSTEXPR bool operator<(dft_iterator const& lhs, dft_iterator const& rhs) {
return lhs.index_ < rhs.index_;
}
friend SPROUT_CONSTEXPR bool operator>(dft_iterator const& lhs, dft_iterator const& rhs) {
return rhs < lhs;
}
friend SPROUT_CONSTEXPR bool operator<=(dft_iterator const& lhs, dft_iterator const& rhs) {
return !(rhs < lhs);
}
friend SPROUT_CONSTEXPR bool operator>=(dft_iterator const& lhs, dft_iterator const& rhs) {
return !(lhs < rhs);
}
SPROUT_CONSTEXPR reference operator*() const {
return sprout::detail::dft_element_impl(first_, last_, index_, size_);
}
@ -136,14 +118,49 @@ namespace sprout {
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
return sprout::detail::dft_element_impl(first_, last_, index_ + n, size_);
}
friend SPROUT_CONSTEXPR difference_type operator-(dft_iterator const& lhs, dft_iterator const& rhs) {
return lhs.index_ - rhs.index_;
}
friend SPROUT_CONSTEXPR dft_iterator operator+(difference_type n, dft_iterator const& it) {
return it + n;
}
};
template<typename Iterator>
inline SPROUT_CONSTEXPR bool
operator==(sprout::dft_iterator<Iterator> const& lhs, sprout::dft_iterator<Iterator> const& rhs) {
return lhs.index() == rhs.index();
}
template<typename Iterator>
inline SPROUT_CONSTEXPR bool
operator!=(sprout::dft_iterator<Iterator> const& lhs, sprout::dft_iterator<Iterator> const& rhs) {
return !(lhs == rhs);
}
template<typename Iterator>
inline SPROUT_CONSTEXPR bool
operator<(sprout::dft_iterator<Iterator> const& lhs, sprout::dft_iterator<Iterator> const& rhs) {
return lhs.index_ < rhs.index_;
}
template<typename Iterator>
inline SPROUT_CONSTEXPR bool
operator>(sprout::dft_iterator<Iterator> const& lhs, sprout::dft_iterator<Iterator> const& rhs) {
return rhs < lhs;
}
template<typename Iterator>
inline SPROUT_CONSTEXPR bool
operator<=(sprout::dft_iterator<Iterator> const& lhs, sprout::dft_iterator<Iterator> const& rhs) {
return !(rhs < lhs);
}
template<typename Iterator>
inline SPROUT_CONSTEXPR bool
operator>=(sprout::dft_iterator<Iterator> const& lhs, sprout::dft_iterator<Iterator> const& rhs) {
return !(lhs < rhs);
}
template<typename Iterator>
inline SPROUT_CONSTEXPR typename sprout::dft_iterator<Iterator>::difference_type
operator-(sprout::dft_iterator<Iterator> const& lhs, sprout::dft_iterator<Iterator> const& rhs) {
return lhs.index() - rhs.index();
}
template<typename Iterator>
inline SPROUT_CONSTEXPR sprout::dft_iterator<Iterator>
operator+(typename sprout::dft_iterator<Iterator>::difference_type n, sprout::dft_iterator<Iterator> const& it) {
return it + n;
}
//
// make_dft_iterator
//

View file

@ -63,7 +63,7 @@ namespace sprout {
}
template<typename InputIterator>
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
iterator_distance(InputIterator first, InputIterator last, void*) {
iterator_distance(InputIterator first, InputIterator last, std::input_iterator_tag*) {
typedef sprout::pair<InputIterator, typename std::iterator_traits<InputIterator>::difference_type> type;
return sprout::iterator_detail::iterator_distance_impl(type(first, 0), last, 1).second;
}

View file

@ -5,7 +5,6 @@
#include <limits>
#include <iterator>
#include <utility>
#include <stdexcept>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/generator/functions.hpp>
@ -34,16 +33,16 @@ namespace sprout {
typedef value_type* pointer;
private:
generator_type gen_;
difference_type count_;
difference_type index_;
public:
SPROUT_CONSTEXPR generator_iterator()
: gen_(), count_()
: gen_(), index_()
{}
explicit SPROUT_CONSTEXPR generator_iterator(
generator_type const& gen,
difference_type count = std::numeric_limits<difference_type>::max()
difference_type index = std::numeric_limits<difference_type>::max()
)
: gen_(gen), count_(count)
: gen_(gen), index_(index)
{}
generator_type& generator() {
return gen_;
@ -51,14 +50,11 @@ namespace sprout {
SPROUT_CONSTEXPR generator_type const& generator() const {
return gen_;
}
SPROUT_CONSTEXPR difference_type count() const {
return count_;
SPROUT_CONSTEXPR difference_type index() const {
return index_;
}
SPROUT_CONSTEXPR generator_iterator operator()() const {
return count_ != 0
? generator_iterator(sprout::generators::next_generator(gen_)(), count_ > 0 ? count_ - 1 : count_)
: throw std::out_of_range("generator_iterator<>: increment at out of range")
;
return generator_iterator(sprout::generators::next_generator(gen_)(), index_ - 1);
}
SPROUT_CONSTEXPR generator_iterator next() const {
return (*this)();
@ -73,35 +69,10 @@ namespace sprout {
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(gen_, other.gen_)))
{
sprout::swap(gen_, other.gen_);
sprout::swap(count_, other.count_);
}
friend SPROUT_CONSTEXPR bool operator==(generator_iterator const& lhs, generator_iterator const& rhs) {
return lhs.count_ == rhs.count_;
}
friend SPROUT_CONSTEXPR bool operator!=(generator_iterator const& lhs, generator_iterator const& rhs) {
return !(lhs == rhs);
}
friend SPROUT_CONSTEXPR bool operator<(generator_iterator const& lhs, generator_iterator const& rhs) {
typedef typename std::make_unsigned<difference_type>::type unsigned_type;
return static_cast<unsigned_type>(lhs.count_) > static_cast<unsigned_type>(rhs.count_);
}
friend SPROUT_CONSTEXPR bool operator>(generator_iterator const& lhs, generator_iterator const& rhs) {
return rhs < lhs;
}
friend SPROUT_CONSTEXPR bool operator<=(generator_iterator const& lhs, generator_iterator const& rhs) {
return !(rhs < lhs);
}
friend SPROUT_CONSTEXPR bool operator>=(generator_iterator const& lhs, generator_iterator const& rhs) {
return !(lhs < rhs);
sprout::swap(index_, other.index_);
}
SPROUT_CONSTEXPR reference operator*() const {
return count_ != 0
? sprout::generators::generated_value(gen_)
: (
throw std::out_of_range("generator_iterator<>: dereference at out of range"),
sprout::generators::generated_value(gen_)
)
;
return sprout::generators::generated_value(gen_);
}
SPROUT_CONSTEXPR pointer operator->() const {
return &*(*this);
@ -116,11 +87,44 @@ namespace sprout {
++*this;
return result;
}
friend SPROUT_CONSTEXPR difference_type operator-(generator_iterator const& lhs, generator_iterator const& rhs) {
return rhs.count_ - lhs.count_;
}
};
template<typename Generator>
inline SPROUT_CONSTEXPR bool
operator==(sprout::generator_iterator<Generator> const& lhs, sprout::generator_iterator<Generator> const& rhs) {
return lhs.index() == rhs.index();
}
template<typename Generator>
inline SPROUT_CONSTEXPR bool
operator!=(sprout::generator_iterator<Generator> const& lhs, sprout::generator_iterator<Generator> const& rhs) {
return !(lhs == rhs);
}
template<typename Generator>
inline SPROUT_CONSTEXPR bool
operator<(sprout::generator_iterator<Generator> const& lhs, sprout::generator_iterator<Generator> const& rhs) {
return rhs.index() < lhs.index();
}
template<typename Generator>
inline SPROUT_CONSTEXPR bool
operator>(sprout::generator_iterator<Generator> const& lhs, sprout::generator_iterator<Generator> const& rhs) {
return rhs < lhs;
}
template<typename Generator>
inline SPROUT_CONSTEXPR bool
operator<=(sprout::generator_iterator<Generator> const& lhs, sprout::generator_iterator<Generator> const& rhs) {
return !(rhs < lhs);
}
template<typename Generator>
inline SPROUT_CONSTEXPR bool
operator>=(sprout::generator_iterator<Generator> const& lhs, sprout::generator_iterator<Generator> const& rhs) {
return !(lhs < rhs);
}
template<typename Generator>
inline SPROUT_CONSTEXPR typename sprout::generator_iterator<Generator>::difference_type
operator-(sprout::generator_iterator<Generator> const& lhs, sprout::generator_iterator<Generator> const& rhs) {
return rhs.index() - lhs.index();
}
//
// swap
//

View file

@ -76,24 +76,6 @@ namespace sprout {
sprout::swap(index_, other.index_);
sprout::swap(size_, other.size_);
}
friend SPROUT_CONSTEXPR bool operator==(idft_iterator const& lhs, idft_iterator const& rhs) {
return lhs.index_ == rhs.index_;
}
friend SPROUT_CONSTEXPR bool operator!=(idft_iterator const& lhs, idft_iterator const& rhs) {
return !(lhs == rhs);
}
friend SPROUT_CONSTEXPR bool operator<(idft_iterator const& lhs, idft_iterator const& rhs) {
return lhs.index_ < rhs.index_;
}
friend SPROUT_CONSTEXPR bool operator>(idft_iterator const& lhs, idft_iterator const& rhs) {
return rhs < lhs;
}
friend SPROUT_CONSTEXPR bool operator<=(idft_iterator const& lhs, idft_iterator const& rhs) {
return !(rhs < lhs);
}
friend SPROUT_CONSTEXPR bool operator>=(idft_iterator const& lhs, idft_iterator const& rhs) {
return !(lhs < rhs);
}
SPROUT_CONSTEXPR reference operator*() const {
return sprout::detail::idft_element_impl(first_, last_, index_, size_);
}
@ -136,14 +118,49 @@ namespace sprout {
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
return sprout::detail::idft_element_impl(first_, last_, index_ + n, size_);
}
friend SPROUT_CONSTEXPR difference_type operator-(idft_iterator const& lhs, idft_iterator const& rhs) {
return lhs.index_ - rhs.index_;
}
friend SPROUT_CONSTEXPR idft_iterator operator+(difference_type n, idft_iterator const& it) {
return it + n;
}
};
template<typename Iterator>
inline SPROUT_CONSTEXPR bool
operator==(sprout::idft_iterator<Iterator> const& lhs, sprout::idft_iterator<Iterator> const& rhs) {
return lhs.index() == rhs.index();
}
template<typename Iterator>
inline SPROUT_CONSTEXPR bool
operator!=(sprout::idft_iterator<Iterator> const& lhs, sprout::idft_iterator<Iterator> const& rhs) {
return !(lhs == rhs);
}
template<typename Iterator>
inline SPROUT_CONSTEXPR bool
operator<(sprout::idft_iterator<Iterator> const& lhs, sprout::idft_iterator<Iterator> const& rhs) {
return lhs.index_ < rhs.index_;
}
template<typename Iterator>
inline SPROUT_CONSTEXPR bool
operator>(sprout::idft_iterator<Iterator> const& lhs, sprout::idft_iterator<Iterator> const& rhs) {
return rhs < lhs;
}
template<typename Iterator>
inline SPROUT_CONSTEXPR bool
operator<=(sprout::idft_iterator<Iterator> const& lhs, sprout::idft_iterator<Iterator> const& rhs) {
return !(rhs < lhs);
}
template<typename Iterator>
inline SPROUT_CONSTEXPR bool
operator>=(sprout::idft_iterator<Iterator> const& lhs, sprout::idft_iterator<Iterator> const& rhs) {
return !(lhs < rhs);
}
template<typename Iterator>
inline SPROUT_CONSTEXPR typename sprout::idft_iterator<Iterator>::difference_type
operator-(sprout::idft_iterator<Iterator> const& lhs, sprout::idft_iterator<Iterator> const& rhs) {
return lhs.index() - rhs.index();
}
template<typename Iterator>
inline SPROUT_CONSTEXPR sprout::idft_iterator<Iterator>
operator+(typename sprout::idft_iterator<Iterator>::difference_type n, sprout::idft_iterator<Iterator> const& it) {
return it + n;
}
//
// make_idft_iterator
//

View file

@ -78,25 +78,21 @@ namespace sprout {
typedef typename traits_type::size_type size_type;
private:
holder_type holder_;
size_type index_;
difference_type index_;
private:
SPROUT_CONSTEXPR index_iterator(holder_type const& r, size_type index)
: holder_(r)
, index_(index)
SPROUT_CONSTEXPR index_iterator(holder_type const& r, difference_type index)
: holder_(r), index_(index)
{}
public:
SPROUT_CONSTEXPR index_iterator()
: holder_()
, index_()
: holder_(), index_()
{}
index_iterator(index_iterator const&) = default;
explicit SPROUT_CONSTEXPR index_iterator(typename holder_type::param_type p)
: holder_(p)
, index_(0)
: holder_(p), index_(0)
{}
SPROUT_CONSTEXPR index_iterator(typename holder_type::param_type p, size_type index)
: holder_(p)
, index_(index)
SPROUT_CONSTEXPR index_iterator(typename holder_type::param_type p, difference_type index)
: holder_(p), index_(index)
{}
operator index_iterator<const_container_type>() const {
return index_iterator<const_container_type>(holder_.get(), index_);
@ -104,7 +100,7 @@ namespace sprout {
SPROUT_CONSTEXPR typename holder_type::mutable_or_const_reference base() const {
return holder_.get();
}
SPROUT_CONSTEXPR size_type index() const {
SPROUT_CONSTEXPR difference_type index() const {
return index_;
}
SPROUT_CONSTEXPR index_iterator next() const {
@ -119,24 +115,6 @@ namespace sprout {
sprout::swap(holder_, other.holder_);
sprout::swap(index_, other.index_);
}
friend SPROUT_CONSTEXPR bool operator==(index_iterator const& lhs, index_iterator const& rhs) {
return lhs.index_ == rhs.index_;
}
friend SPROUT_CONSTEXPR bool operator!=(index_iterator const& lhs, index_iterator const& rhs) {
return !(lhs == rhs);
}
friend SPROUT_CONSTEXPR bool operator<(index_iterator const& lhs, index_iterator const& rhs) {
return lhs.index_ < rhs.index_;
}
friend SPROUT_CONSTEXPR bool operator>(index_iterator const& lhs, index_iterator const& rhs) {
return rhs < lhs;
}
friend SPROUT_CONSTEXPR bool operator<=(index_iterator const& lhs, index_iterator const& rhs) {
return !(rhs < lhs);
}
friend SPROUT_CONSTEXPR bool operator>=(index_iterator const& lhs, index_iterator const& rhs) {
return !(lhs < rhs);
}
SPROUT_CONSTEXPR reference operator*() const {
return holder_.get()[index_];
}
@ -182,14 +160,73 @@ namespace sprout {
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
return holder_.get()[index_ + n];
}
friend SPROUT_CONSTEXPR difference_type operator-(index_iterator const& lhs, index_iterator const& rhs) {
return static_cast<difference_type>(lhs.index_) - static_cast<difference_type>(rhs.index_);
}
friend SPROUT_CONSTEXPR index_iterator operator+(difference_type n, index_iterator const& it) {
return it + n;
}
};
template<typename Container1, typename Container2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<Container1>::type, typename std::decay<Container2>::type>::value,
bool
>::type
operator==(sprout::index_iterator<Container1, C> const& lhs, sprout::index_iterator<Container2, C> const& rhs) {
return lhs.index() == rhs.index();
}
template<typename Container1, typename Container2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<Container1>::type, typename std::decay<Container2>::type>::value,
bool
>::type
operator!=(sprout::index_iterator<Container1, C> const& lhs, sprout::index_iterator<Container2, C> const& rhs) {
return !(lhs == rhs);
}
template<typename Container1, typename Container2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<Container1>::type, typename std::decay<Container2>::type>::value,
bool
>::type
operator<(sprout::index_iterator<Container1, C> const& lhs, sprout::index_iterator<Container2, C> const& rhs) {
return lhs.index() < rhs.index();
}
template<typename Container1, typename Container2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<Container1>::type, typename std::decay<Container2>::type>::value,
bool
>::type
operator>(sprout::index_iterator<Container1, C> const& lhs, sprout::index_iterator<Container2, C> const& rhs) {
return rhs < lhs;
}
template<typename Container1, typename Container2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<Container1>::type, typename std::decay<Container2>::type>::value,
bool
>::type
operator<=(sprout::index_iterator<Container1, C> const& lhs, sprout::index_iterator<Container2, C> const& rhs) {
return !(rhs < lhs);
}
template<typename Container1, typename Container2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<Container1>::type, typename std::decay<Container2>::type>::value,
bool
>::type
operator>=(sprout::index_iterator<Container1, C> const& lhs, sprout::index_iterator<Container2, C> const& rhs) {
return !(lhs < rhs);
}
template<typename Container1, typename Container2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<Container1>::type, typename std::decay<Container2>::type>::value,
decltype(
std::declval<typename std::iterator_traits<sprout::index_iterator<Container1, C> >::difference_type>()
- std::declval<typename std::iterator_traits<sprout::index_iterator<Container2, C> >::difference_type>()
)
>::type
operator-(sprout::index_iterator<Container1, C> const& lhs, sprout::index_iterator<Container2, C> const& rhs) {
return lhs.index() - rhs.index();
}
template<typename Container, bool C>
inline SPROUT_CONSTEXPR sprout::index_iterator<Container, C>
operator+(typename sprout::index_iterator<Container, C>::difference_type n, sprout::index_iterator<Container, C> const& it) {
return it + n;
}
//
// swap
//

View file

@ -25,7 +25,7 @@ namespace sprout {
}
template<typename ForwardIterator>
inline SPROUT_CONSTEXPR ForwardIterator
next_impl(ForwardIterator const& it, void*) {
next_impl(ForwardIterator const& it, std::forward_iterator_tag*) {
return std::next(it);
}
@ -79,7 +79,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR ForwardIterator
next_impl_1(
ForwardIterator const& it, typename std::iterator_traits<ForwardIterator>::difference_type n,
void*
std::forward_iterator_tag*
)
{
return n == 0 ? it
@ -95,7 +95,7 @@ namespace sprout {
>::type
next_impl(
ForwardIterator const& it, typename std::iterator_traits<ForwardIterator>::difference_type n,
void*
std::forward_iterator_tag*
)
{
typedef typename std::iterator_traits<ForwardIterator>::iterator_category* category;
@ -108,7 +108,7 @@ namespace sprout {
>::type
next_impl(
ForwardIterator const& it, typename std::iterator_traits<ForwardIterator>::difference_type n,
void*
std::forward_iterator_tag*
)
{
return std::next(it, n);

View file

@ -24,7 +24,7 @@ namespace sprout {
}
template<typename BidirectionalIterator>
inline SPROUT_CONSTEXPR BidirectionalIterator
prev_impl(BidirectionalIterator const& it, void*) {
prev_impl(BidirectionalIterator const& it, std::bidirectional_iterator_tag*) {
return std::prev(it);
}
@ -69,7 +69,7 @@ namespace sprout {
>::type
prev_impl(
BidirectionalIterator const& it, typename std::iterator_traits<BidirectionalIterator>::difference_type n,
void*
std::bidirectional_iterator_tag*
)
{
return n == 0 ? it
@ -84,7 +84,7 @@ namespace sprout {
>::type
prev_impl(
BidirectionalIterator const& it, typename std::iterator_traits<BidirectionalIterator>::difference_type n,
void*
std::bidirectional_iterator_tag*
)
{
return std::prev(it, n);

View file

@ -52,17 +52,14 @@ namespace sprout {
difference_type index_;
public:
SPROUT_CONSTEXPR ptr_index_iterator()
: p_()
, index_()
: p_(), index_()
{}
ptr_index_iterator(ptr_index_iterator const&) = default;
explicit SPROUT_CONSTEXPR ptr_index_iterator(pointer p)
: p_(p)
, index_(0)
: p_(p), index_(0)
{}
SPROUT_CONSTEXPR ptr_index_iterator(pointer p, difference_type index)
: p_(p)
, index_(index)
: p_(p), index_(index)
{}
operator ptr_index_iterator<const_pointer>() const {
return ptr_index_iterator<const_pointer>(p_, index_);
@ -88,24 +85,6 @@ namespace sprout {
sprout::swap(p_, other.p_);
sprout::swap(index_, other.index_);
}
friend SPROUT_CONSTEXPR bool operator==(ptr_index_iterator const& lhs, ptr_index_iterator const& rhs) {
return lhs.index_ == rhs.index_;
}
friend SPROUT_CONSTEXPR bool operator!=(ptr_index_iterator const& lhs, ptr_index_iterator const& rhs) {
return !(lhs == rhs);
}
friend SPROUT_CONSTEXPR bool operator<(ptr_index_iterator const& lhs, ptr_index_iterator const& rhs) {
return lhs.index_ < rhs.index_;
}
friend SPROUT_CONSTEXPR bool operator>(ptr_index_iterator const& lhs, ptr_index_iterator const& rhs) {
return rhs < lhs;
}
friend SPROUT_CONSTEXPR bool operator<=(ptr_index_iterator const& lhs, ptr_index_iterator const& rhs) {
return !(rhs < lhs);
}
friend SPROUT_CONSTEXPR bool operator>=(ptr_index_iterator const& lhs, ptr_index_iterator const& rhs) {
return !(lhs < rhs);
}
SPROUT_CONSTEXPR reference operator*() const {
return p_[index_];
}
@ -151,14 +130,73 @@ namespace sprout {
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
return p_[index_ + n];
}
friend SPROUT_CONSTEXPR difference_type operator-(ptr_index_iterator const& lhs, ptr_index_iterator const& rhs) {
return lhs.index_ - rhs.index_;
}
friend SPROUT_CONSTEXPR ptr_index_iterator operator+(difference_type n, ptr_index_iterator const& it) {
return it + n;
}
};
template<typename T1, typename T2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<T1>::type, typename std::decay<T2>::type>::value,
bool
>::type
operator==(sprout::ptr_index_iterator<T1, C> const& lhs, sprout::ptr_index_iterator<T2, C> const& rhs) {
return lhs.index() == rhs.index();
}
template<typename T1, typename T2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<T1>::type, typename std::decay<T2>::type>::value,
bool
>::type
operator!=(sprout::ptr_index_iterator<T1, C> const& lhs, sprout::ptr_index_iterator<T2, C> const& rhs) {
return !(lhs == rhs);
}
template<typename T1, typename T2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<T1>::type, typename std::decay<T2>::type>::value,
bool
>::type
operator<(sprout::ptr_index_iterator<T1, C> const& lhs, sprout::ptr_index_iterator<T2, C> const& rhs) {
return lhs.index() < rhs.index();
}
template<typename T1, typename T2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<T1>::type, typename std::decay<T2>::type>::value,
bool
>::type
operator>(sprout::ptr_index_iterator<T1, C> const& lhs, sprout::ptr_index_iterator<T2, C> const& rhs) {
return rhs < lhs;
}
template<typename T1, typename T2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<T1>::type, typename std::decay<T2>::type>::value,
bool
>::type
operator<=(sprout::ptr_index_iterator<T1, C> const& lhs, sprout::ptr_index_iterator<T2, C> const& rhs) {
return !(rhs < lhs);
}
template<typename T1, typename T2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<T1>::type, typename std::decay<T2>::type>::value,
bool
>::type
operator>=(sprout::ptr_index_iterator<T1, C> const& lhs, sprout::ptr_index_iterator<T2, C> const& rhs) {
return !(lhs < rhs);
}
template<typename T1, typename T2, bool C>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_same<typename std::decay<T1>::type, typename std::decay<T2>::type>::value,
decltype(
std::declval<typename std::iterator_traits<sprout::ptr_index_iterator<T1, C> >::difference_type>()
- std::declval<typename std::iterator_traits<sprout::ptr_index_iterator<T2, C> >::difference_type>()
)
>::type
operator-(sprout::ptr_index_iterator<T1, C> const& lhs, sprout::ptr_index_iterator<T2, C> const& rhs) {
return lhs.index() - rhs.index();
}
template<typename T, bool C>
inline SPROUT_CONSTEXPR sprout::ptr_index_iterator<T, C>
operator+(typename sprout::ptr_index_iterator<T, C>::difference_type n, sprout::ptr_index_iterator<T, C> const& it) {
return it + n;
}
//
// swap
//

View file

@ -5,7 +5,6 @@
#include <limits>
#include <iterator>
#include <utility>
#include <stdexcept>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/next.hpp>
@ -51,66 +50,45 @@ namespace sprout {
typedef typename base_type::reference reference;
private:
sprout::value_holder<T> holder_;
difference_type count_;
difference_type index_;
private:
SPROUT_CONSTEXPR value_iterator(sprout::value_holder<T> const& r, difference_type count)
: holder_(r), count_(count)
SPROUT_CONSTEXPR value_iterator(sprout::value_holder<T> const& r, difference_type index)
: holder_(r), index_(index)
{}
public:
SPROUT_CONSTEXPR value_iterator()
: holder_(), count_()
: holder_(), index_()
{}
value_iterator(value_iterator const&) = default;
explicit SPROUT_CONSTEXPR value_iterator(
typename sprout::value_holder<T>::param_type p,
difference_type count = std::numeric_limits<difference_type>::max()
difference_type index = std::numeric_limits<difference_type>::max()
)
: holder_(p), count_(count)
: holder_(p), index_(index)
{}
operator value_iterator<const_type>() const {
return value_iterator<const_type>(holder_.get(), count_);
return value_iterator<const_type>(holder_.get(), index_);
}
SPROUT_CONSTEXPR difference_type index() const {
return index_;
}
SPROUT_CONSTEXPR value_iterator next() const {
return value_iterator(holder_, count_ != 0 ? count_ - 1 : count_);
return value_iterator(holder_, index_ - 1);
}
SPROUT_CONSTEXPR value_iterator prev() const {
return value_iterator(holder_, count_ != 0 ? count_ + 1 : count_);
return value_iterator(holder_, index_ + 1);
}
void swap(value_iterator& other)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(holder_, other.holder_)))
{
sprout::swap(holder_, other.holder_);
sprout::swap(count_, other.count_);
}
friend SPROUT_CONSTEXPR bool operator==(value_iterator const& lhs, value_iterator const& rhs) {
return lhs.count_ == rhs.count_ && (lhs.count_ == 0 || lhs.holder_.get() == rhs.holder_.get());
}
friend SPROUT_CONSTEXPR bool operator!=(value_iterator const& lhs, value_iterator const& rhs) {
return !(lhs == rhs);
}
friend SPROUT_CONSTEXPR bool operator<(value_iterator const& lhs, value_iterator const& rhs) {
return lhs.count_ > rhs.count_;
}
friend SPROUT_CONSTEXPR bool operator>(value_iterator const& lhs, value_iterator const& rhs) {
return rhs < lhs;
}
friend SPROUT_CONSTEXPR bool operator<=(value_iterator const& lhs, value_iterator const& rhs) {
return !(rhs < lhs);
}
friend SPROUT_CONSTEXPR bool operator>=(value_iterator const& lhs, value_iterator const& rhs) {
return !(lhs < rhs);
sprout::swap(index_, other.index_);
}
SPROUT_CONSTEXPR reference operator*() const {
return count_ != 0
? holder_.get()
: (throw std::out_of_range("value_iterator<>: dereference at out of range"), holder_.get())
;
return holder_.get();
}
SPROUT_CONSTEXPR pointer operator->() const {
return count_ != 0
? holder_.get_pointer()
: throw std::out_of_range("value_iterator<>: dereference at out of range")
;
return holder_.get_pointer();
}
value_iterator& operator++() {
value_iterator temp(next());
@ -133,32 +111,67 @@ namespace sprout {
return result;
}
SPROUT_CONSTEXPR value_iterator operator+(difference_type n) const {
return value_iterator(holder_, count_ - n);
return value_iterator(holder_, index_ - n);
}
SPROUT_CONSTEXPR value_iterator operator-(difference_type n) const {
return value_iterator(holder_, count_ + n);
return value_iterator(holder_, index_ + n);
}
value_iterator& operator+=(difference_type n) {
value_iterator temp(holder_, count_ - n);
value_iterator temp(holder_, index_ - n);
temp.swap(*this);
return *this;
}
value_iterator& operator-=(difference_type n) {
value_iterator temp(holder_, count_ + n);
value_iterator temp(holder_, index_ + n);
temp.swap(*this);
return *this;
}
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
return holder_.get();
}
friend SPROUT_CONSTEXPR difference_type operator-(value_iterator const& lhs, value_iterator const& rhs) {
return rhs.count_ - lhs.count_;
}
friend SPROUT_CONSTEXPR value_iterator operator+(difference_type n, value_iterator const& it) {
return it + n;
}
};
template<typename T>
inline SPROUT_CONSTEXPR bool
operator==(sprout::value_iterator<T> const& lhs, sprout::value_iterator<T> const& rhs) {
return lhs.index() == rhs.index();
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator!=(sprout::value_iterator<T> const& lhs, sprout::value_iterator<T> const& rhs) {
return !(lhs == rhs);
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator<(sprout::value_iterator<T> const& lhs, sprout::value_iterator<T> const& rhs) {
return rhs.index() < lhs.index();
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator>(sprout::value_iterator<T> const& lhs, sprout::value_iterator<T> const& rhs) {
return rhs < lhs;
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator<=(sprout::value_iterator<T> const& lhs, sprout::value_iterator<T> const& rhs) {
return !(rhs < lhs);
}
template<typename T>
inline SPROUT_CONSTEXPR bool
operator>=(sprout::value_iterator<T> const& lhs, sprout::value_iterator<T> const& rhs) {
return !(lhs < rhs);
}
template<typename T>
inline SPROUT_CONSTEXPR typename sprout::value_iterator<T>::difference_type
operator-(sprout::value_iterator<T> const& lhs, sprout::value_iterator<T> const& rhs) {
return rhs.index() - lhs.index();
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::value_iterator<T>
operator+(typename sprout::value_iterator<T>::difference_type n, sprout::value_iterator<T> const& it) {
return it + n;
}
//
// swap
//

View file

@ -90,7 +90,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR T
accumulate(
InputIterator first, InputIterator last, T init, BinaryOperation binary_op,
void*
std::input_iterator_tag*
)
{
typedef sprout::pair<InputIterator, T> type;

View file

@ -75,7 +75,7 @@ namespace sprout {
dft_element_gen_impl(
InputIterator first, InputIterator last,
typename std::iterator_traits<InputIterator>::value_type::value_type arg,
void*
std::input_iterator_tag*
)
{
return sprout::detail::dft_element_gen_impl_1(first, last, arg);

View file

@ -88,7 +88,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
amplitude_spectrum(
ForwardIterator first, ForwardIterator last, Result const& result,
void*
std::forward_iterator_tag*
)
{
return sprout::fixed::detail::amplitude_spectrum_impl(first, last, result, sprout::size(result));

View file

@ -90,7 +90,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
dft(
ForwardIterator first, ForwardIterator last, Result const& result,
void*
std::forward_iterator_tag*
)
{
return sprout::fixed::detail::dft_impl(first, last, result, sprout::size(result), first, 0);

View file

@ -90,7 +90,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
idft(
ForwardIterator first, ForwardIterator last, Result const& result,
void*
std::forward_iterator_tag*
)
{
return sprout::fixed::detail::idft_impl(first, last, result, sprout::size(result), first, 0);

View file

@ -88,7 +88,7 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type
phase_spectrum(
ForwardIterator first, ForwardIterator last, Result const& result,
void*
std::forward_iterator_tag*
)
{
return sprout::fixed::detail::phase_spectrum_impl(first, last, result, sprout::size(result));

View file

@ -99,7 +99,7 @@ namespace sprout {
inner_product(
InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init,
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2,
void*
std::input_iterator_tag*
)
{
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, T> type;

View file

@ -8,6 +8,7 @@
#include <sprout/type_traits/is_c_str.hpp>
#include <sprout/type_traits/lvalue_reference.hpp>
#include <sprout/type_traits/const_reference.hpp>
#include <sprout/type_traits/common_decay.hpp>
#include <sprout/type_traits/arithmetic_promote.hpp>
#include <sprout/type_traits/float_promote.hpp>
#include <sprout/type_traits/enabler_if.hpp>

View file

@ -0,0 +1,17 @@
#ifndef SPROUT_TYPE_TRAITS_COMMON_DECAY_HPP
#define SPROUT_TYPE_TRAITS_COMMON_DECAY_HPP
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
//
// common_decay
//
template<typename... Types>
struct common_decay
: public std::decay<typename std::common_type<Types...>::type>
{};
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_COMMON_DECAY_HPP