#include <catch2/catch_test_macros.hpp>
#include <string>
namespace simple {
std::string result;
for (auto const& item : items) {
result += item.fn1();
}
return result;
}
struct model1 {
std::string s;
[[nodiscard]] std::string fn1() const { return "model1"; }
};
struct model2 {
int x;
};
}
static std::string fn1(simple::model2 const& m) {
return std::to_string(m.x);
};
};
TEST_CASE("any via concept simple") {
using namespace anyxx;
using namespace simple;
CHECK(test1.fn1() == "model1");
CHECK(test2.fn1() == "42");
CHECK(cat({test1, test2}) == "model142");
}
C++ header only library for external polymorphism.
The core class template to control dispatch for external polymorphism.
Definition anyxx.hpp:2806
#define ANY_FN(ret, name, params, const_)
TRAIT function whose default behavior is to call an equally named member function of the model.
Definition anyxx.hpp:1019
#define ANY_MODEL_MAP(model_, trait_)
ANY_MODEL_MAP macro.
Definition anyxx.hpp:1192
#define TRAIT(n, fns)
Macro to define the functional behavior for an any.
Definition anyxx.hpp:774