2
0
mirror of https://github.com/boostorg/hof.git synced 2026-01-23 17:42:40 +00:00

Change args to take an integral constant, and make it return a function. Deprecate the old usage

This commit is contained in:
Paul
2015-04-24 21:19:52 -05:00
parent be971a6414
commit 9f50dd3308
3 changed files with 42 additions and 11 deletions

View File

@@ -18,19 +18,21 @@
/// Description
/// -----------
///
/// The `args` function returns the Nth argument passed to it. It actually
/// starts at 1, so it is not the zero-based index of the argument.
/// The `args` returns a function object that returns the Nth argument passed
/// to it. It actually starts at 1, so it is not the zero-based index of the
/// argument.
///
/// Synopsis
/// --------
///
/// template<int N, class... Ts>
/// constexpr auto args(Ts&&... xs);
/// template<class IntegralConstant>
/// constexpr auto args(IntegralConstant);
///
///
/// Example
/// -------
///
/// assert(args<3>(1,2,3,4,5) == 3);
/// assert(args(std::integral_constant<int, 3>())(1,2,3,4,5) == 3);
///
namespace fit {
@@ -74,15 +76,37 @@ constexpr args_at<N...> make_args_at(seq<N...>)
return {};
}
template<int N, class... Ts>
constexpr auto get_args(Ts&&... xs) FIT_RETURNS
(
make_args_at(typename gens<N>::type())(nullptr, make_perfect_ref(fit::forward<Ts>(xs))...)
);
template<class T, T N>
struct args_f
{
template<class... Ts>
constexpr auto operator()(Ts&&... xs) FIT_RETURNS
(
get_args<N>(fit::forward<Ts>(xs)...)
);
};
}
// TODO: Make this a variable template in C++14
// Deprecate
template<int N, class... Ts>
constexpr auto args(Ts&&... xs) FIT_RETURNS
(
detail::make_args_at(typename detail::gens<N>::type())(nullptr, detail::make_perfect_ref(fit::forward<Ts>(xs))...)
detail::get_args<N>(fit::forward<Ts>(xs)...)
);
template<class IntegralConstant>
constexpr detail::args_f<int, IntegralConstant::value> args(IntegralConstant)
{
return detail::args_f<int, IntegralConstant::value>();
}
}
#endif
#endif

View File

@@ -71,7 +71,7 @@ struct placeholder_transformer
{
template<class... Ts>
constexpr auto operator()(Ts&&... xs) const FIT_RETURNS
(args<std::is_placeholder<T>::value>(fit::forward<Ts>(xs)...));
(detail::get_args<std::is_placeholder<T>::value>(fit::forward<Ts>(xs)...));
};
template<class T, typename std::enable_if<(std::is_placeholder<T>::value > 0), int>::type = 0>

View File

@@ -1,8 +1,15 @@
#include <fit/args.h>
#include <type_traits>
#include "test.h"
// FIT_TEST_CASE()
// {
// FIT_STATIC_TEST_CHECK(fit::args<3>(1,2,3,4,5) == 3);
// FIT_TEST_CHECK( fit::args<3>(1,2,3,4,5) == 3 );
// }
FIT_TEST_CASE()
{
FIT_STATIC_TEST_CHECK(fit::args<3>(1,2,3,4,5) == 3);
FIT_TEST_CHECK( fit::args<3>(1,2,3,4,5) == 3 );
FIT_STATIC_TEST_CHECK(fit::args(std::integral_constant<int, 3>())(1,2,3,4,5) == 3);
FIT_TEST_CHECK( fit::args(std::integral_constant<int, 3>())(1,2,3,4,5) == 3 );
}