diff --git a/sprout/algorithm/fixed/copy.hpp b/sprout/algorithm/fixed/copy.hpp index d524b16a..198ad235 100644 --- a/sprout/algorithm/fixed/copy.hpp +++ b/sprout/algorithm/fixed/copy.hpp @@ -2,6 +2,8 @@ #define SPROUT_ALGORITHM_FIXED_COPY_HPP #include +#include +#include #include #include #include @@ -13,10 +15,10 @@ namespace sprout { namespace fixed { namespace detail { - template - SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm::type copy_impl( - Iterator first, - Iterator last, + template + SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm::type copy_impl_ra( + RandomAccessIterator first, + RandomAccessIterator last, Result const& result, sprout::index_tuple, typename sprout::fixed_container_traits::difference_type offset, @@ -33,25 +35,148 @@ namespace sprout { )... ); } + template + SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm::type copy( + RandomAccessIterator first, + RandomAccessIterator last, + Result const& result, + std::random_access_iterator_tag* + ) + { + return sprout::fixed::detail::copy_impl_ra( + first, + last, + result, + typename sprout::index_range<0, sprout::fixed_container_traits::fixed_size>::type(), + sprout::fixed_begin_offset(result), + sprout::size(result), + NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(first, last) + ); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::fixed_container_traits::fixed_size == sizeof...(Args), + typename sprout::fixed::result_of::algorithm::type + >::type copy_impl_3( + Result const& result, + Args const&... args + ) + { + return sprout::remake_clone(result, sprout::size(result), args...); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::fixed_container_traits::fixed_size != sizeof...(Args), + typename sprout::fixed::result_of::algorithm::type + >::type copy_impl_3( + Result const& result, + Args const&... args + ) + { + return copy_impl_3(result, args..., *sprout::next(sprout::fixed_begin(result), sizeof...(Args))); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::fixed_container_traits::fixed_size == sizeof...(Args), + typename sprout::fixed::result_of::algorithm::type + >::type copy_impl_2( + InputIterator first, + InputIterator last, + Result const& result, + typename sprout::fixed_container_traits::difference_type offset, + Args const&... args + ) + { + return sprout::remake_clone(result, sprout::size(result), args...); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::fixed_container_traits::fixed_size != sizeof...(Args), + typename sprout::fixed::result_of::algorithm::type + >::type copy_impl_2( + InputIterator first, + InputIterator last, + Result const& result, + typename sprout::fixed_container_traits::difference_type offset, + Args const&... args + ) + { + return first != last && sizeof...(Args) < static_cast(offset) + ? copy_impl_2(sprout::next(first), last, result, offset, args..., *first) + : copy_impl_3(result, args...) + ; + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::fixed_container_traits::fixed_size == sizeof...(Args), + typename sprout::fixed::result_of::algorithm::type + >::type copy_impl_1( + InputIterator first, + InputIterator last, + Result const& result, + typename sprout::fixed_container_traits::difference_type offset, + Args const&... args + ) + { + return sprout::remake_clone(result, sprout::size(result), args...); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::fixed_container_traits::fixed_size != sizeof...(Args), + typename sprout::fixed::result_of::algorithm::type + >::type copy_impl_1( + InputIterator first, + InputIterator last, + Result const& result, + typename sprout::fixed_container_traits::difference_type offset, + Args const&... args + ) + { + return sizeof...(Args) < static_cast(offset) + ? copy_impl_1(first, last, result, offset, args..., *sprout::next(sprout::fixed_begin(result), sizeof...(Args))) + : copy_impl_2(first, last, result, offset + sprout::size(result), args...) + ; + } + template + SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm::type copy_impl( + InputIterator first, + InputIterator last, + Result const& result + ) + { + return copy_impl_1(first, last, result, sprout::fixed_begin_offset(result)); + } + template + SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm::type copy( + InputIterator first, + InputIterator last, + Result const& result, + void* + ) + { + return sprout::fixed::detail::copy_impl( + first, + last, + result + ); + } } // namespace detail // // copy // - template + template SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm::type copy( - Iterator first, - Iterator last, + InputIterator first, + InputIterator last, Result const& result ) { - return sprout::fixed::detail::copy_impl( + typedef typename std::iterator_traits::iterator_category* category; + return sprout::fixed::detail::copy( first, last, result, - typename sprout::index_range<0, sprout::fixed_container_traits::fixed_size>::type(), - sprout::fixed_begin_offset(result), - sprout::size(result), - NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(first, last) + category() ); } } // namespace fixed diff --git a/sprout/algorithm/fixed/copy_if.hpp b/sprout/algorithm/fixed/copy_if.hpp index e8c44bb3..13d9e2d7 100644 --- a/sprout/algorithm/fixed/copy_if.hpp +++ b/sprout/algorithm/fixed/copy_if.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include namespace sprout { @@ -33,13 +33,13 @@ namespace sprout { { return copy_if_impl_3(result, args..., *sprout::next(sprout::fixed_begin(result), sizeof...(Args))); } - template + template SPROUT_CONSTEXPR inline typename std::enable_if< sprout::fixed_container_traits::fixed_size == sizeof...(Args), typename sprout::fixed::result_of::algorithm::type >::type copy_if_impl_2( - Iterator first, - Iterator last, + InputIterator first, + InputIterator last, Result const& result, Predicate pred, typename sprout::fixed_container_traits::difference_type offset, @@ -48,33 +48,33 @@ namespace sprout { { return sprout::remake_clone(result, sprout::size(result), args...); } - template + template SPROUT_CONSTEXPR inline typename std::enable_if< sprout::fixed_container_traits::fixed_size != sizeof...(Args), typename sprout::fixed::result_of::algorithm::type >::type copy_if_impl_2( - Iterator first, - Iterator last, + InputIterator first, + InputIterator last, Result const& result, Predicate pred, typename sprout::fixed_container_traits::difference_type offset, Args const&... args ) { - return first != last && sizeof...(Args) < offset + return first != last && sizeof...(Args) < static_cast(offset) ? pred(*first) ? copy_if_impl_2(sprout::next(first), last, result, pred, offset, args..., *first) : copy_if_impl_2(sprout::next(first), last, result, pred, offset, args...) : copy_if_impl_3(result, args...) ; } - template + template SPROUT_CONSTEXPR inline typename std::enable_if< sprout::fixed_container_traits::fixed_size == sizeof...(Args), typename sprout::fixed::result_of::algorithm::type >::type copy_if_impl_1( - Iterator first, - Iterator last, + InputIterator first, + InputIterator last, Result const& result, Predicate pred, typename sprout::fixed_container_traits::difference_type offset, @@ -83,28 +83,28 @@ namespace sprout { { return sprout::remake_clone(result, sprout::size(result), args...); } - template + template SPROUT_CONSTEXPR inline typename std::enable_if< sprout::fixed_container_traits::fixed_size != sizeof...(Args), typename sprout::fixed::result_of::algorithm::type >::type copy_if_impl_1( - Iterator first, - Iterator last, + InputIterator first, + InputIterator last, Result const& result, Predicate pred, typename sprout::fixed_container_traits::difference_type offset, Args const&... args ) { - return sizeof...(Args) < offset + return sizeof...(Args) < static_cast(offset) ? copy_if_impl_1(first, last, result, pred, offset, args..., *sprout::next(sprout::fixed_begin(result), sizeof...(Args))) : copy_if_impl_2(first, last, result, pred, offset + sprout::size(result), args...) ; } - template + template SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm::type copy_if_impl( - Iterator first, - Iterator last, + InputIterator first, + InputIterator last, Result const& result, Predicate pred ) @@ -115,10 +115,10 @@ namespace sprout { // // copy_if // - template + template SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm::type copy_if( - Iterator first, - Iterator last, + InputIterator first, + InputIterator last, Result const& result, Predicate pred ) diff --git a/sprout/algorithm/fixed/copy_n.hpp b/sprout/algorithm/fixed/copy_n.hpp index d554faf8..88f26f96 100644 --- a/sprout/algorithm/fixed/copy_n.hpp +++ b/sprout/algorithm/fixed/copy_n.hpp @@ -20,14 +20,10 @@ namespace sprout { Result const& result ) { - return sprout::fixed::detail::copy_impl( + return sprout::fixed::copy( first, sprout::next(first, n), - result, - typename sprout::index_range<0, sprout::fixed_container_traits::fixed_size>::type(), - sprout::fixed_begin_offset(result), - sprout::size(result), - n + result ); } } // namespace fixed diff --git a/sprout/iterator/next.hpp b/sprout/iterator/next.hpp index 13324e2e..54843544 100644 --- a/sprout/iterator/next.hpp +++ b/sprout/iterator/next.hpp @@ -20,12 +20,13 @@ namespace sprout { return sprout::forward(it) + 1; } template - Iterator next_impl( + SPROUT_CONSTEXPR typename std::decay::type next_impl( Iterator&& it, void* ) { - return std::next(sprout::forward(it)); + using std::next; + return next(sprout::forward(it)); } template @@ -41,13 +42,14 @@ namespace sprout { return sprout::forward(it) + n; } template - Iterator next_impl( + SPROUT_CONSTEXPR typename std::decay::type next_impl( Iterator it, typename std::iterator_traits::type>::difference_type n, void* ) { - return std::next(sprout::forward(it), n); + using std::next; + return next(sprout::forward(it), n); } } // namespace detail // diff --git a/sprout/random/random_iterator.hpp b/sprout/random/random_iterator.hpp index 0969dfe9..4ac68dea 100644 --- a/sprout/random/random_iterator.hpp +++ b/sprout/random/random_iterator.hpp @@ -306,18 +306,18 @@ namespace sprout { { return sprout::random::random_iterator(); } - } // namespace random - // - // next - // - template - SPROUT_CONSTEXPR sprout::random::random_iterator next( - sprout::random::random_iterator const& it - ) - { - return it(); - } + // + // next + // + template + SPROUT_CONSTEXPR sprout::random::random_iterator next( + sprout::random::random_iterator const& it + ) + { + return it(); + } + } // namespace random using sprout::random::random_iterator; } // namespace sprout diff --git a/sprout/random/random_result.hpp b/sprout/random/random_result.hpp index 6e70298b..c24dda70 100644 --- a/sprout/random/random_result.hpp +++ b/sprout/random/random_result.hpp @@ -23,7 +23,7 @@ namespace sprout { typename std::enable_if::value>::type > : public std::iterator< - std::forward_iterator_tag, + std::input_iterator_tag, typename Distribution::result_type, std::ptrdiff_t, typename Distribution::result_type const*, @@ -36,7 +36,7 @@ namespace sprout { typedef typename distribution_type::result_type result_type; private: typedef std::iterator< - std::forward_iterator_tag, + std::input_iterator_tag, result_type, std::ptrdiff_t, result_type const*, @@ -137,7 +137,7 @@ namespace sprout { typename std::enable_if::value>::type > : public std::iterator< - std::forward_iterator_tag, + std::input_iterator_tag, typename Engine::result_type, std::ptrdiff_t, typename Engine::result_type const*, @@ -149,7 +149,7 @@ namespace sprout { typedef typename engine_type::result_type result_type; private: typedef std::iterator< - std::forward_iterator_tag, + std::input_iterator_tag, result_type, std::ptrdiff_t, result_type const*,