1
0
forked from Alepha/Alepha

Added Sequence and optional detection.

This is part of the larger `Meta` library.  Need to implement
tuple-for-each and more.
This commit is contained in:
2021-07-01 22:28:24 -04:00
parent 7ceef7e1b1
commit ec07dcc83a
9 changed files with 355 additions and 0 deletions

3
Meta/Makefile Normal file
View File

@ -0,0 +1,3 @@
CXXFLAGS+= -std=c++17 -I ../
all: test

34
Meta/is_deque.h Normal file
View File

@ -0,0 +1,34 @@
static_assert( __cplusplus > 201700, "C++17 Required" );
#pragma once
#include <Alepha/Alepha.h>
#include <type_traits>
#include <deque>
namespace Alepha::Hydrogen::Meta
{
inline namespace exports { inline namespace type_traits {} }
namespace detail::type_traits::is_deque
{
inline namespace exports
{
template< typename T >
struct is_deque : std::false_type {};
template< typename T, typename ... Args >
struct is_deque< std::deque< T, Args... > > : std::true_type {};
template< typename T >
constexpr bool is_deque_v= is_deque< T >::value;
}
}
namespace exports::type_traits
{
using namespace detail::type_traits::is_deque::exports;
}
}

34
Meta/is_forward_list.h Normal file
View File

@ -0,0 +1,34 @@
static_assert( __cplusplus > 201700, "C++17 Required" );
#pragma once
#include <Alepha/Alepha.h>
#include <type_traits>
#include <forward_list>
namespace Alepha::Hydrogen::Meta
{
inline namespace exports { inline namespace type_traits {} }
namespace detail::type_traits::is_forward_list
{
inline namespace exports
{
template< typename T >
struct is_forward_list : std::false_type {};
template< typename T, typename ... Args >
struct is_forward_list< std::forward_list< T, Args... > > : std::true_type {};
template< typename T >
constexpr bool is_forward_list_v= is_forward_list< T >::value;
}
}
namespace exports::type_traits
{
using namespace detail::type_traits::is_forward_list::exports;
}
}

34
Meta/is_list.h Normal file
View File

@ -0,0 +1,34 @@
static_assert( __cplusplus > 201700, "C++17 Required" );
#pragma once
#include <Alepha/Alepha.h>
#include <type_traits>
#include <list>
namespace Alepha::Hydrogen::Meta
{
inline namespace exports { inline namespace type_traits {} }
namespace detail::type_traits::is_list
{
inline namespace exports
{
template< typename T >
struct is_list : std::false_type {};
template< typename T, typename ... Args >
struct is_list< std::list< T, Args... > > : std::true_type {};
template< typename T >
constexpr bool is_list_v= is_list< T >::value;
}
}
namespace exports::type_traits
{
using namespace detail::type_traits::is_list::exports;
}
}

34
Meta/is_optional.h Normal file
View File

@ -0,0 +1,34 @@
static_assert( __cplusplus > 201700, "C++17 Required" );
#pragma once
#include <Alepha/Alepha.hpp>
#include <type_traits>
#include <optional>
namespace Alepha::Hydrogen::Meta
{
inline namespace exports { inline namespace type_traits {} }
namespace detail::type_traits::is_optional
{
inline namespace exports
{
template< typename T >
struct is_optional : std::false_type {};
template< typename T, typename ... Args >
struct is_optional< std::optional< T, Args... > > : std::true_type {};
template< typename T >
constexpr bool is_optional_v= is_optional< T >::value;
}
}
namespace exports::type_traits
{
using namespace detail::type_traits::is_optional::exports;
}
}

36
Meta/is_sequence.h Normal file
View File

