RESTinio
compiler_features.hpp
Go to the documentation of this file.
1 /*
2  * RESTinio
3  */
4 
12 #pragma once
13 
14 #include <utility>
15 
16 // Try to use __has_cpp_attribute if it is supported.
17 #if defined(__has_cpp_attribute)
18  // clang-4 and clang-5 produce warnings when [[nodiscard]]
19  // is used with -std=c++11 and -std=c++14.
20  #if __has_cpp_attribute(nodiscard) && \
21  !(defined(__clang__) && __cplusplus < 201703L)
22  #define RESTINIO_NODISCARD [[nodiscard]]
23  #endif
24 
25  #if __has_cpp_attribute(fallthrough) && \
26  !(defined(__clang__) && __cplusplus < 201703L)
27  #define RESTINIO_FALLTHROUGH [[fallthrough]]
28  #endif
29 #endif
30 
31 // Handle the result of __has_cpp_attribute.
32 #if !defined( RESTINIO_NODISCARD )
33  #define RESTINIO_NODISCARD
34 #endif
35 
36 #if !defined( RESTINIO_FALLTHROUGH )
37  #define RESTINIO_FALLTHROUGH
38 #endif
39 
60 #define RESTINIO_ENSURE_NOEXCEPT_CALL(expr) \
61  static_assert(noexcept(expr), "this call is expected to be noexcept: " #expr); \
62  expr
63 
89 #define RESTINIO_STATIC_ASSERT_NOEXCEPT(expr) \
90  static_assert(noexcept(expr), #expr " is expected to be noexcept" )
91 
116 #define RESTINIO_STATIC_ASSERT_NOT_NOEXCEPT(expr) \
117  static_assert(!noexcept(expr), #expr " is not expected to be noexcept" )
118 
119 namespace restinio
120 {
121 
122 namespace static_if_details
123 {
124 
125 template< bool Condition >
127 
128 template<>
129 struct static_if_impl<true>
130 {
131  template<typename If_Part, typename Else_Part>
132  static decltype(auto)
133  call( If_Part && if_part, Else_Part && )
134  {
135  return if_part();
136  }
137 };
138 
139 template<>
140 struct static_if_impl<false>
141 {
142  template<typename If_Part, typename Else_Part>
143  static decltype(auto)
144  call( If_Part &&, Else_Part && else_part )
145  {
146  return else_part();
147  }
148 };
149 
150 } /* namespace static_if_details */
151 
152 //
153 // static_if_else
154 //
174 template< bool Condition, typename If_Part, typename Else_Part >
175 decltype(auto)
176 static_if_else( If_Part && if_part, Else_Part && else_part )
177 {
179  std::forward<If_Part>(if_part),
180  std::forward<Else_Part>(else_part) );
181 }
182 
183 } /* namespace restinio */
184 
restinio::static_if_details::static_if_impl
Definition: compiler_features.hpp:126
restinio
Definition: asio_include.hpp:21
restinio::static_if_else
decltype(auto) static_if_else(If_Part &&if_part, Else_Part &&else_part)
An emulation of if constexpr for C++14.
Definition: compiler_features.hpp:176