forked from Alepha/Alepha
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 )
{
...;
};
```
43 lines
807 B
C++
43 lines
807 B
C++
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" },
|
|
};
|
|
};
|