Vcsn  2.4
Be Rational
static-if.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <utility>
4 
6 
7 namespace vcsn
8 {
9  namespace detail
10  {
12  template <typename Then, typename Else>
13  auto static_if(std::true_type, Then&& then, Else&&)
14  {
15  return std::forward<Then>(then);
16  }
17 
19  template <typename Then, typename Else>
20  auto static_if(std::false_type, Then&&, Else&& else_)
21  {
22  return std::forward<Else>(else_);
23  }
24 
26  template <bool cond, typename Then, typename Else>
27  auto static_if(Then&& then, Else&& else_)
28  {
30  std::forward<Then>(then),
31  std::forward<Else>(else_));
32  }
33 
35  template <bool cond, typename Then>
36  auto static_if(Then&& then)
37  {
38  // Applies to both GCC and Clang. Cannot be done inside a
39  // statement.
40 #if defined __GNUC__
41 # pragma GCC diagnostic push
42 # pragma GCC diagnostic ignored "-Wunused-parameter"
43 #endif
44  return static_if<cond>(std::forward<Then>(then),
45 #if (defined __clang__ && __clang_major__ == 3 && __clang_minor__ < 6 \
46  || defined __GNUC__ && !defined __clang__ && __GNUC__ < 5)
47  // Clang 3.5 and GCC 4.9 require that we name the argument.
48  [](auto&&... args){}
49 #else
50  [](auto&&...){}
51 #endif
52  );
53 #if defined __GNUC__
54 # pragma GCC diagnostic pop
55 #endif
56  }
57  }
58 }
auto static_if(std::true_type, Then &&then, Else &&)
Execute the then-clause.
Definition: static-if.hh:13
Definition: a-star.hh:8
std::integral_constant< bool, B > bool_constant
Definition: type_traits.hh:12