compiler_features.hpp
Go to the documentation of this file.
/*
* RESTinio
*/
#pragma once
#include <utility>
// Try to use __has_cpp_attribute if it is supported.
#if defined(__has_cpp_attribute)
// clang-4 and clang-5 produce warnings when [[nodiscard]]
// is used with -std=c++11 and -std=c++14.
#if __has_cpp_attribute(nodiscard) && \
!(defined(__clang__) && __cplusplus < 201703L)
#define RESTINIO_NODISCARD [[nodiscard]]
#endif
#if __has_cpp_attribute(fallthrough) && \
!(defined(__clang__) && __cplusplus < 201703L)
#define RESTINIO_FALLTHROUGH [[fallthrough]]
#endif
#endif
// Handle the result of __has_cpp_attribute.
#if !defined( RESTINIO_NODISCARD )
#define RESTINIO_NODISCARD
#endif
#if !defined( RESTINIO_FALLTHROUGH )
#define RESTINIO_FALLTHROUGH
#endif
#define RESTINIO_ENSURE_NOEXCEPT_CALL(expr) \
static_assert(noexcept(expr), "this call is expected to be noexcept: " #expr); \
expr
#define RESTINIO_STATIC_ASSERT_NOEXCEPT(expr) \
static_assert(noexcept(expr), #expr " is expected to be noexcept" )
#define RESTINIO_STATIC_ASSERT_NOT_NOEXCEPT(expr) \
static_assert(!noexcept(expr), #expr " is not expected to be noexcept" )
namespace restinio
{
namespace static_if_details
{
template< bool Condition >
struct static_if_impl;
template<>
struct static_if_impl<true>
{
template<typename If_Part, typename Else_Part>
static decltype(auto)
call( If_Part && if_part, Else_Part && )
{
return if_part();
}
};
template<>
struct static_if_impl<false>
{
template<typename If_Part, typename Else_Part>
static decltype(auto)
call( If_Part &&, Else_Part && else_part )
{
return else_part();
}
};
} /* namespace static_if_details */
//
// static_if_else
//
template< bool Condition, typename If_Part, typename Else_Part >
decltype(auto)
static_if_else( If_Part && if_part, Else_Part && else_part )
{
return static_if_details::static_if_impl<Condition>::call(
std::forward<If_Part>(if_part),
std::forward<Else_Part>(else_part) );
}
} /* namespace restinio */
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
restinio::static_if_details::static_if_impl< false >::call
static decltype(auto) call(If_Part &&, Else_Part &&else_part)
Definition: compiler_features.hpp:144
restinio::static_if_details::static_if_impl< true >::call
static decltype(auto) call(If_Part &&if_part, Else_Part &&)
Definition: compiler_features.hpp:133
restinio::static_if_details::static_if_impl
Definition: compiler_features.hpp:126