forked from Alepha/Alepha
Rename the template_for
header.
C++26 (I hope) is supposed to have this syntax: ``` template for( const auto &element: aggregate ) { ...; } ``` Thus, I've adjusted this gadget to have a similar name, to enable simple mechanical code changes. From Alepha, you'd use it thus: ``` template_for( aggregate ) <=[&]( const auto &element ) { ...; }; ```
This commit is contained in:
42
template_for.test/0.cc
Normal file
42
template_for.test/0.cc
Normal file
@ -0,0 +1,42 @@
|
||||
static_assert( __cplusplus > 2023'00 );
|
||||
|
||||
#include "../template_for.h"
|
||||
|
||||
#include <Alepha/Testing/test.h>
|
||||
#include <Alepha/Testing/TableTest.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <Alepha/Utility/enroll.h>
|
||||
|
||||
static auto init= Alepha::Utility::enroll <=[]
|
||||
{
|
||||
using namespace Alepha::Testing::literals;
|
||||
using namespace Alepha::Testing::exports;
|
||||
|
||||
struct Example
|
||||
{
|
||||
int x;
|
||||
std::string s;
|
||||
int y;
|
||||
};
|
||||
|
||||
"Can one `template_for` each over a simple struct and get the members into a string?"_test <=TableTest
|
||||
<
|
||||
[]( Example ex )
|
||||
{
|
||||
using Alepha::template_for;
|
||||
std::ostringstream oss;
|
||||
template_for( ex ) <=[&]( const auto &element )
|
||||
{
|
||||
oss << element << std::endl;
|
||||
};
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
>
|
||||
::Cases
|
||||
{
|
||||
{ "Simple case", { { 42, "Hello World", 1138 } }, "42\nHello World\n1138\n" },
|
||||
};
|
||||
};
|
1
template_for.test/CMakeLists.txt
Normal file
1
template_for.test/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
unit_test( 0 )
|
Reference in New Issue
Block a user