RESTinio
Loading...
Searching...
No Matches
compiler_features.hpp
Go to the documentation of this file.
1/*
2 * RESTinio
3 */
4
5/*!
6 * @file
7 * @brief Detection of compiler version and absence of various features.
8 *
9 * @since v.0.6.0
10 */
11
12#pragma once
13
14#include <utility>
15
16/*!
17 * @brief A wrapper around static_assert for checking that an expression
18 * is noexcept and execution of that expression
19 *
20 * Usage example:
21 * @code
22 * some_class::~some_class() noexcept {
23 * // We should have a guarantee that this call doesn't throw.
24 * RESTINIO_ENSURE_NOEXCEPT_CALL(m_some_resouce.release());
25 * ...
26 * }
27 * @endcode
28 *
29 * @attention
30 * This macro is a part of RESTinio and is not intended to be uses as
31 * a part of public API. It can be changed or remove in some future version
32 * without any prior notice.
33 *
34 * @since v.0.6.0
35 */
36#define RESTINIO_ENSURE_NOEXCEPT_CALL(expr)
37 static_assert(noexcept(expr), "this call is expected to be noexcept: " #expr);
38 expr
39
40/*!
41 * @brief A wrapper around static_assert for checking that an expression is
42 * noexcept
43 *
44 * Usage example:
45 * @code
46 * void remove_appropriate_items_at_front(some_container_t & cnt) noexcept {
47 * RESTINIO_STATIC_ASSERT_NOEXCEPT(cnt.empty());
48 * RESTINIO_STATIC_ASSERT_NOEXCEPT(cnt.front());
49 * RESTINIO_STATIC_ASSERT_NOEXCEPT(cnt.pop_front());
50 *
51 * while(!cnt.empty() && some_confitions(cnt.front()) {
52 * // We don't expect exceptions here.
53 * cnt.pop_front();
54 * }
55 * }
56 * @endcode
57 *
58 * @attention
59 * This macro is a part of RESTinio and is not intended to be uses as
60 * a part of public API. It can be changed or remove in some future version
61 * without any prior notice.
62 *
63 * @since v.0.6.0
64 */
65#define RESTINIO_STATIC_ASSERT_NOEXCEPT(expr)
66 static_assert(noexcept(expr), #expr " is expected to be noexcept" )
67
68/*!
69 * @brief A wrapper around static_assert for checking that an expression is
70 * not noexcept.
71 *
72 * Usage example:
73 * @code
74 * some_class::~some_class() noexcept {
75 * // If that call throws then we have to use try-catch block.
76 * RESTINIO_STATIC_ASSERT_NOT_NOEXCEPT(m_some_resouce.release());
77 * try {
78 * m_some_resouce.release();
79 * }
80 * catch(...) {}
81 * ...
82 * }
83 * @endcode
84 *
85 * @attention
86 * This macro is a part of RESTinio and is not intended to be uses as
87 * a part of public API. It can be changed or remove in some future version
88 * without any prior notice.
89 *
90 * @since v.0.6.0
91 */
92#define RESTINIO_STATIC_ASSERT_NOT_NOEXCEPT(expr)
93 static_assert(!noexcept(expr), #expr " is not expected to be noexcept" )