From f45298f81f68f612fcd97fdf74b551365809a67a Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Thu, 29 May 2014 13:30:51 +0900 Subject: [PATCH] add iterator_traits: SFINAE-friendly version --- sprout/iterator.hpp | 1 + sprout/iterator/iterator_traits.hpp | 50 +++++++++++++++++++++ sprout/iterator/type_traits/is_iterator.hpp | 4 +- 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 sprout/iterator/iterator_traits.hpp diff --git a/sprout/iterator.hpp b/sprout/iterator.hpp index 6be98789..e5a03ae4 100644 --- a/sprout/iterator.hpp +++ b/sprout/iterator.hpp @@ -9,6 +9,7 @@ #define SPROUT_ITERATOR_HPP #include +#include #include #include #include diff --git a/sprout/iterator/iterator_traits.hpp b/sprout/iterator/iterator_traits.hpp new file mode 100644 index 00000000..becf0a8c --- /dev/null +++ b/sprout/iterator/iterator_traits.hpp @@ -0,0 +1,50 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_ITERATOR_ITERATOR_TRAITS_HPP +#define SPROUT_ITERATOR_ITERATOR_TRAITS_HPP + +#include +#include +#include +#include + +namespace sprout { + // + // iterator_traits + // + namespace detail { + template + struct iterator_traits_impl + : public sprout::detail::nil_base + {}; + template + struct iterator_traits_impl< + Iterator, + typename sprout::head_element< + void, + typename Iterator::difference_type, + typename Iterator::value_type, + typename Iterator::pointer, + typename Iterator::reference, + typename Iterator::iterator_category + >::type + > + : public std::iterator_traits + {}; + } // namespace detail + template + struct iterator_traits + : public sprout::detail::iterator_traits_impl + {}; + template + struct iterator_traits + : public std::iterator_traits + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_ITERATOR_ITERATOR_TRAITS_HPP diff --git a/sprout/iterator/type_traits/is_iterator.hpp b/sprout/iterator/type_traits/is_iterator.hpp index 2db2eb60..93029c27 100644 --- a/sprout/iterator/type_traits/is_iterator.hpp +++ b/sprout/iterator/type_traits/is_iterator.hpp @@ -8,9 +8,9 @@ #ifndef SPROUT_ITERATOR_TYPE_TRAITS_IS_ITERATOR_HPP #define SPROUT_ITERATOR_TYPE_TRAITS_IS_ITERATOR_HPP -#include #include #include +#include namespace sprout { namespace detail { @@ -25,7 +25,7 @@ namespace sprout { // template struct is_iterator - : public sprout::detail::has_iterator_category > + : public sprout::detail::has_iterator_category > {}; #if SPROUT_USE_VARIABLE_TEMPLATES