| 1 | /* |
|---|---|
| 2 | Copyright 2022 Glen Joseph Fernandes |
| 3 | (glenjofe@gmail.com) |
| 4 | |
| 5 | Distributed under the Boost Software License, Version 1.0. |
| 6 | (http://www.boost.org/LICENSE_1_0.txt) |
| 7 | */ |
| 8 | #include <boost/config.hpp> |
| 9 | #if !defined(BOOST_NO_CXX11_CONSTEXPR) |
| 10 | #include <boost/core/empty_value.hpp> |
| 11 | #include <boost/core/lightweight_test.hpp> |
| 12 | |
| 13 | struct empty { |
| 14 | constexpr int value() const { |
| 15 | return 1; |
| 16 | } |
| 17 | }; |
| 18 | |
| 19 | class type { |
| 20 | public: |
| 21 | explicit constexpr type(int count) |
| 22 | : value_(count) { } |
| 23 | |
| 24 | constexpr int value() const { |
| 25 | return value_; |
| 26 | } |
| 27 | |
| 28 | private: |
| 29 | int value_; |
| 30 | }; |
| 31 | |
| 32 | void test_int() |
| 33 | { |
| 34 | constexpr boost::empty_value<int> v(boost::empty_init_t(), 4); |
| 35 | constexpr int c = v.get(); |
| 36 | BOOST_TEST_EQ(c, 4); |
| 37 | } |
| 38 | |
| 39 | void test_empty() |
| 40 | { |
| 41 | constexpr boost::empty_value<empty> v = boost::empty_init_t(); |
| 42 | constexpr int c = v.get().value(); |
| 43 | BOOST_TEST_EQ(c, 1); |
| 44 | } |
| 45 | |
| 46 | void test_type() |
| 47 | { |
| 48 | constexpr boost::empty_value<type> v(boost::empty_init_t(), 2); |
| 49 | constexpr int c = v.get().value(); |
| 50 | BOOST_TEST_EQ(c, 2); |
| 51 | } |
| 52 | |
| 53 | int main() |
| 54 | { |
| 55 | test_int(); |
| 56 | test_empty(); |
| 57 | test_type(); |
| 58 | return boost::report_errors(); |
| 59 | } |
| 60 | #else |
| 61 | int main() |
| 62 | { |
| 63 | return 0; |
| 64 | } |
| 65 | #endif |
| 66 |
