forked from Alepha/Alepha
Pairs !- tuples, so add some better Meta support
I usually use `tuple` for all product types, but some STL bits use pair, which is a distinct type. So here's some helpful meta helpers for them.
This commit is contained in:
33
Meta/is_pair.h
Normal file
33
Meta/is_pair.h
Normal file
@ -0,0 +1,33 @@
|
||||
static_assert( __cplusplus > 201700, "C++17 Required" );
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Alepha/Alepha.h>
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace Alepha::Hydrogen::Meta
|
||||
{
|
||||
inline namespace exports { inline namespace type_traits {} }
|
||||
|
||||
namespace detail::type_traits::is_pair
|
||||
{
|
||||
inline namespace exports
|
||||
{
|
||||
template< typename T >
|
||||
struct is_pair : std::false_type {};
|
||||
|
||||
template< typename ... Args >
|
||||
struct is_pair< std::pair< Args... > > : std::true_type {};
|
||||
|
||||
template< typename T >
|
||||
constexpr bool is_pair_v= is_pair< T >::value;
|
||||
}
|
||||
}
|
||||
|
||||
namespace exports::type_traits
|
||||
{
|
||||
using namespace detail::type_traits::is_pair::exports;
|
||||
}
|
||||
}
|
30
Meta/is_product_type.h
Normal file
30
Meta/is_product_type.h
Normal file
@ -0,0 +1,30 @@
|
||||
static_assert( __cplusplus > 201700, "C++17 Required" );
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Alepha/Alepha.h>
|
||||
|
||||
#include <Alepha/meta/is_pair.h>
|
||||
#include <Alepha/meta/is_tuple.h>
|
||||
|
||||
namespace Alepha::Hydrogen::Meta
|
||||
{
|
||||
inline namespace exports { inline namespace type_traits {} }
|
||||
|
||||
namespace detail::type_traits::is_product_type
|
||||
{
|
||||
inline namespace exports
|
||||
{
|
||||
template< typename T >
|
||||
constexpr bool is_product_type_v= is_tuple_v< T > or is_pair_v< T >;
|
||||
|
||||
template< typename T >
|
||||
struct is_product_type : std::bool_constant< is_product_type_v< T > > {};
|
||||
}
|
||||
}
|
||||
|
||||
namespace exports::type_traits
|
||||
{
|
||||
using namespace detail::type_traits::is_product_type::exports;
|
||||
}
|
||||
}
|
36
Meta/pair_decay.h
Normal file
36
Meta/pair_decay.h
Normal file
@ -0,0 +1,36 @@
|
||||
static_assert( __cplusplus > 201700, "C++17 Required" );
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Alepha/Alepha.h>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include <Alepha/Stud/type_traits.h>
|
||||
|
||||
namespace Alepha::Hydrogen::Meta
|
||||
{
|
||||
inline namespace exports { inline namespace type_traits {} }
|
||||
|
||||
namespace detail::type_traits::pair_decay
|
||||
{
|
||||
inline namespace exports
|
||||
{
|
||||
template< typename T > struct pair_decay;
|
||||
|
||||
template< typename First, typename Second >
|
||||
struct pair_decay< std::pair< First, Second > >
|
||||
{
|
||||
using type= std::pair< Stud::decay_t< First >, Stud::decay_t< Second > >;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
using pair_decay_t= typename pair_decay< T >::type;
|
||||
}
|
||||
}
|
||||
|
||||
namespace exports::type_traits
|
||||
{
|
||||
using namespace detail::type_traits::pair_decay::exports;
|
||||
}
|
||||
}
|
40
Meta/product_type_decay.h
Normal file
40
Meta/product_type_decay.h
Normal file
@ -0,0 +1,40 @@
|
||||
static_assert( __cplusplus > 201700, "C++17 Required" );
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Alepha/Alepha.h>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include <Alepha/Stud/type_traits.h>
|
||||
|
||||
#include <Alepha/Meta/pair_decay.h>
|
||||
#include <Alepha/Meta/tuple_decay.h>
|
||||
|
||||
namespace Alepha::Hydrogen::Meta
|
||||
{
|
||||
inline namespace exports { inline namespace type_traits {} }
|
||||
|
||||
namespace detail::type_traits::product_type_decay
|
||||
{
|
||||
inline namespace exports
|
||||
{
|
||||
template< typename T > struct product_type_decay;
|
||||
|
||||
template< typename ... Args >
|
||||
struct product_type_decay< std::pair< Args... > > : pair_decay< std::pair< Args... > > {};
|
||||
|
||||
template< typename ... Args >
|
||||
struct product_type_decay< std::tuple< Args... > > : tuple_decay< std::tuple< Args... > > {};
|
||||
|
||||
template< typename T >
|
||||
using product_type_decay_t= typename product_type_decay< T >::type;
|
||||
}
|
||||
}
|
||||
|
||||
namespace exports::type_traits
|
||||
{
|
||||
using namespace detail::type_traits::product_type_decay::exports;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user