RESTinio
Loading...
Searching...
No Matches
compiler_features.hpp
Go to the documentation of this file.
1/*
2 * RESTinio
3 */
4
12#pragma once
13
14#include <utility>
15
16// It's necessary for __cpp_lib_launder and std::launder.
17#include <new>
18
19// Try to use __has_cpp_attribute if it is supported.
20#if defined(__has_cpp_attribute)
21 // clang-4 and clang-5 produce warnings when [[nodiscard]]
22 // is used with -std=c++11 and -std=c++14.
23 #if __has_cpp_attribute(nodiscard) && \
24 !(defined(__clang__) && __cplusplus < 201703L)
25 #define RESTINIO_NODISCARD [[nodiscard]]
26 #endif
27
28 #if __has_cpp_attribute(fallthrough) && \
29 !(defined(__clang__) && __cplusplus < 201703L)
30 #define RESTINIO_FALLTHROUGH [[fallthrough]]
31 #endif
32#endif
33
34// Handle the result of __has_cpp_attribute.
35#if !defined( RESTINIO_NODISCARD )
36 #define RESTINIO_NODISCARD
37#endif
38
39#if !defined( RESTINIO_FALLTHROUGH )
40 #define RESTINIO_FALLTHROUGH
41#endif
42
43// Handle the presence of std::launder.
44#if defined(__cpp_lib_launder)
45 #define RESTINIO_STD_LAUNDER(x) std::launder(x)
46#else
47 #define RESTINIO_STD_LAUNDER(x) x
48#endif
49
70#define RESTINIO_ENSURE_NOEXCEPT_CALL(expr) \
71 static_assert(noexcept(expr), "this call is expected to be noexcept: " #expr); \
72 expr
73
99#define RESTINIO_STATIC_ASSERT_NOEXCEPT(expr) \
100 static_assert(noexcept(expr), #expr " is expected to be noexcept" )
101
126#define RESTINIO_STATIC_ASSERT_NOT_NOEXCEPT(expr) \
127 static_assert(!noexcept(expr), #expr " is not expected to be noexcept" )
128
129namespace restinio
130{
131
132namespace static_if_details
133{
134
135template< bool Condition >
137
138template<>
139struct static_if_impl<true>
140{
141 template<typename If_Part, typename Else_Part>
142 static decltype(auto)
143 call( If_Part && if_part, Else_Part && )
144 {
145 return if_part();
146 }
147};
148
149template<>
150struct static_if_impl<false>
151{
152 template<typename If_Part, typename Else_Part>
153 static decltype(auto)
154 call( If_Part &&, Else_Part && else_part )
155 {
156 return else_part();
157 }
158};
159
160} /* namespace static_if_details */
161
162//
163// static_if_else
164//
184template< bool Condition, typename If_Part, typename Else_Part >
185decltype(auto)
186static_if_else( If_Part && if_part, Else_Part && else_part )
187{
189 std::forward<If_Part>(if_part),
190 std::forward<Else_Part>(else_part) );
191}
192
193} /* namespace restinio */
194
decltype(auto) static_if_else(If_Part &&if_part, Else_Part &&else_part)
An emulation of if constexpr for C++14.
static decltype(auto) call(If_Part &&, Else_Part &&else_part)
static decltype(auto) call(If_Part &&if_part, Else_Part &&)