add iterator_traits: SFINAE-friendly version

This commit is contained in:
bolero-MURAKAMI 2014-05-29 13:30:51 +09:00
parent c15de6136b
commit f45298f81f
3 changed files with 53 additions and 2 deletions

View file

@ -9,6 +9,7 @@
#define SPROUT_ITERATOR_HPP #define SPROUT_ITERATOR_HPP
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/iterator/iterator_traits.hpp>
#include <sprout/iterator/type_traits.hpp> #include <sprout/iterator/type_traits.hpp>
#include <sprout/iterator/operation.hpp> #include <sprout/iterator/operation.hpp>
#include <sprout/iterator/predefined.hpp> #include <sprout/iterator/predefined.hpp>

View file

@ -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 <iterator>
#include <sprout/config.hpp>
#include <sprout/utility/pack.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
//
// iterator_traits
//
namespace detail {
template<typename Iterator, typename = void>
struct iterator_traits_impl
: public sprout::detail::nil_base
{};
template<typename Iterator>
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<Iterator>
{};
} // namespace detail
template<typename Iterator>
struct iterator_traits
: public sprout::detail::iterator_traits_impl<Iterator>
{};
template<typename T>
struct iterator_traits<T*>
: public std::iterator_traits<T*>
{};
} // namespace sprout
#endif // #ifndef SPROUT_ITERATOR_ITERATOR_TRAITS_HPP

View file

@ -8,9 +8,9 @@
#ifndef SPROUT_ITERATOR_TYPE_TRAITS_IS_ITERATOR_HPP #ifndef SPROUT_ITERATOR_TYPE_TRAITS_IS_ITERATOR_HPP
#define SPROUT_ITERATOR_TYPE_TRAITS_IS_ITERATOR_HPP #define SPROUT_ITERATOR_TYPE_TRAITS_IS_ITERATOR_HPP
#include <iterator>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/type_traits/has_xxx.hpp> #include <sprout/type_traits/has_xxx.hpp>
#include <sprout/iterator/iterator_traits.hpp>
namespace sprout { namespace sprout {
namespace detail { namespace detail {
@ -25,7 +25,7 @@ namespace sprout {
// //
template<typename T> template<typename T>
struct is_iterator struct is_iterator
: public sprout::detail::has_iterator_category<std::iterator_traits<T> > : public sprout::detail::has_iterator_category<sprout::iterator_traits<T> >
{}; {};
#if SPROUT_USE_VARIABLE_TEMPLATES #if SPROUT_USE_VARIABLE_TEMPLATES