| 1 | /*============================================================================= |
|---|---|
| 2 | Copyright (c) 2019 Nikita Kniazev |
| 3 | |
| 4 | Use, modification and distribution is subject to the Boost Software |
| 5 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 6 | http://www.boost.org/LICENSE_1_0.txt) |
| 7 | =============================================================================*/ |
| 8 | |
| 9 | #include <boost/spirit/home/support/unused.hpp> |
| 10 | #include <boost/static_assert.hpp> |
| 11 | #include <boost/type_traits/is_same.hpp> |
| 12 | |
| 13 | #if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && \ |
| 14 | !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) |
| 15 | #include <type_traits> |
| 16 | static_assert(std::is_trivial<boost::spirit::unused_type>::value, ""); |
| 17 | #endif |
| 18 | |
| 19 | void test_use(boost::spirit::unused_type) {} |
| 20 | |
| 21 | template <typename Expected, typename T> |
| 22 | void test(T&) |
| 23 | { |
| 24 | BOOST_STATIC_ASSERT((boost::is_same<T&, Expected>::value)); |
| 25 | } |
| 26 | |
| 27 | int main() |
| 28 | { |
| 29 | using boost::spirit::unused; |
| 30 | using boost::spirit::unused_type; |
| 31 | |
| 32 | unused_type unused_mut; |
| 33 | test<unused_type const&>(unused); |
| 34 | test<unused_type&>(unused_mut); |
| 35 | test<unused_type const&>(unused = 123); |
| 36 | test<unused_type const&>(unused = *&unused); |
| 37 | test<unused_type const&>(unused = unused_mut); |
| 38 | test<unused_type&>(unused_mut = 123); |
| 39 | test<unused_type&>(unused_mut = unused); |
| 40 | test<unused_type&>(unused_mut = *&unused_mut); |
| 41 | |
| 42 | test_use(0); |
| 43 | test_use(unused); |
| 44 | test_use(unused_mut); |
| 45 | } |
| 46 |
