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
|
#include <array>
#include <tuple>
#include <string>
template<typename T, std::size_t N>
class Tuple
{
};
// If I'm reading the standard correctly, below should produce undefined behavior
// I've tried to read the source of <tuple> to determine what I need to do, but...it's getting dangerous.
template<typename T, std::size_t N>
struct std::tuple_size<Tuple<T, N>> : std::integral_constant<std::size_t, N> {};
template<std::size_t I, typename T, std::size_t N>
struct std::tuple_element<I, Tuple<T, N>> { typedef T type;};
namespace std
{
template<std::size_t I, typename T, std::size_t N>
constexpr const T& get(const Tuple<T, N>& tuple) noexcept
{
return tuple[I];
}
template<std::size_t I, typename T, std::size_t N>
constexpr const T&& get(const Tuple<T, N>&& tuple) noexcept
{
return tuple[I];
}
template<std::size_t I, typename T, std::size_t N>
constexpr T& get(Tuple<T, N>& tuple) noexcept
{
return tuple[I];
}
template<typename _Tp, std::size_t _Nm>
struct __is_tuple_like<Tuple<_Tp, _Nm>> : true_type
{typedef true_type type; };
}
int main()
{
std::tuple<int, int, int> t0, t1, t2;
std::tuple_cat(t0, t1, t2);
// How to make my type compatible with std::tuple_cat?
Tuple<int, 3> t3, t4, t5;
std::tuple_cat(t3, t4, t5);
}
|