From 28e9a4e5d996220ec2b01b2d39fbc5af197dcea8 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sun, 13 Jul 2014 01:41:33 +0900 Subject: [PATCH] add extension index_iterator --- sprout/iterator/index_iterator.hpp | 10 ++++++---- testspr/iterator.hpp | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sprout/iterator/index_iterator.hpp b/sprout/iterator/index_iterator.hpp index 8cd454fb..d863b9ed 100644 --- a/sprout/iterator/index_iterator.hpp +++ b/sprout/iterator/index_iterator.hpp @@ -23,12 +23,13 @@ #include #include #include +#include namespace sprout { // // index_iterator // - template + template > class index_iterator : public std::iterator< std::random_access_iterator_tag, @@ -64,6 +65,7 @@ namespace sprout { typename std::remove_reference::type const >::type const_container_type; private: + typedef Subscript subscript_type; typedef std::iterator< std::random_access_iterator_tag, typename traits_type::value_type, @@ -127,10 +129,10 @@ namespace sprout { sprout::swap(index_, other.index_); } SPROUT_CONSTEXPR reference operator*() const { - return holder_.get()[index_]; + return subscript_type()(holder_.get(), index_); } SPROUT_CONSTEXPR pointer operator->() const { - return &holder_.get()[index_]; + return &subscript_type()(holder_.get(), index_); } SPROUT_CXX14_CONSTEXPR index_iterator& operator++() { index_iterator temp(next()); @@ -169,7 +171,7 @@ namespace sprout { return *this; } SPROUT_CONSTEXPR reference operator[](difference_type n) const { - return holder_.get()[index_ + n]; + return subscript_type()(holder_.get(), index_ + n); } }; diff --git a/testspr/iterator.hpp b/testspr/iterator.hpp index 9a3f2852..dd828ed2 100644 --- a/testspr/iterator.hpp +++ b/testspr/iterator.hpp @@ -45,7 +45,7 @@ namespace testspr { SPROUT_CONSTEXPR reduct_iterator() : current() {} - SPROUT_CONSTEXPR reduct_iterator(reduct_iterator const& other) = default; + reduct_iterator(reduct_iterator const& other) = default; explicit SPROUT_CONSTEXPR reduct_iterator(iterator_type it) : current(it) {}