diff --git a/test/box/recursive.cpp b/test/box/recursive.cpp index 9635f6e3..28003cce 100644 --- a/test/box/recursive.cpp +++ b/test/box/recursive.cpp @@ -13,6 +13,10 @@ #include #include +#include +#include +#include + #include struct rec_vec @@ -106,3 +110,80 @@ TEST_CASE("recursive set") CHECK(v3.children.count(rec_set{13, {}}) == 1); CHECK(v3.children.count(rec_set{14, {}}) == 0); } + +namespace example1 { + +struct a_type; + +struct b_type +{ + b_type(int a, immer::box val); + int a; + immer::box val; +}; + +struct a_type +{ + a_type(); + // this does not work with std::optional, because it seems like + // `immer::box` is still not considered complete at this point... + boost::optional> b; +}; + +b_type::b_type(int a, immer::box val) + : a(a) + , val(val) +{} + +a_type::a_type() + : b{} +{} + +} // namespace example1 + +TEST_CASE("recursive optional") +{ + auto x = example1::a_type{}; + auto y = example1::b_type{42, x}; + CHECK(y.a == 42); +} + +namespace example2 { + +struct empty_t +{}; + +struct a_type; + +struct b_type +{ + b_type(int a, immer::box val); + int a; + immer::box val; +}; + +struct a_type +{ + a_type(); + // this does not work with std::variant, because it seems like + // `immer::box` is still not considered complete at this point... + boost::variant b; +}; + +b_type::b_type(int a, immer::box val) + : a(a) + , val(val) +{} + +a_type::a_type() + : b{} +{} + +} // namespace example2 + +TEST_CASE("recursive variant") +{ + auto x = example2::a_type{}; + auto y = example2::b_type{42, x}; + CHECK(y.a == 42); +}