You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB
C++

// -*- c++ -*-
#pragma once
#include <type_traits>
#include <xutility>
#include <new>
// replace "tuple()" with "constexpr tuple()", but leave other tuple ctors...
// http://stackoverflow.com/a/21371401
#define __GET_MACRO(_0, _1, _2, _3, _4, NAME, ...) NAME
#define tuple(...) \
__GET_MACRO(_0, ##__VA_ARGS__, tuple, tuple, tuple, tuple, constexpr tuple) \
(__VA_ARGS__)
// remove explicit from direct ctor (this is not c++17 compatible, but the
// libc++ builds should catch this problem)
#pragma push_macro("explicit")
#define explicit _Pragma("pop_macro(\"explicit\")")
#pragma push_macro("explicit")
#define explicit explicit _Pragma("pop_macro(\"explicit\")")
#pragma push_macro("explicit")
#define explicit explicit _Pragma("pop_macro(\"explicit\")")
#include_next <tuple>
#undef tuple
#undef __GET_MACRO
namespace std
{
template <typename T>
inline constexpr size_t tuple_size_v = tuple_size<T>::value;
template <std::size_t I, typename T>
using tuple_element_t = typename tuple_element<I, T>::type;
namespace detail
{
template <typename T, typename Tuple, size_t... I>
constexpr T make_from_tuple_impl(Tuple&& t, index_sequence<I...>)
{ return T(get<I>(std::forward<Tuple>(t))...); }
}
template <typename T, typename Tuple>
constexpr T make_from_tuple(Tuple&& t)
{
return detail::make_from_tuple_impl<T>(
forward<Tuple>(t),
make_index_sequence<tuple_size_v<decay_t<Tuple>>>{});
}
}