@ -0,0 +1,36 @@
static_assert( __cplusplus > 201700, "C++17 Required" );
#pragma once
#include <Alepha/Alepha.h>
#include <type_traits>
#include <Alepha/Meta/is_list.h>
#include <Alepha/Meta/is_forward_list.h>
#include <Alepha/Meta/is_vector.h>
#include <Alepha/Meta/is_deque.h>
#include <Alepha/Meta/is_string.h>
namespace Alepha::Hydrogen::Meta
{
inline namespace exports { inline namespace type_traits {} }
namespace detail::type_traits::is_sequence
{
inline namespace exports
{
template< typename T >
constexpr bool is_sequence_v= is_list_v< T > or is_forward_list_v< T > or is_deque_v< T > or is_string_v< T > or is_vector_v< T >;
template< typename T >
struct is_sequence : std::bool_constant< is_sequence_v< T > > {};
}
}
namespace exports::type_traits
{
using namespace detail::type_traits::is_sequence::exports;
}
}

34
Meta/is_string.h Normal file
View File

@ -0,0 +1,34 @@
static_assert( __cplusplus > 201700, "C++17 Required" );
#pragma once
#include <Alepha/Alepha.h>
#include <type_traits>
#include <string>
namespace Alepha::Hydrogen::Meta
{
inline namespace exports { inline namespace type_traits {} }
namespace detail::type_traits::is_string
{
inline namespace exports
{
template< typename T >
struct is_string : std::false_type {};
template< typename T, typename ... Args >
struct is_string< std::basic_string< T, Args... > > : std::true_type {};
template< typename T >
constexpr bool is_string_v= is_string< T >::value;
}
}
namespace exports::type_traits
{
using namespace detail::type_traits::is_string::exports;
}
}

34
Meta/is_vector.h Normal file
View File

@ -0,0 +1,34 @@
static_assert( __cplusplus > 201700, "C++17 Required" );
#pragma once
#include <Alepha/Alepha.h>
#include <type_traits>
#include <vector>
namespace Alepha::Hydrogen::Meta
{
inline namespace exports { inline namespace type_traits {} }
namespace detail::type_traits::is_vector
{
inline namespace exports
{
template< typename T >
struct is_vector : std::false_type {};
template< typename T, typename ... Args >
struct is_vector< std::vector< T, Args... > > : std::true_type {};
template< typename T >
constexpr bool is_vector_v= is_vector< T >::value;
}
}
namespace exports::type_traits
{
using namespace detail::type_traits::is_vector::exports;
}
}

112
Meta/test.cc Normal file
View File

