]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/histogram/test/detail_static_if_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / histogram / test / detail_static_if_test.cpp
1 // Copyright 2015-2017 Hans Dembinski
2 //
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)
6
7 #include <boost/core/lightweight_test.hpp>
8 #include <boost/histogram/detail/static_if.hpp>
9 #include "throw_exception.hpp"
10
11 using namespace boost::histogram::detail;
12
13 int main() {
14 using T = std::true_type;
15 using F = std::false_type;
16
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);
20
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);
23
24 // check that noexcept is correctly propagated
25 auto may_throw = [](auto x) { return x; };
26 auto no_throw = [](auto x) noexcept { return x; };
27
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)));
31
32 return boost::report_errors();
33 }