| 1 | // Copyright (c) 2018-2024 Antony Polukhin |
|---|---|
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | // Test case for https://github.com/boostorg/pfr/issues/30 |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <boost/pfr.hpp> |
| 10 | #include <boost/core/lightweight_test.hpp> |
| 11 | |
| 12 | struct Message { |
| 13 | std::unique_ptr<int> data; |
| 14 | }; |
| 15 | |
| 16 | struct Message2 { |
| 17 | std::unique_ptr<int> data41 = std::make_unique<int>(args: 41); |
| 18 | std::unique_ptr<int> data42 = std::make_unique<int>(args: 42); |
| 19 | }; |
| 20 | |
| 21 | // Example from duplicate issue #45 |
| 22 | struct UniquePtr { |
| 23 | std::unique_ptr<int> a; |
| 24 | }; |
| 25 | static_assert (boost::pfr::tuple_size_v<UniquePtr> == 1, ""); |
| 26 | |
| 27 | int main() { |
| 28 | Message message; |
| 29 | auto& ptr = boost::pfr::get<0>(val&: message); |
| 30 | BOOST_TEST(ptr == nullptr); |
| 31 | |
| 32 | Message2 message2; |
| 33 | auto& ptr2 = boost::pfr::get<1>(val&: message2); |
| 34 | BOOST_TEST_EQ(*ptr2, 42); |
| 35 | |
| 36 | return boost::report_errors(); |
| 37 | } |
| 38 |
