forked from Alepha/Alepha
Add an identity
which works with TableTest
This commit is contained in:
34
Algorithm/identity.h
Normal file
34
Algorithm/identity.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
static_assert( __cplusplus > 2020'99 );
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Alepha/Alepha.h>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
@ -1,2 +1,3 @@
|
|||||||
unit_test( test )
|
unit_test( test )
|
||||||
unit_test( test2 )
|
unit_test( test2 )
|
||||||
|
unit_test( test3 )
|
||||||
|
26
Testing/TableTest.test/test3.cc
Normal file
26
Testing/TableTest.test/test3.cc
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
static_assert( __cplusplus > 2020'99 );
|
||||||
|
|
||||||
|
#include <Alepha/Testing/TableTest.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include <Alepha/Testing/test.h>
|
||||||
|
#include <Alepha/Utility/evaluation_helpers.h>
|
||||||
|
|
||||||
|
#include <Alepha/Algorithm/identity.h>
|
||||||
|
|
||||||
|
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" },
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Reference in New Issue
Block a user