@ -0,0 +1,112 @@
static_assert( __cplusplus > 201700, "C++17 Required" );
#include <Alepha/Meta/is_sequence.h>
#include <Alepha/Testing/test.h>
#include <Alepha/Utility/evaluation.h>
#include <cassert>
int
main( const int argcnt, const char *const *const argvec )
{
return Alepha::Testing::runAllTests( argcnt, argvec );
}
namespace
{
using namespace Alepha::Utility::evaluation;
using namespace Alepha::Testing::literals;
// These tests never actually fail at runtime, but they provide a simple way to have them
// as unit tests. There's no call to actually assert them at runtime. If this test built,
// it passes.
auto tests= enroll <=[]
{
"meta.specific"_test <=[]
{
static_assert( Alepha::Meta::is_vector_v< std::vector< int > > );
static_assert( Alepha::Meta::is_list_v< std::list< int > > );
static_assert( Alepha::Meta::is_forward_list_v< std::forward_list< int > > );
static_assert( Alepha::Meta::is_deque_v< std::deque< int > > );
static_assert( Alepha::Meta::is_vector_v< std::vector< std::string > > );
static_assert( Alepha::Meta::is_list_v< std::list< std::string > > );
static_assert( Alepha::Meta::is_forward_list_v< std::forward_list< std::string > > );
static_assert( Alepha::Meta::is_deque_v< std::deque< std::string > > );
static_assert( Alepha::Meta::is_string_v< std::string > );
static_assert( Alepha::Meta::is_string_v< std::wstring > );
};
"meta.sequence"_test <=[]
{
static_assert( Alepha::Meta::is_sequence_v< std::vector< int > > );
static_assert( Alepha::Meta::is_sequence_v< std::list< int > > );
static_assert( Alepha::Meta::is_sequence_v< std::forward_list< int > > );
static_assert( Alepha::Meta::is_sequence_v< std::deque< int > > );
static_assert( Alepha::Meta::is_sequence_v< std::vector< std::string > > );
static_assert( Alepha::Meta::is_sequence_v< std::list< std::string > > );
static_assert( Alepha::Meta::is_sequence_v< std::forward_list< std::string > > );
static_assert( Alepha::Meta::is_sequence_v< std::deque< std::string > > );
static_assert( Alepha::Meta::is_sequence_v< std::string > );
static_assert( Alepha::Meta::is_sequence_v< std::wstring > );
};
"meta.confusion"_test <=[]
{
static_assert( not Alepha::Meta::is_sequence_v< int > );
static_assert( not Alepha::Meta::is_sequence_v< std::nullptr_t > );
static_assert( not Alepha::Meta::is_vector_v< std::list< int > > );
static_assert( not Alepha::Meta::is_vector_v< std::forward_list< int > > );
static_assert( not Alepha::Meta::is_vector_v< std::deque< int > > );
static_assert( not Alepha::Meta::is_vector_v< std::list< std::string > > );
static_assert( not Alepha::Meta::is_vector_v< std::forward_list< std::string > > );
static_assert( not Alepha::Meta::is_vector_v< std::deque< std::string > > );
static_assert( not Alepha::Meta::is_vector_v< std::string > );
static_assert( not Alepha::Meta::is_vector_v< std::wstring > );
static_assert( not Alepha::Meta::is_list_v< std::vector< int > > );
static_assert( not Alepha::Meta::is_list_v< std::forward_list< int > > );
static_assert( not Alepha::Meta::is_list_v< std::deque< int > > );
static_assert( not Alepha::Meta::is_list_v< std::vector< std::string > > );
static_assert( not Alepha::Meta::is_list_v< std::forward_list< std::string > > );
static_assert( not Alepha::Meta::is_list_v< std::deque< std::string > > );
static_assert( not Alepha::Meta::is_list_v< std::string > );
static_assert( not Alepha::Meta::is_list_v< std::wstring > );
static_assert( not Alepha::Meta::is_forward_list_v< std::vector< int > > );
static_assert( not Alepha::Meta::is_forward_list_v< std::list< int > > );
static_assert( not Alepha::Meta::is_forward_list_v< std::deque< int > > );
static_assert( not Alepha::Meta::is_forward_list_v< std::vector< std::string > > );
static_assert( not Alepha::Meta::is_forward_list_v< std::list< std::string > > );
static_assert( not Alepha::Meta::is_forward_list_v< std::deque< std::string > > );
static_assert( not Alepha::Meta::is_forward_list_v< std::string > );
static_assert( not Alepha::Meta::is_forward_list_v< std::wstring > );
static_assert( not Alepha::Meta::is_deque_v< std::vector< int > > );
static_assert( not Alepha::Meta::is_deque_v< std::list< int > > );
static_assert( not Alepha::Meta::is_deque_v< std::forward_list< int > > );
static_assert( not Alepha::Meta::is_deque_v< std::vector< std::string > > );
static_assert( not Alepha::Meta::is_deque_v< std::list< std::string > > );
static_assert( not Alepha::Meta::is_deque_v< std::forward_list< std::string > > );
static_assert( not Alepha::Meta::is_deque_v< std::string > );
static_assert( not Alepha::Meta::is_deque_v< std::wstring > );
static_assert( not Alepha::Meta::is_string_v< std::vector< int > > );
static_assert( not Alepha::Meta::is_string_v< std::list< int > > );
static_assert( not Alepha::Meta::is_string_v< std::forward_list< int > > );
static_assert( not Alepha::Meta::is_string_v< std::deque< int > > );
static_assert( not Alepha::Meta::is_string_v< std::vector< std::string > > );
static_assert( not Alepha::Meta::is_string_v< std::list< std::string > > );
static_assert( not Alepha::Meta::is_string_v< std::forward_list< std::string > > );
static_assert( not Alepha::Meta::is_string_v< std::deque< std::string > > );
};
};
}