From d435c59657d0d1b1b0bc641d1cf6a6f7ef9a8c75 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Tue, 9 Jul 2013 23:15:53 +0900 Subject: [PATCH] fix _va, _Ntail placeholder: can be placed any positions --- sprout/functional/bind/bind.hpp | 297 ++++++++++++++++-------- sprout/type/algorithm.hpp | 1 + sprout/type/algorithm/find_index.hpp | 8 +- sprout/type/algorithm/find_index_if.hpp | 45 ++++ sprout/type/seq/algorithm/find.hpp | 12 +- sprout/type/seq/algorithm/find_if.hpp | 12 +- 6 files changed, 254 insertions(+), 121 deletions(-) create mode 100644 sprout/type/algorithm/find_index_if.hpp diff --git a/sprout/functional/bind/bind.hpp b/sprout/functional/bind/bind.hpp index 08e14026..84c7dbf4 100644 --- a/sprout/functional/bind/bind.hpp +++ b/sprout/functional/bind/bind.hpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include #include @@ -71,7 +73,6 @@ namespace sprout { public: template SPROUT_CONSTEXPR result_type operator()(CVRef& arg, Tuple&) const volatile { - //return arg.get(); // ??? return const_cast::type>::type&>(arg).get(); } }; @@ -82,7 +83,6 @@ namespace sprout { public: template SPROUT_CONSTEXPR result_type operator()(CVRef& arg, Tuple&) const volatile { - //return arg.get(); // ??? return const_cast::type>::type&>(arg).get(); } }; @@ -188,86 +188,183 @@ namespace sprout { return sprout::tuples::get(const_cast const&>(tuple)); } - template - struct is_variadic_bounds - : public std::false_type - {}; - template - struct is_variadic_bounds< - Bounds, - typename std::enable_if::value>::type - > + template + struct is_variadic_placeholder : public std::integral_constant< bool, - (sprout::is_placeholder::value - 1, Bounds>::type>::value + (sprout::is_placeholder::value <= sprout::is_placeholder::value ) > {}; + struct is_variadic_placeholder_pred { + public: + template + struct apply + : public sprout::detail::is_variadic_placeholder + {}; + }; template - struct tail_bounds_place + struct is_variadic_bounds + : public std::integral_constant< + bool, + (sprout::types::find_index_if::value != sprout::tuples::tuple_size::value) + > + {}; + + template + struct tail_place : public std::integral_constant {}; - template - struct tail_bounds_place< - Bounds, - typename std::enable_if::value>::type + template + struct tail_place< + T, + typename std::enable_if::value>::type > : public std::integral_constant< int, (sprout::is_placeholder::value - - sprout::is_placeholder::value - 1, Bounds>::type>::value + - sprout::is_placeholder::value ) > {}; - template - struct bounds_size + template + struct bound_size + : public std::integral_constant + {}; + template + struct bound_size< + T, ArgSize, + typename std::enable_if::value>::type + > : public std::integral_constant< std::size_t, - sprout::detail::is_variadic_bounds::value - ? (sprout::tuples::tuple_size::value - 1) + (sizeof...(Args) - sprout::detail::tail_bounds_place::value) - : sprout::tuples::tuple_size::value - > - {}; - - template - struct bound_indexes - : public sprout::make_index_tuple::value> - {}; - - template - struct is_variadic_part - : public std::integral_constant< - bool, - sprout::detail::is_variadic_bounds::value && (I >= sprout::tuples::tuple_size::value) + (ArgSize - sprout::detail::tail_place::value) > {}; - template - struct bound_element - : public sprout::tuples::tuple_element + template + struct bounds_size_impl + : public std::integral_constant {}; - template - struct bound_element< - I, Bounds, - typename std::enable_if::value>::type - > { + template + struct bounds_size_impl< + I, Bounds, ArgSize, + typename std::enable_if<(I < sprout::tuples::tuple_size::value)>::type + > + : public std::integral_constant< + std::size_t, + (sprout::detail::bound_size::type, ArgSize>::value + + sprout::detail::bounds_size_impl::value + ) + > + {}; + template + struct bounds_size + : public sprout::detail::bounds_size_impl<0, Bounds, ArgSize> + {}; + + template + struct bounds_partial_size_impl { public: - typedef sprout::placeholder::value + sprout::detail::tail_bounds_place::value + 1> type; + typedef Seq type; + }; + template + struct bounds_partial_size_impl< + I, Bounds, ArgSize, Current, sprout::types::integral_array, + typename std::enable_if<(I < sprout::tuples::tuple_size::value)>::type + > + : public sprout::detail::bounds_partial_size_impl< + I + 1, Bounds, ArgSize, + Current + sprout::detail::bound_size::type, ArgSize>::value, + sprout::types::integral_array + > + {}; + template + struct bounds_partial_size + : public sprout::detail::bounds_partial_size_impl<0, Bounds, ArgSize, 0, sprout::types::integral_array > + {}; + + template + struct bound_indexes + : public sprout::make_index_tuple::value> + {}; + + struct meta_less_ { + public: + template + struct apply + : public std::integral_constant + {}; }; - template - struct complete_bounds_impl; - template - struct complete_bounds_impl > { + template + struct lower_bound_index_impl + : public std::integral_constant + {}; + template + struct lower_bound_index_impl< + I, Tuple, T, Compare, + typename std::enable_if<(I < sprout::tuples::tuple_size::value)>::type + > + : public std::conditional< + Compare::template apply::type, T>::type::value, + sprout::detail::lower_bound_index_impl, + std::integral_constant + >::type + {}; + template + struct lower_bound_index + : public sprout::detail::lower_bound_index_impl<0, Tuple, T, Compare> + {}; + + template + struct bound_position + : public std::integral_constant< + sprout::index_t, + (sprout::detail::lower_bound_index< + typename sprout::detail::bounds_partial_size::type, + std::integral_constant + >::type::value - 1 + ) + > + {}; + + template + struct is_variadic_part + : public sprout::detail::is_variadic_placeholder< + typename sprout::tuples::tuple_element< + sprout::detail::bound_position::value, + Bounds + >::type + > + {}; + + template + struct bound_element_impl + : public sprout::tuples::tuple_element + {}; + template + struct bound_element_impl< + I, Bounds, ArgSize, BoundPos, SizeSeq, + typename std::enable_if::value>::type + > { public: - typedef sprout::tuples::tuple...> type; + typedef sprout::placeholder< + (I + 1 + - sprout::tuples::tuple_element::type::value + + sprout::detail::tail_place::type>::value + ) + > type; }; - template - struct complete_bounds - : public sprout::detail::complete_bounds_impl::type> + template + struct bound_element + : public sprout::detail::bound_element_impl< + I, Bounds, ArgSize, sprout::detail::bound_position::value, + typename sprout::detail::bounds_partial_size::type + > {}; struct get_bound_helper { @@ -314,23 +411,29 @@ namespace sprout { } }; template< - sprout::index_t I, typename Bounds, - typename sprout::enabler_if::type>::value>::type = sprout::enabler + sprout::index_t I, std::size_t ArgSize, typename Bounds, + typename sprout::enabler_if::type, ArgSize>::value>::type = sprout::enabler > - inline SPROUT_CONSTEXPR typename sprout::detail::bound_element::type>::type + inline SPROUT_CONSTEXPR typename sprout::detail::bound_element::type, ArgSize>::type get_bound(Bounds&&) { - typedef typename sprout::detail::bound_element::type>::type type; + typedef typename sprout::detail::bound_element::type, ArgSize>::type type; return type(); } template< - sprout::index_t I, typename Bounds, - typename sprout::enabler_if::type>::value>::type = sprout::enabler + sprout::index_t I, std::size_t ArgSize, typename Bounds, + typename sprout::enabler_if::type, ArgSize>::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR auto get_bound(Bounds&& bound_args) - -> decltype(sprout::detail::get_bound_helper::get_bound(std::forward(bound_args))) + -> decltype( + sprout::detail::get_bound_helper::get_bound< + sprout::detail::bound_position::type, ArgSize>::value + >(std::forward(bound_args)) + ) { - return sprout::detail::get_bound_helper::get_bound(std::forward(bound_args)); + return sprout::detail::get_bound_helper::get_bound< + sprout::detail::bound_position::type, ArgSize>::value + >(std::forward(bound_args)); } } // namespace detail @@ -353,29 +456,29 @@ namespace sprout { template Result call(sprout::tuples::tuple&& args, sprout::index_tuple) { return f_( - sprout::detail::mu::type>() - (sprout::detail::get_bound(bound_args_), args)... + sprout::detail::mu::type>() + (sprout::detail::get_bound(bound_args_), args)... ); } template SPROUT_CONSTEXPR Result call_c(sprout::tuples::tuple&& args, sprout::index_tuple) const { return f_( - sprout::detail::mu::type const>() - (sprout::detail::get_bound(bound_args_), args)... + sprout::detail::mu::type const>() + (sprout::detail::get_bound(bound_args_), args)... ); } template Result call_v(sprout::tuples::tuple&& args, sprout::index_tuple) volatile { return f_( - sprout::detail::mu::type volatile>() - (sprout::detail::get_bound(bound_args_), args)... + sprout::detail::mu::type volatile>() + (sprout::detail::get_bound(bound_args_), args)... ); } template SPROUT_CONSTEXPR Result call_cv(sprout::tuples::tuple&& args, sprout::index_tuple) const volatile { return f_( - sprout::detail::mu::type const volatile>() - (sprout::detail::get_bound(bound_args_), args)... + sprout::detail::mu::type const volatile>() + (sprout::detail::get_bound(bound_args_), args)... ); } private: @@ -384,8 +487,8 @@ namespace sprout { > static SPROUT_CONSTEXPR decltype( std::declval()( - sprout::detail::mu::type>() - (sprout::detail::get_bound(std::declval()), std::declval&>())... + sprout::detail::mu::type>() + (sprout::detail::get_bound(std::declval()), std::declval&>())... ) ) call_(sprout::tuples::tuple&& args, sprout::index_tuple); @@ -394,8 +497,8 @@ namespace sprout { > static SPROUT_CONSTEXPR decltype( std::declval= 0), typename std::add_const::type>::type&>()( - sprout::detail::mu::type const>() - (sprout::detail::get_bound(std::declval()), std::declval&>())... + sprout::detail::mu::type const>() + (sprout::detail::get_bound(std::declval()), std::declval&>())... ) ) call_c_(sprout::tuples::tuple&& args, sprout::index_tuple); @@ -404,8 +507,8 @@ namespace sprout { > static SPROUT_CONSTEXPR decltype( std::declval= 0), typename std::add_volatile::type>::type&>()( - sprout::detail::mu::type volatile>() - (sprout::detail::get_bound(std::declval()), std::declval&>())... + sprout::detail::mu::type volatile>() + (sprout::detail::get_bound(std::declval()), std::declval&>())... ) ) call_v_(sprout::tuples::tuple&& args, sprout::index_tuple); @@ -414,8 +517,8 @@ namespace sprout { > static SPROUT_CONSTEXPR decltype( std::declval= 0), typename std::add_cv::type>::type&>()( - sprout::detail::mu::type const volatile>() - (sprout::detail::get_bound(std::declval()), std::declval&>())... + sprout::detail::mu::type const volatile>() + (sprout::detail::get_bound(std::declval()), std::declval&>())... ) ) call_cv_(sprout::tuples::tuple&& args, sprout::index_tuple); @@ -429,49 +532,49 @@ namespace sprout { template< typename... Args, typename Result = decltype( - call_(std::declval >(), sprout::detail::bound_indexes::make()) + call_(std::declval >(), sprout::detail::bound_indexes::make()) ) > Result operator()(Args&&... args) { return call( sprout::tuples::forward_as_tuple(sprout::forward(args)...), - sprout::detail::bound_indexes::make() + sprout::detail::bound_indexes::make() ); } template< typename... Args, typename Result = decltype( - call_c_(std::declval >(), sprout::detail::bound_indexes::make()) + call_c_(std::declval >(), sprout::detail::bound_indexes::make()) ) > SPROUT_CONSTEXPR Result operator()(Args&&... args) const { return call_c( sprout::tuples::forward_as_tuple(sprout::forward(args)...), - sprout::detail::bound_indexes::make() + sprout::detail::bound_indexes::make() ); } template< typename... Args, typename Result = decltype( - call_v_(std::declval >(), sprout::detail::bound_indexes::make()) + call_v_(std::declval >(), sprout::detail::bound_indexes::make()) ) > Result operator()(Args&&... args) volatile { return call_v( sprout::tuples::forward_as_tuple(sprout::forward(args)...), - sprout::detail::bound_indexes::make() + sprout::detail::bound_indexes::make() ); } template< typename... Args, typename Result = decltype( - call_cv_(std::declval >(), sprout::detail::bound_indexes::make()) + call_cv_(std::declval >(), sprout::detail::bound_indexes::make()) ) > SPROUT_CONSTEXPR Result operator()(Args&&... args) const volatile { return call_cv( sprout::tuples::forward_as_tuple(sprout::forward(args)...), - sprout::detail::bound_indexes::make() + sprout::detail::bound_indexes::make() ); } }; @@ -506,7 +609,7 @@ namespace sprout { typename disable_if_void::type = 0 ) { - return f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); + return f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); } template Result call( @@ -515,7 +618,7 @@ namespace sprout { typename enable_if_void::type = 0 ) { - f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); + f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); } template SPROUT_CONSTEXPR Result call( @@ -524,7 +627,7 @@ namespace sprout { typename disable_if_void::type = 0 ) const { - return f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); + return f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); } template Result call( @@ -533,7 +636,7 @@ namespace sprout { typename enable_if_void::type = 0 ) const { - f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); + f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); } template Result call( @@ -542,7 +645,7 @@ namespace sprout { typename disable_if_void::type = 0 ) volatile { - return f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); + return f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); } template Result call( @@ -551,7 +654,7 @@ namespace sprout { typename enable_if_void::type = 0 ) volatile { - f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); + f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); } template SPROUT_CONSTEXPR Result call( @@ -560,7 +663,7 @@ namespace sprout { typename disable_if_void::type = 0 ) const volatile { - return f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); + return f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); } template Result call( @@ -569,7 +672,7 @@ namespace sprout { typename enable_if_void::type = 0 ) const volatile { - f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); + f_(sprout::detail::mu()(sprout::detail::get_bound(bound_args_), args)...); } public: typedef Result result_type; @@ -583,28 +686,28 @@ namespace sprout { result_type operator()(Args&&... args) { return call( sprout::tuples::forward_as_tuple(sprout::forward(args)...), - sprout::detail::bound_indexes::make() + sprout::detail::bound_indexes::make() ); } template SPROUT_CONSTEXPR result_type operator()(Args&&... args) const { return call( sprout::tuples::forward_as_tuple(sprout::forward(args)...), - sprout::detail::bound_indexes::make() + sprout::detail::bound_indexes::make() ); } template result_type operator()(Args&&... args) volatile { return call( sprout::tuples::forward_as_tuple(sprout::forward(args)...), - sprout::detail::bound_indexes::make() + sprout::detail::bound_indexes::make() ); } template SPROUT_CONSTEXPR result_type operator()(Args&&... args) const volatile { return call( sprout::tuples::forward_as_tuple(sprout::forward(args)...), - sprout::detail::bound_indexes::make() + sprout::detail::bound_indexes::make() ); } }; diff --git a/sprout/type/algorithm.hpp b/sprout/type/algorithm.hpp index 8a816908..16097cdd 100644 --- a/sprout/type/algorithm.hpp +++ b/sprout/type/algorithm.hpp @@ -3,5 +3,6 @@ #include #include +#include #endif // #ifndef SPROUT_TYPE_ALGORITHM_HPP diff --git a/sprout/type/algorithm/find_index.hpp b/sprout/type/algorithm/find_index.hpp index 0b925d0f..6fcf56ea 100644 --- a/sprout/type/algorithm/find_index.hpp +++ b/sprout/type/algorithm/find_index.hpp @@ -13,9 +13,7 @@ namespace sprout { struct find_index_impl; template struct find_index_impl< - Tuple, - T, - I, + Tuple, T, I, typename std::enable_if< I == sprout::types::tuple_size::value || std::is_same::type, T>::value @@ -25,9 +23,7 @@ namespace sprout { {}; template struct find_index_impl< - Tuple, - T, - I, + Tuple, T, I, typename std::enable_if< I != sprout::types::tuple_size::value && !std::is_same::type, T>::value diff --git a/sprout/type/algorithm/find_index_if.hpp b/sprout/type/algorithm/find_index_if.hpp new file mode 100644 index 00000000..7e922858 --- /dev/null +++ b/sprout/type/algorithm/find_index_if.hpp @@ -0,0 +1,45 @@ +#ifndef SPROUT_TYPE_ALGORITHM_FIND_INDEX_IF_HPP +#define SPROUT_TYPE_ALGORITHM_FIND_INDEX_IF_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace types { + namespace detail { + template + struct find_index_if_impl; + template + struct find_index_if_impl< + Tuple, Predicate, I, + typename std::enable_if< + I == sprout::types::tuple_size::value + || Predicate::template apply::type>::type::value + >::type + > + : public std::integral_constant + {}; + template + struct find_index_if_impl< + Tuple, Predicate, I, + typename std::enable_if< + I != sprout::types::tuple_size::value + && !Predicate::template apply::type>::type::value + >::type + > + : public sprout::types::detail::find_index_if_impl + {}; + } // namespace detail + // + // find_index_if + // + template + struct find_index_if + : public sprout::types::detail::find_index_if_impl + {}; + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_ALGORITHM_FIND_INDEX_IF_HPP diff --git a/sprout/type/seq/algorithm/find.hpp b/sprout/type/seq/algorithm/find.hpp index 89195fc7..40ed4f34 100644 --- a/sprout/type/seq/algorithm/find.hpp +++ b/sprout/type/seq/algorithm/find.hpp @@ -13,9 +13,7 @@ namespace sprout { struct find_impl; template struct find_impl< - First, - Last, - T, + First, Last, T, typename std::enable_if< std::is_same::value >::type @@ -25,9 +23,7 @@ namespace sprout { }; template struct find_impl< - First, - Last, - T, + First, Last, T, typename std::enable_if< !std::is_same::value && std::is_same::type, T>::value @@ -38,9 +34,7 @@ namespace sprout { }; template struct find_impl< - First, - Last, - T, + First, Last, T, typename std::enable_if< !std::is_same::value && !std::is_same::type, T>::value diff --git a/sprout/type/seq/algorithm/find_if.hpp b/sprout/type/seq/algorithm/find_if.hpp index 6cd3ff0e..a2372d32 100644 --- a/sprout/type/seq/algorithm/find_if.hpp +++ b/sprout/type/seq/algorithm/find_if.hpp @@ -13,9 +13,7 @@ namespace sprout { struct find_if_impl; template struct find_if_impl< - First, - Last, - Predicate, + First, Last, Predicate, typename std::enable_if< std::is_same::value >::type @@ -25,9 +23,7 @@ namespace sprout { }; template struct find_if_impl< - First, - Last, - Predicate, + First, Last, Predicate, typename std::enable_if< !std::is_same::value && Predicate::template apply::type>::type::value @@ -38,9 +34,7 @@ namespace sprout { }; template struct find_if_impl< - First, - Last, - Predicate, + First, Last, Predicate, typename std::enable_if< !std::is_same::value && !Predicate::template apply::type>::type::value