From 500ad866eb62ad2780c527ca6d39cc01e727cf46 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Wed, 12 Jun 2024 16:58:21 -0400 Subject: [PATCH] Add an `identity` which works with `TableTest` --- Algorithm/identity.h | 34 +++++++++++++++++++++++++++ Testing/TableTest.test/CMakeLists.txt | 1 + Testing/TableTest.test/test3.cc | 26 ++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 Algorithm/identity.h create mode 100644 Testing/TableTest.test/test3.cc diff --git a/Algorithm/identity.h b/Algorithm/identity.h new file mode 100644 index 0000000..e325b23 --- /dev/null +++ b/Algorithm/identity.h @@ -0,0 +1,34 @@ +static_assert( __cplusplus > 2020'99 ); + +#pragma once + +#include + + +namespace Alepha::Hydrogen::Algorithm ::detail:: identity_m +{ + inline namespace exports + { + /*! + * Specializable identity function. + * + * Sometimes you need an unambiguous overload for `std::identity`. Because the + * standard's version is a function object with an unbounded member template + * `operator ()`, this means that deduction contexts cannod deduce which + * type is the range and domain for the identity object passed. Normally + * this doesn't matter, but some `Alepha` constructs need to inspect functions. + * to that end, one can use `Alepha::Algorithm::identity< T >` for this purpose + * + * @note This functions effectively the same as the original SGI STL's `identity` + * extension, but with C++11's rvalue semantics. Although we also use a template + * variable to avoid the need to instantiate. + */ + template< typename T > + constexpr auto identity= []( T val ) { return val; }; + } +} + +namespace Alepha::Hydrogen::Algorithm::inline exports::inline identity_m +{ + using namespace detail::identity_m::exports; +} diff --git a/Testing/TableTest.test/CMakeLists.txt b/Testing/TableTest.test/CMakeLists.txt index f75bd65..d8411b3 100644 --- a/Testing/TableTest.test/CMakeLists.txt +++ b/Testing/TableTest.test/CMakeLists.txt @@ -1,2 +1,3 @@ unit_test( test ) unit_test( test2 ) +unit_test( test3 ) diff --git a/Testing/TableTest.test/test3.cc b/Testing/TableTest.test/test3.cc new file mode 100644 index 0000000..3122276 --- /dev/null +++ b/Testing/TableTest.test/test3.cc @@ -0,0 +1,26 @@ +static_assert( __cplusplus > 2020'99 ); + +#include + + +#include +#include + +#include + +namespace +{ + using namespace Alepha::Testing::exports; + using namespace Alepha::Utility::exports::evaluation_helpers_m; + using namespace Alepha::Algorithm::exports; + + auto init= enroll <=[] + { + auto x= identity< int >( 42 ); + + "Simple Identity Test"_test <=TableTest< identity< std::string > >::Cases + { + { "Tony 1", { "tony" }, "tony" }, + }; + }; +}