/*============================================================================= Copyright (c) 2014 Paul Fultz II args.h 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 FIT_GUARD_FUNCTION_ARGS_H #define FIT_GUARD_FUNCTION_ARGS_H #include #include #include /// args /// ==== /// /// 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. /// /// Synopsis /// -------- /// /// template /// constexpr auto args(Ts&&... xs); /// /// Example /// ------- /// /// assert(args<3>(1,2,3,4,5) == 3); /// namespace fit { namespace detail { template struct perfect_ref { typedef T&& type; T&& value; constexpr perfect_ref(T&& x) : value(fit::forward(x)) {} }; template constexpr perfect_ref make_perfect_ref(T&& x) { return { fit::forward(x) }; } template struct ignore { template constexpr ignore(T&&...) {} }; template struct args_at { template constexpr auto operator()(ignore..., T x, Ts...) const FIT_RETURNS(fit::forward(x.value)); }; template constexpr args_at make_args_at(seq) { return {}; } } // TODO: Make this a variable template in C++14 template constexpr auto args(Ts&&... xs) FIT_RETURNS ( detail::make_args_at(typename detail::gens::type())(nullptr, detail::make_perfect_ref(fit::forward(xs))...) ); } #endif