1 // Copyright 2015-2017 Hans Dembinski
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #include <boost/core/lightweight_test.hpp>
8 #include <boost/histogram/detail/static_if.hpp>
9 #include "throw_exception.hpp"
11 using namespace boost::histogram::detail;
14 using T = std::true_type;
15 using F = std::false_type;
17 // check that branch not taken does not have to compile
18 BOOST_TEST_EQ(static_if<T>([](auto) { return 1; }, [] {}, 0), 1);
19 BOOST_TEST_EQ(static_if<F>([] {}, [](auto) { return 1; }, 0), 1);
21 BOOST_TEST_EQ(static_if_c<true>([](auto) { return 1; }, [] {}, 0), 1);
22 BOOST_TEST_EQ(static_if_c<false>([] {}, [](auto) { return 1; }, 0), 1);
24 // check that noexcept is correctly propagated
25 auto may_throw = [](auto x) { return x; };
26 auto no_throw = [](auto x) noexcept { return x; };
28 // make this work with -fno-exceptions
29 BOOST_TEST_EQ(noexcept(static_if<F>(no_throw, may_throw, 0)), noexcept(may_throw(0)));
30 BOOST_TEST(noexcept(static_if<T>(no_throw, may_throw, 0)));
32 return boost::report_errors();