1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
/*=============================================================================
Copyright (c) 2017 Paul Fultz II
always.cpp
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#include <boost/hof/always.hpp>
#include <boost/hof/function.hpp>
#include <memory>
#include "test.hpp"
BOOST_HOF_TEST_CASE()
{
static const int ten = 10;
BOOST_HOF_STATIC_TEST_CHECK(boost::hof::always(ten)(1,2,3,4,5) == 10);
BOOST_HOF_TEST_CHECK( boost::hof::always(ten)(1,2,3,4,5) == 10 );
int i = 10;
BOOST_HOF_TEST_CHECK( boost::hof::always(std::ref(i))(1,2,3,4,5) == 10 );
BOOST_HOF_TEST_CHECK( &boost::hof::always(std::ref(i))(1,2,3,4,5) == &i );
boost::hof::always()(1, 2);
static_assert(std::is_same<decltype(boost::hof::always()(1, 2)), BOOST_HOF_ALWAYS_VOID_RETURN>::value, "Failed");
}
BOOST_HOF_TEST_CASE()
{
int i = 10;
BOOST_HOF_TEST_CHECK( boost::hof::always_ref(i)(1,2,3,4,5) == 10 );
BOOST_HOF_TEST_CHECK( &boost::hof::always_ref(i)(1,2,3,4,5) == &i );
}
BOOST_HOF_STATIC_FUNCTION(gten) = boost::hof::always(std::integral_constant<int, 10>{});
BOOST_HOF_TEST_CASE()
{
BOOST_HOF_STATIC_TEST_CHECK(gten(1,2,3,4,5) == 10);
BOOST_HOF_TEST_CHECK(gten(1,2,3,4,5) == 10);
}
BOOST_HOF_TEST_CASE()
{
auto f = boost::hof::always(10);
STATIC_ASSERT_NOT_DEFAULT_CONSTRUCTIBLE(decltype(f));
BOOST_HOF_TEST_CHECK(f(1,2,3,4,5) == 10);
}
struct copy_throws
{
copy_throws() {}
copy_throws(copy_throws const&) {}
copy_throws(copy_throws&&) noexcept {}
};
BOOST_HOF_TEST_CASE()
{
static_assert(noexcept(boost::hof::always()()), "noexcept always");
static_assert(noexcept(boost::hof::always(1)()), "noexcept always");
static_assert(!noexcept(boost::hof::always(copy_throws{})()), "noexcept always");
copy_throws ct{};
static_assert(!noexcept(boost::hof::always(ct)()), "noexcept always");
static_assert(noexcept(boost::hof::always(std::ref(ct))()) == BOOST_HOF_IS_NOTHROW_COPY_CONSTRUCTIBLE(std::reference_wrapper<copy_throws>), "noexcept always");
auto ctf = boost::hof::always(copy_throws{});
static_assert(!noexcept(ctf()), "noexcept always");
}
|