From c29e7ff9ac8478e78ba568d3d74a7a7c937456f9 Mon Sep 17 00:00:00 2001 From: Alex Shabalin Date: Tue, 12 Mar 2024 11:21:38 +0100 Subject: [PATCH] Remove the is_constructible check because it breaks the usecase with forward declared types --- immer/box.hpp | 3 +-- test/extra/archive/test_box.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/immer/box.hpp b/immer/box.hpp index 711ac78f..ddf03636 100644 --- a/immer/box.hpp +++ b/immer/box.hpp @@ -74,8 +74,7 @@ class box */ template >::value && - std::is_constructible::value>> + !std::is_same>::value>> box(Arg&& arg) : impl_{detail::make(std::forward(arg))} {} diff --git a/test/extra/archive/test_box.cpp b/test/extra/archive/test_box.cpp index 769a59b0..55dc0139 100644 --- a/test/extra/archive/test_box.cpp +++ b/test/extra/archive/test_box.cpp @@ -88,3 +88,21 @@ TEST_CASE("Test saving and mutating a box") const auto loaded2 = loader.load(id2); REQUIRE(loaded2.get() == "hello world"); } + +namespace { +struct fwd_type; +struct test_type +{ + immer::box data; +}; +struct fwd_type +{ + int data = 123; +}; +} // namespace + +TEST_CASE("Test box with a fwd declared type") +{ + auto val = test_type{}; + REQUIRE(val.data.get().data == 123); +}