summaryrefslogtreecommitdiff
path: root/asl/tests/box_tests.cpp
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-01-30 23:34:12 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-01-30 23:34:12 +0100
commit224048d0f4022f91c2074daddf9dcafbf11f2be9 (patch)
tree3b238537b9920e536f4220d22edda69df0c2645c /asl/tests/box_tests.cpp
parentf882f51c0500f9a31c5e77b252fee63ab3726f7e (diff)
Add implicit conversions for box from derived to base type
Diffstat (limited to 'asl/tests/box_tests.cpp')
-rw-r--r--asl/tests/box_tests.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/asl/tests/box_tests.cpp b/asl/tests/box_tests.cpp
index edb574c..3faf121 100644
--- a/asl/tests/box_tests.cpp
+++ b/asl/tests/box_tests.cpp
@@ -76,3 +76,27 @@ ASL_TEST(niche)
ASL_TEST_EXPECT(!opt2.has_value());
ASL_TEST_EXPECT(destroyed);
}
+
+class Base
+{
+public:
+ virtual ~Base() = default;
+ virtual int number() { return 1; }
+};
+
+class Derived : public Base
+{
+public:
+ int number() override { return 2; }
+};
+
+static_assert(asl::convertible_from<asl::box<Base>, asl::box<Derived>>);
+static_assert(asl::convertible_from<asl::box<Base>, asl::box<Base>>);
+static_assert(!asl::convertible_from<asl::box<Derived>, asl::box<Base>>);
+static_assert(!asl::convertible_from<asl::box<int>, asl::box<float>>);
+
+ASL_TEST(derived)
+{
+ asl::box<Base> obj = asl::make_box<Derived>();
+ ASL_TEST_ASSERT(obj->number() == 2);
+}