]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/example/misc/nth.cpp
1 // Copyright Louis Dionne 2013-2016
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
5 #include <boost/hana/functional/arg.hpp>
9 namespace hana
= boost::hana
;
12 constexpr int to_int(char c
)
13 { return static_cast<int>(c
) - 48; }
15 template <std::size_t N
>
16 constexpr long long parse(const char (&arr
)[N
]) {
17 long long number
= 0, base
= 1;
18 for (std::size_t i
= 0; i
< N
; ++i
) {
19 number
+= to_int(arr
[N
- 1 - i
]) * base
;
27 static constexpr unsigned long n
= parse
<sizeof...(c
)>({c
...});
29 template <typename
...T
>
30 constexpr auto operator()(T
&& ...args
) const
31 { return hana::arg
<n
>(std::forward
<T
>(args
)...); }
34 template <char ...c
> constexpr pick
<c
...> operator"" _st() { return {}; }
35 template <char ...c
> constexpr pick
<c
...> operator"" _nd() { return {}; }
36 template <char ...c
> constexpr pick
<c
...> operator"" _rd() { return {}; }
37 template <char ...c
> constexpr pick
<c
...> operator"" _th() { return {}; }
40 static_assert(1_st(1, '2', 3.3, 444) == 1, "");
41 static_assert(2_nd(1, '2', 3.3, 444) == '2', "");
42 static_assert(3_rd(1, '2', 3.3, 444) == 3.3, "");
43 static_assert(4_th(1, '2', 3.3, 444) == 444, "");