types/traits: add is_tuple_like trait

This commit is contained in:
Danny Robson 2018-11-01 16:30:56 +11:00
parent 44eeeaa134
commit 7d55221331

View File

@ -3,13 +3,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2012-2017 Danny Robson <danny@nerdcruft.net>
* Copyright 2012-2018 Danny Robson <danny@nerdcruft.net>
*/
#ifndef CRUFT_UTIL_TYPES_TRAITS_HPP
#define CRUFT_UTIL_TYPES_TRAITS_HPP
#pragma once
#include <memory>
#include <tuple>
#include <type_traits>
@ -449,6 +449,25 @@ namespace cruft {
template <typename ValueA, typename ValueB>
constexpr auto is_same_basic_type_v = is_same_basic_type<ValueA,ValueB>::value;
}
#endif
/// Tests if an object is 'tuple-like'; ie, it responds to std::get,
/// std::tuple_size, and std::tuple_element.
template <typename, typename = void>
struct is_tuple_like : public std::false_type {};
template <typename T>
struct is_tuple_like<
T,
std::void_t<
decltype (std::get<0> (std::declval<T> ())),
decltype (std::tuple_size_v<T>),
std::tuple_element_t<0,T>
>
> : public std::true_type {};
template <typename T>
constexpr auto is_tuple_like_v = is_tuple_like<T>::value;
}