diff --git a/CMakeLists.txt b/CMakeLists.txt index 83127ec..88e74ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ add_subdirectory( Utility ) # The local subdir tests to build add_subdirectory( AutoRAII.test ) +add_subdirectory( Enum.test ) add_subdirectory( comparisons.test ) add_subdirectory( Exception.test ) add_subdirectory( word_wrap.test ) diff --git a/ConstexprString.h b/ConstexprString.h index ab12897..d6d2d1a 100644 --- a/ConstexprString.h +++ b/ConstexprString.h @@ -24,6 +24,11 @@ namespace Alepha::Hydrogen ::detail:: ConstexprString_m // benefit of the NTTP variadic list way, for compiler memory usage, is that // the a type using the string as a parameter has a symbol size which // is proportional to the number of chars in the string. + // + // However, NTTP parameters are pretty large in terms of memory footprint + // of the compiler and they do tax the compiler's CPU usage a lot more. + // As such, compile time strings of a "reasonable" size are probably the + // best we can hope for. const std::size_t maxSize= 128; } @@ -47,7 +52,7 @@ namespace Alepha::Hydrogen ::detail:: ConstexprString_m const char * what() const noexcept final { - return "Failure to allocate enough space for a a compile-time string."; + return "Failure to allocate enough space for a a compile-time string."; } }; diff --git a/Enum.h b/Enum.h index ab3ce67..ac3d31a 100644 --- a/Enum.h +++ b/Enum.h @@ -19,7 +19,7 @@ static_assert( __cplusplus > 2020'99 ); #include "ConstexprString.h" #include "meta.h" -namespace Alepha::Hydrogen ::detail:: Enum_m +namespace Alepha::Hydrogen ::detail:: Enum_m { inline namespace exports {} @@ -52,13 +52,6 @@ namespace Alepha::Hydrogen ::detail:: Enum_m } } - template< auto value, auto ... > - constexpr decltype( auto ) - get_first_enum_string() - { - return value; - } - template< ConstexprString s > struct EnumValueString { @@ -121,8 +114,6 @@ namespace Alepha::Hydrogen ::detail:: Enum_m template< EnumValueString ... values > class exports::Enum - //: private comparable - // Alepha::Hydrogen comparables work differently than the one-off Cavorite form. { private: enum class StrictInteger : unsigned {}; @@ -197,8 +188,6 @@ namespace Alepha::Hydrogen ::detail:: Enum_m constexpr unsigned get_index() const { return static_cast< unsigned >( value ); } - constexpr auto equality_lens() const { return value; } - bool operator == ( const Enum & ) const= default; friend std::ostream & diff --git a/Enum.test/0.cc b/Enum.test/0.cc new file mode 100644 index 0000000..a327809 --- /dev/null +++ b/Enum.test/0.cc @@ -0,0 +1,61 @@ +static_assert( __cplusplus > 2020'99 ); + +#include "../Enum.h" + +#include +#include + +#include + +#include + +static auto init= Alepha::Utility::enroll <=[] +{ + using namespace Alepha::literals::enum_literals; + using namespace Alepha::Testing::literals; + + using namespace Alepha::Testing::exports; + + using MyEnum= Alepha::Enum< "Adam"_value, "Baker"_value, "Charlie"_value, "David"_value >; + + "Enum round trip printing test"_test <= TableTest + < + []( const std::string s ) -> std::string + { + MyEnum e; + std::istringstream iss{ s }; + + ( iss >> e ); + return Alepha::IOStreams::String{} << e; + } + > + ::Cases + { + { "Adam", { "Adam" }, "Adam" }, + { "Charlie", { "Charlie" }, "Charlie" }, + { "Wrong", { "Wrong" }, std::type_identity< Alepha::EnumTextMismatchError >{} }, + }; + + "Enum failure parse"_test <= TableTest + < + []( const std::string s ) + { + try + { + MyEnum e; + std::istringstream iss{ s }; + + ( iss >> e ); + throw "Fail"; + } + catch( const Alepha::EnumTextMismatchError &ex ) + { + return ex.expectedValues(); + } + } + > + ::Cases + { + { "Wrong", { "Wrong" }, { "Adam", "Baker", "Charlie", "David" } }, + }; +}; diff --git a/Enum.test/CMakeLists.txt b/Enum.test/CMakeLists.txt new file mode 100644 index 0000000..b099603 --- /dev/null +++ b/Enum.test/CMakeLists.txt @@ -0,0 +1 @@ +unit_test( 0 )