forked from Alepha/Alepha
Add a template binding gadget for type lists
This is useful when the same set of types has to go into a std::variant, a std::tuple, and perhaps a few other template lists. Git-commit-built-by: Merge branch 'make-template'
This commit is contained in:
@ -33,6 +33,7 @@ add_subdirectory( Utility )
|
||||
# The local subdir tests to build
|
||||
add_subdirectory( AutoRAII.test )
|
||||
add_subdirectory( Enum.test )
|
||||
add_subdirectory( make_template.test )
|
||||
add_subdirectory( comparisons.test )
|
||||
add_subdirectory( Exception.test )
|
||||
add_subdirectory( word_wrap.test )
|
||||
|
38
make_template.h
Normal file
38
make_template.h
Normal file
@ -0,0 +1,38 @@
|
||||
static_assert( __cplusplus > 2023'00 );
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Alepha/Alepha.h>
|
||||
|
||||
#include <Alepha/type_lisp.h>
|
||||
|
||||
namespace Alepha::Hydrogen ::detail:: make_template_m
|
||||
{
|
||||
inline namespace exports {}
|
||||
|
||||
template< template< typename ... > class, TypeListType >
|
||||
struct make_template;
|
||||
|
||||
template< template< typename ... > class Template, typename ... Types >
|
||||
struct make_template< Template, TypeList< Types... > >
|
||||
{
|
||||
using type= Template< Types... >;
|
||||
};
|
||||
|
||||
namespace exports
|
||||
{
|
||||
/*!
|
||||
* Bind a type list to a class template which takes a list of arguments.
|
||||
*
|
||||
* @tparam Template The class template to instantiate.
|
||||
* @tparam List The list of types (`Alepha::TypeList< ... >`) to bind.
|
||||
*/
|
||||
template< template< typename ... > class Template, TypeListType List >
|
||||
using make_template_t= typename make_template< Template, List >::type;
|
||||
};
|
||||
}
|
||||
|
||||
namespace Alepha::Hydrogen::inline exports::inline make_template_m
|
||||
{
|
||||
using namespace detail::make_template_m::exports;
|
||||
}
|
21
make_template.test/0.cc
Normal file
21
make_template.test/0.cc
Normal file
@ -0,0 +1,21 @@
|
||||
static_assert( __cplusplus > 2023'00 );
|
||||
|
||||
#include "../make_template.h"
|
||||
|
||||
#include <tuple>
|
||||
#include <variant>
|
||||
|
||||
namespace
|
||||
{
|
||||
#define ALL_TYPES int, float, char, double, std::nullptr_t, void
|
||||
using MyTypes= Alepha::TypeList
|
||||
<
|
||||
ALL_TYPES
|
||||
>;
|
||||
|
||||
using MyTuple= Alepha::make_template_t< std::tuple, MyTypes >;
|
||||
static_assert( std::is_same_v< MyTuple, std::tuple< ALL_TYPES > > );
|
||||
|
||||
using MyVariant= Alepha::make_template_t< std::variant, MyTypes >;
|
||||
static_assert( std::is_same_v< MyVariant, std::variant< ALL_TYPES > > );
|
||||
}
|
1
make_template.test/CMakeLists.txt
Normal file
1
make_template.test/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
unit_test( 0 )
|
Reference in New Issue
Block a user