11#include <catch2/catch.hpp>
31 operator int()
const {
return value; }
34constexpr auto Component = Callable::UniqueMaker<MyComponent, int>();
40inline bool operator== (
int n,
const unique_ptr<MyComponent> &p)
47template<
bool members = true,
typename Container1,
typename Container2>
51 if constexpr(members) {
53 (equal(c1.begin(), c1.end(), c2.begin(), c2.end()))
55 (equal(c1.cbegin(), c1.cend(), c2.cbegin(), c2.cend()))
57 (equal(c1.rbegin(), c1.rend(), c2.rbegin(), c2.rend()))
59 (equal(c1.crbegin(), c1.crend(), c2.crbegin(), c2.crend()));
64 (equal(cbegin(c1), cend(c1), cbegin(c2), cend(c2)))
66 (equal(rbegin(c1), rend(c1), rbegin(c2), rend(c2)))
68 (equal(crbegin(c1), crend(c1), crbegin(c2), crend(c2)))
74template<
typename Container,
auto Maker =
nullptr,
typename... Args>
77 auto Make = [](
int value){
78 if constexpr (!bool(
Maker))
84 using ComponentType =
decltype(Make(0));
87 Container container{ args... };
88 REQUIRE(0 == container);
89 REQUIRE(container.empty());
98 vector<ComponentType> components;
102 for (
size_t ii = 1; ii <= N; ++ii)
103 components.push_back(Make(ii));
110 move(components.begin(), components.end(), back_inserter(container));
111 REQUIRE(!container.empty());
119 container.push_back(Make(N + 1));
125 DoTest<MyCompositeBase>(0);
127 DoTest<MyCompositeBase2>(0, Ignore{});
135inline bool operator== (
int n,
const std::unique_ptr<MyComponentEx> &p)
139static auto Maker (
int value){
return std::make_unique<MyComponentEx>(value); };
147 struct ItemBuilderType {
148 auto operator () (std::unique_ptr<MyComponent> ptr)
const {
149 return std::make_unique<MyComponentEx>(ptr->value); };
150 auto operator () (
int value)
const {
151 return std::make_unique<MyComponentEx>(-value); };
159 using Builder::Builder;
165 using namespace placeholders;
166 std::array
values{ 0, 1, 2, 3, 4 };
168 DoTest<MyBuilder, Maker>(0);
172 MyBuilder builder{ 0, 0, 1, 2, 3, 4 };
181 std::array values2{ 1, 2, 3, 4, 5 };
182 MyBuilder builder3{ 0,
begin(values2),
end(values2),
183 bind( minus{}, _1, -1 ) };
191 DoTest<Container>(0, X{});
193 DoTest<Container2>(0, Ignore{}, X{});
199 DoTest<Container>(0);
201 DoTest<Container2>(0, Ignore{});
Functions and classes that generate callable objects.
TEST_CASE("Composite::Base")
void DoTest(Args ...args)
Base< MyComponent, unique_ptr< MyComponent >, int > MyCompositeBase
bool compareSequences(const Container1 &c1, const Container2 &c2)
bool operator==(int n, const std::unique_ptr< MyComponentEx > &p)
static auto Maker(int value)
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept
Extend Base with extra fields, in a second, protected base class.
static constexpr auto ItemBuilder
static constexpr auto enables_item_type_v
virtual ~MyComponent()=default
MyComponent(int value, Ignore ignored)