| 1 | /*============================================================================= |
|---|---|
| 2 | Copyright (c) 2017 Paul Fultz II |
| 3 | returns.cpp |
| 4 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | ==============================================================================*/ |
| 7 | #include <boost/hof/returns.hpp> |
| 8 | #include "test.hpp" |
| 9 | |
| 10 | #if !defined (__GNUC__) || defined (__clang__) |
| 11 | struct add_1 |
| 12 | { |
| 13 | int a; |
| 14 | add_1() : a(1) {} |
| 15 | |
| 16 | BOOST_HOF_RETURNS_CLASS(add_1); |
| 17 | |
| 18 | template<class T> |
| 19 | auto operator()(T x) const |
| 20 | BOOST_HOF_RETURNS(x+BOOST_HOF_CONST_THIS->a); |
| 21 | }; |
| 22 | |
| 23 | BOOST_HOF_TEST_CASE() |
| 24 | { |
| 25 | BOOST_HOF_TEST_CHECK(3 == add_1()(2)); |
| 26 | } |
| 27 | #endif |
| 28 | // TODO: check noexcept |
| 29 | struct id |
| 30 | { |
| 31 | template<class T> |
| 32 | constexpr auto operator()(T x) const BOOST_HOF_RETURNS |
| 33 | (x); |
| 34 | }; |
| 35 | |
| 36 | BOOST_HOF_TEST_CASE() |
| 37 | { |
| 38 | BOOST_HOF_TEST_CHECK(id{}(3) == 3); |
| 39 | BOOST_HOF_STATIC_TEST_CHECK(id{}(3) == 3); |
| 40 | } |
| 41 | |
| 42 | struct void_ {}; |
| 43 | constexpr void_ no_op() { return void_{}; } |
| 44 | |
| 45 | struct id_comma |
| 46 | { |
| 47 | template<class T> |
| 48 | constexpr auto operator()(T&& x) const BOOST_HOF_RETURNS |
| 49 | (no_op(), boost::hof::forward<T>(x)); |
| 50 | }; |
| 51 | |
| 52 | BOOST_HOF_TEST_CASE() |
| 53 | { |
| 54 | BOOST_HOF_TEST_CHECK(id_comma{}(3) == 3); |
| 55 | BOOST_HOF_STATIC_TEST_CHECK(id_comma{}(3) == 3); |
| 56 | } |
| 57 |
