| 1 |
// Range v3 library |
| 2 |
// |
| 3 |
// Copyright Eric Niebler 2013-present |
| 4 |
// |
| 5 |
// Use, modification and distribution is subject to the |
| 6 |
// Boost Software License, Version 1.0. (See accompanying |
| 7 |
// file LICENSE_1_0.txt or copy at |
| 8 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 9 |
// |
| 10 |
// Project home: https://github.com/ericniebler/range-v3 |
| 11 |
// |
| 12 |
#ifndef RANGES_V3_DETAIL_WITH_BRACED_INIT_ARGS_HPP |
| 13 |
#define RANGES_V3_DETAIL_WITH_BRACED_INIT_ARGS_HPP |
| 14 |
|
| 15 |
#include <initializer_list> |
| 16 |
|
| 17 |
#include <range/v3/functional/invoke.hpp> |
| 18 |
|
| 19 |
#include <range/v3/detail/prologue.hpp> |
| 20 |
|
| 21 |
namespace ranges |
| 22 |
{ |
| 23 |
/// \cond |
| 24 |
namespace detail |
| 25 |
{ |
| 26 |
// Accepts initializer_lists as either the first or second parameter, or both, |
| 27 |
// and forwards on to an implementation. |
| 28 |
template<typename ImplFn> |
| 29 |
struct with_braced_init_args : ImplFn |
| 30 |
{ |
| 31 |
private: |
| 32 |
constexpr ImplFn const & base() const |
| 33 |
{ |
| 34 |
return *this; |
| 35 |
} |
| 36 |
|
| 37 |
public: |
| 38 |
using ImplFn::operator(); |
| 39 |
|
| 40 |
template<typename V0, typename... Args> |
| 41 |
constexpr invoke_result_t<ImplFn const &, std::initializer_list<V0>, Args...> |
| 42 |
operator()(std::initializer_list<V0> && rng0, Args &&... args) const |
| 43 |
{ |
| 44 |
return base()(static_cast<std::initializer_list<V0> &&>(rng0), |
| 45 |
static_cast<Args &&>(args)...); |
| 46 |
} |
| 47 |
/// \overload |
| 48 |
template<typename Rng0, typename V1, typename... Args> |
| 49 |
constexpr invoke_result_t<ImplFn const &, |
| 50 |
Rng0, |
| 51 |
std::initializer_list<V1>, |
| 52 |
Args...> // |
| 53 |
operator()(Rng0 && rng0, std::initializer_list<V1> && rng1, Args &&... args) |
| 54 |
const |
| 55 |
{ |
| 56 |
return base()( // |
| 57 |
static_cast<Rng0 &&>(rng0), |
| 58 |
static_cast<std::initializer_list<V1> &&>(rng1), |
| 59 |
static_cast<Args &&>(args)...); |
| 60 |
} |
| 61 |
/// \overload |
| 62 |
template<typename V0, typename V1, typename... Args> |
| 63 |
constexpr invoke_result_t<ImplFn const &, |
| 64 |
std::initializer_list<V0>, |
| 65 |
std::initializer_list<V1>, |
| 66 |
Args...> |
| 67 |
operator()(std::initializer_list<V0> && rng0, |
| 68 |
std::initializer_list<V1> && rng1, |
| 69 |
Args &&... args) const |
| 70 |
{ |
| 71 |
return base()( // |
| 72 |
static_cast<std::initializer_list<V0> &&>(rng0), |
| 73 |
static_cast<std::initializer_list<V1> &&>(rng1), |
| 74 |
static_cast<Args &&>(args)...); |
| 75 |
} |
| 76 |
}; |
| 77 |
} // namespace detail |
| 78 |
/// \endcond |
| 79 |
} // namespace ranges |
| 80 |
|
| 81 |
#include <range/v3/detail/epilogue.hpp> |
| 82 |
|
| 83 |
#endif |