• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2017 Paul Fultz II
3     indirect.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/indirect.hpp>
8 #include "test.hpp"
9 
BOOST_HOF_TEST_CASE()10 BOOST_HOF_TEST_CASE()
11 {
12     BOOST_HOF_TEST_CHECK(3 == boost::hof::indirect(std::unique_ptr<binary_class>(new binary_class()))(1, 2));
13     BOOST_HOF_TEST_CHECK(3 == boost::hof::reveal(boost::hof::indirect(std::unique_ptr<binary_class>(new binary_class())))(1, 2));
14 
15     binary_class f;
16 
17     BOOST_HOF_TEST_CHECK(3 == boost::hof::indirect(&f)(1, 2));
18     BOOST_HOF_TEST_CHECK(3 == boost::hof::reveal(boost::hof::indirect(&f))(1, 2));
19 }
20 #if BOOST_HOF_HAS_NOEXCEPT_DEDUCTION
BOOST_HOF_TEST_CASE()21 BOOST_HOF_TEST_CASE()
22 {
23     binary_class f;
24     static_assert(noexcept(boost::hof::indirect(&f)(1, 2)), "noexcept indirect");
25 }
26 #endif
27 
28 struct mutable_function
29 {
mutable_functionmutable_function30     mutable_function() : value(0) {}
operator ()mutable_function31     void operator()(int a) { value += a; }
32     int value;
33 };
34 
BOOST_HOF_TEST_CASE()35 BOOST_HOF_TEST_CASE()
36 {
37     auto mf = mutable_function{};
38     boost::hof::indirect(&mf)(15);
39     boost::hof::indirect(&mf)(2);
40     BOOST_HOF_TEST_CHECK(mf.value == 17);
41 }
42 
43 
BOOST_HOF_TEST_CASE()44 BOOST_HOF_TEST_CASE()
45 {
46     auto mf = std::make_shared<mutable_function>();
47     boost::hof::indirect(mf)(15);
48     boost::hof::indirect(mf)(2);
49     BOOST_HOF_TEST_CHECK(mf->value == 17);
50 }
51 
52 
53