]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Macros/Asserts//BOOST_MPL_ASSERT_MSG |
2 | ||
3 | BOOST_MPL_ASSERT_MSG | |
4 | ==================== | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | #define BOOST_MPL_ASSERT_MSG( condition, message, types ) \\ | |
12 | |unspecified-token-seq| \\ | |
13 | /\*\*/ | |
14 | ||
15 | ||
16 | Description | |
17 | ----------- | |
18 | ||
19 | Generates a compilation error with an embedded custom message when the condition | |
20 | doesn't hold. | |
21 | ||
22 | ||
23 | Header | |
24 | ------ | |
25 | ||
26 | .. parsed-literal:: | |
27 | ||
28 | #include <boost/mpl/assert.hpp> | |
29 | ||
30 | ||
31 | Parameters | |
32 | ---------- | |
33 | ||
34 | +---------------+-----------------------------------+-----------------------------------------------+ | |
35 | | Parameter | Requirement | Description | | |
36 | +===============+===================================+===============================================+ | |
37 | | ``condition`` | An integral constant expression | A condition to be asserted. | | |
38 | +---------------+-----------------------------------+-----------------------------------------------+ | |
39 | | ``message`` | A legal identifier token | A custom message in a form of a legal C++ | | |
40 | | | | identifier token. | | |
41 | +---------------+-----------------------------------+-----------------------------------------------+ | |
42 | | ``types`` | A legal function parameter list | A parenthized list of types to be displayed | | |
43 | | | | in the error message. | | |
44 | +---------------+-----------------------------------+-----------------------------------------------+ | |
45 | ||
46 | ||
47 | Expression semantics | |
48 | -------------------- | |
49 | ||
50 | For any integral constant expression ``expr``, legal C++ identifier ``message``, and | |
51 | arbitrary types ``t1``, ``t2``,... ``tn``: | |
52 | ||
53 | ||
54 | .. parsed-literal:: | |
55 | ||
56 | BOOST_MPL_ASSERT_MSG( expr, message, (t1, t2,... tn) ); | |
57 | ||
58 | :Return type: | |
59 | None. | |
60 | ||
61 | :Precondition: | |
62 | ``t1``, ``t2``,... ``tn`` are non-``void``. | |
63 | ||
64 | :Semantics: | |
65 | Generates a compilation error if ``expr != true``, otherwise | |
66 | has no effect. | |
67 | ||
68 | When possible within the compiler's diagnostic capabilities, | |
69 | the error message will include the ``message`` identifier and the parenthized | |
70 | list of ``t1``, ``t2``,... ``tn`` types, and have a general form of: | |
71 | ||
72 | .. parsed-literal:: | |
73 | ||
74 | |...| \*\*\*\*\*\*\*\*\*\*\*\*( |...|::message )\*\*\*\*\*\*\*\*\*\*\*\*)(t1, t2,... tn) |...| | |
75 | ||
76 | ||
77 | .. parsed-literal:: | |
78 | ||
79 | BOOST_MPL_ASSERT_MSG( expr, message, (types<t1, t2,... tn>) ); | |
80 | ||
81 | :Return type: | |
82 | None. | |
83 | ||
84 | :Precondition: | |
85 | None. | |
86 | ||
87 | :Semantics: | |
88 | Generates a compilation error if ``expr != true``, otherwise | |
89 | has no effect. | |
90 | ||
91 | When possible within the compiler's diagnostics capabilities, | |
92 | the error message will include the ``message`` identifier and the list of | |
93 | ``t1``, ``t2``,... ``tn`` types, and have a general form of: | |
94 | ||
95 | .. parsed-literal:: | |
96 | ||
97 | |...| \*\*\*\*\*\*\*\*\*\*\*\*( |...|::message )\*\*\*\*\*\*\*\*\*\*\*\*)(types<t1, t2,... tn>) |...| | |
98 | ||
99 | ||
100 | Example | |
101 | ------- | |
102 | ||
103 | :: | |
104 | ||
105 | template< typename T > struct my | |
106 | { | |
107 | // ... | |
108 | BOOST_MPL_ASSERT_MSG( | |
109 | is_integral<T>::value | |
110 | , NON_INTEGRAL_TYPES_ARE_NOT_ALLOWED | |
111 | , (T) | |
112 | ); | |
113 | }; | |
114 | ||
115 | my<void*> test; | |
116 | ||
117 | // In instantiation of `my<void*>': | |
118 | // instantiated from here | |
119 | // conversion from ` | |
120 | // mpl_::failed************(my<void*>:: | |
121 | // NON_INTEGRAL_TYPES_ARE_NOT_ALLOWED::************)(void*) | |
122 | // ' to non-scalar type `mpl_::assert<false>' requested | |
123 | ||
124 | ||
125 | See also | |
126 | -------- | |
127 | ||
128 | |Asserts|, |BOOST_MPL_ASSERT|, |BOOST_MPL_ASSERT_NOT|, |BOOST_MPL_ASSERT_RELATION| | |
129 | ||
130 | ||
131 |