• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018-2019 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 #ifndef BOOST_HISTOGRAM_DETAIL_STATIC_IF_HPP
8 #define BOOST_HISTOGRAM_DETAIL_STATIC_IF_HPP
9 
10 #include <type_traits>
11 #include <utility>
12 
13 namespace boost {
14 namespace histogram {
15 namespace detail {
16 
17 template <class T, class F, class... Args>
static_if_impl(std::true_type,T && t,F &&,Args &&...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)...);
22 }
23 
24 template <class T, class F, class... Args>
static_if_impl(std::false_type,T &&,F && f,Args &&...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)...);
29 }
30 
31 template <bool B, class... Ts>
static_if_c(Ts &&...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)...);
35 }
36 
37 template <class Bool, class... Ts>
static_if(Ts &&...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)...);
41 }
42 
43 } // namespace detail
44 } // namespace histogram
45 } // namespace boost
46 
47 #endif
48