File size: 1,645 Bytes
8ae5fc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef METAL_LAMBDA_ARG_HPP
#define METAL_LAMBDA_ARG_HPP

#include "../config.hpp"

#include <cstddef>

namespace metal {
/// \cond
namespace detail {
    template <std::size_t n>
    struct _arg;
}
/// \endcond

/// \ingroup lambda
///
/// ### Description
/// A parametric \lambda that selects the n-th argument it is invoked with.
///
/// ### Usage
/// For any nonzero positive integral value `n`
/// \code
///     using result = metal::arg<n>;
/// \endcode
///
/// \returns: \lambda
/// \semantics:
///     Equivalent to
///     \code
///         using result = metal::lambda<expr>;
///     \endcode
///     where `expr` is an \expression such that
///     `expr<val_0, ..., val_n-1, ..., val_m-1>` yields `val_n-1`.
///
/// ### Example
/// \snippet lambda.cpp arg
///
/// ### See Also
/// \see lambda, invoke, bind, always
template <std::size_t n>
using arg = typename detail::_arg<n>::type;
}

#include "../lambda/lambda.hpp"
#include "../list/at.hpp"
#include "../list/list.hpp"
#include "../number/number.hpp"

namespace metal {
/// \cond
namespace detail {
    template <std::size_t n>
    struct _arg {
        template <class... vals>
        using impl = at<list<vals...>, number<n - 1>>;

        using type = lambda<impl>;
    };

    template <>
    struct _arg<0U> {
    };
}
/// \endcond

/// \ingroup lambda
///
/// ### Description
/// Predefined placeholder.
/// \{
using _1 = metal::arg<1U>;
using _2 = metal::arg<2U>;
using _3 = metal::arg<3U>;
using _4 = metal::arg<4U>;
using _5 = metal::arg<5U>;
using _6 = metal::arg<6U>;
using _7 = metal::arg<7U>;
using _8 = metal::arg<8U>;
using _9 = metal::arg<9U>;
/// \}
}

#endif