1 // Copyright 2018-2019 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 #ifndef BOOST_HISTOGRAM_DETAIL_STATIC_IF_HPP
8 #define BOOST_HISTOGRAM_DETAIL_STATIC_IF_HPP
10 #include <type_traits>
17 template <class T, class F, class... Args>
18 constexpr decltype(auto) static_if_impl(
19 std::true_type, T&& t, F&&,
20 Args&&... args) noexcept(noexcept(std::declval<T>()(std::declval<Args>()...))) {
21 return std::forward<T>(t)(std::forward<Args>(args)...);
24 template <class T, class F, class... Args>
25 constexpr decltype(auto) static_if_impl(
26 std::false_type, T&&, F&& f,
27 Args&&... args) noexcept(noexcept(std::declval<F>()(std::declval<Args>()...))) {
28 return std::forward<F>(f)(std::forward<Args>(args)...);
31 template <bool B, class... Ts>
32 constexpr decltype(auto) static_if_c(Ts&&... ts) noexcept(
33 noexcept(static_if_impl(std::integral_constant<bool, B>{}, std::declval<Ts>()...))) {
34 return static_if_impl(std::integral_constant<bool, B>{}, std::forward<Ts>(ts)...);
37 template <class Bool, class... Ts>
38 constexpr decltype(auto) static_if(Ts&&... ts) noexcept(
39 noexcept(static_if_impl(Bool{}, std::declval<Ts>()...))) {
40 return static_if_impl(Bool{}, std::forward<Ts>(ts)...);
44 } // namespace histogram