From 9f50dd3308edca9164e37e4faec00ef767e2cd76 Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 24 Apr 2015 21:19:52 -0500 Subject: [PATCH] Change args to take an integral constant, and make it return a function. Deprecate the old usage --- fit/args.h | 40 ++++++++++++++++++++++++++++++++-------- fit/lazy.h | 2 +- test/args.cpp | 11 +++++++++-- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/fit/args.h b/fit/args.h index 7e96853..7fb187a 100644 --- a/fit/args.h +++ b/fit/args.h @@ -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 -/// constexpr auto args(Ts&&... xs); +/// template +/// constexpr auto args(IntegralConstant); +/// /// /// Example /// ------- /// -/// assert(args<3>(1,2,3,4,5) == 3); +/// assert(args(std::integral_constant())(1,2,3,4,5) == 3); /// namespace fit { @@ -74,15 +76,37 @@ constexpr args_at make_args_at(seq) return {}; } +template +constexpr auto get_args(Ts&&... xs) FIT_RETURNS +( + make_args_at(typename gens::type())(nullptr, make_perfect_ref(fit::forward(xs))...) +); + +template +struct args_f +{ + template + constexpr auto operator()(Ts&&... xs) FIT_RETURNS + ( + get_args(fit::forward(xs)...) + ); +}; + } -// TODO: Make this a variable template in C++14 +// Deprecate template constexpr auto args(Ts&&... xs) FIT_RETURNS ( - detail::make_args_at(typename detail::gens::type())(nullptr, detail::make_perfect_ref(fit::forward(xs))...) + detail::get_args(fit::forward(xs)...) ); +template +constexpr detail::args_f args(IntegralConstant) +{ + return detail::args_f(); +} + } -#endif \ No newline at end of file +#endif diff --git a/fit/lazy.h b/fit/lazy.h index 9edfd73..84953f5 100644 --- a/fit/lazy.h +++ b/fit/lazy.h @@ -71,7 +71,7 @@ struct placeholder_transformer { template constexpr auto operator()(Ts&&... xs) const FIT_RETURNS - (args::value>(fit::forward(xs)...)); + (detail::get_args::value>(fit::forward(xs)...)); }; template::value > 0), int>::type = 0> diff --git a/test/args.cpp b/test/args.cpp index b0aaee5..ff57af7 100644 --- a/test/args.cpp +++ b/test/args.cpp @@ -1,8 +1,15 @@ #include +#include #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())(1,2,3,4,5) == 3); + FIT_TEST_CHECK( fit::args(std::integral_constant())(1,2,3,4,5) == 3 ); } \ No newline at end of file