| 1 | <?xml version="1.0" encoding="utf-8" ?> |
|---|
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
|---|
| 4 | <!-- Copyright Aleksey Gurtovoy 2006. Distributed under the Boost --> |
|---|
| 5 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 6 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 7 | <head> |
|---|
| 8 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|---|
| 9 | <meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" /> |
|---|
| 10 | <title>The MPL Reference Manual: BOOST_MPL_ASSERT_MSG</title> |
|---|
| 11 | <link rel="stylesheet" href="../style.css" type="text/css" /> |
|---|
| 12 | </head> |
|---|
| 13 | <body class="docframe refmanual"> |
|---|
| 14 | <table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./assert.html" class="navigation-link">Prev</a> <a href="./assert-not.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./assert.html" class="navigation-link">Back</a> <a href="./assert-not.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./asserts.html" class="navigation-link">Up</a> <a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td> |
|---|
| 15 | <td class="header-group page-location"><a href="../refmanual.html" class="navigation-link">Front Page</a> / <a href="./macros.html" class="navigation-link">Macros</a> / <a href="./asserts.html" class="navigation-link">Asserts</a> / <a href="./assert-msg.html" class="navigation-link">BOOST_MPL_ASSERT_MSG</a></td> |
|---|
| 16 | </tr></table><div class="header-separator"></div> |
|---|
| 17 | <div class="section" id="assert-msg"> |
|---|
| 18 | <h1><a class="toc-backref" href="./asserts.html#id512" name="assert-msg">BOOST_MPL_ASSERT_MSG</a></h1> |
|---|
| 19 | <div class="section" id="asserts-assert-synopsis"> |
|---|
| 20 | <h3><a class="subsection-title" href="#synopsis" name="synopsis">Synopsis</a></h3> |
|---|
| 21 | <pre class="literal-block"> |
|---|
| 22 | #define <a href="./assert-msg.html" class="identifier">BOOST_MPL_ASSERT_MSG</a>( condition, message, types ) \ |
|---|
| 23 | <em>unspecified token sequence</em> \ |
|---|
| 24 | /**/ |
|---|
| 25 | </pre> |
|---|
| 26 | </div> |
|---|
| 27 | <div class="section" id="asserts-assert-description"> |
|---|
| 28 | <h3><a class="subsection-title" href="#description" name="description">Description</a></h3> |
|---|
| 29 | <p>Generates a compilation error with an embedded custom message when the condition |
|---|
| 30 | doesn't hold.</p> |
|---|
| 31 | </div> |
|---|
| 32 | <div class="section" id="asserts-assert-header"> |
|---|
| 33 | <h3><a class="subsection-title" href="#header" name="header">Header</a></h3> |
|---|
| 34 | <pre class="literal-block"> |
|---|
| 35 | #include <<a href="../../../../boost/mpl/assert.hpp" class="header">boost/mpl/assert.hpp</a>> |
|---|
| 36 | </pre> |
|---|
| 37 | </div> |
|---|
| 38 | <div class="section" id="asserts-assert-parameters"> |
|---|
| 39 | <h3><a class="subsection-title" href="#parameters" name="parameters">Parameters</a></h3> |
|---|
| 40 | <table border="1" class="table"> |
|---|
| 41 | <colgroup> |
|---|
| 42 | <col width="15%" /> |
|---|
| 43 | <col width="36%" /> |
|---|
| 44 | <col width="48%" /> |
|---|
| 45 | </colgroup> |
|---|
| 46 | <thead valign="bottom"> |
|---|
| 47 | <tr><th>Parameter</th> |
|---|
| 48 | <th>Requirement</th> |
|---|
| 49 | <th>Description</th> |
|---|
| 50 | </tr> |
|---|
| 51 | </thead> |
|---|
| 52 | <tbody valign="top"> |
|---|
| 53 | <tr><td><tt class="literal"><span class="pre">condition</span></tt></td> |
|---|
| 54 | <td>An integral constant expression</td> |
|---|
| 55 | <td>A condition to be asserted.</td> |
|---|
| 56 | </tr> |
|---|
| 57 | <tr><td><tt class="literal"><span class="pre">message</span></tt></td> |
|---|
| 58 | <td>A legal identifier token</td> |
|---|
| 59 | <td>A custom message in a form of a legal C++ |
|---|
| 60 | identifier token.</td> |
|---|
| 61 | </tr> |
|---|
| 62 | <tr><td><tt class="literal"><span class="pre">types</span></tt></td> |
|---|
| 63 | <td>A legal function parameter list</td> |
|---|
| 64 | <td>A parenthized list of types to be displayed |
|---|
| 65 | in the error message.</td> |
|---|
| 66 | </tr> |
|---|
| 67 | </tbody> |
|---|
| 68 | </table> |
|---|
| 69 | </div> |
|---|
| 70 | <div class="section" id="asserts-assert-expression-semantics"> |
|---|
| 71 | <h3><a class="subsection-title" href="#expression-semantics" name="expression-semantics">Expression semantics</a></h3> |
|---|
| 72 | <p>For any integral constant expression <tt class="literal"><span class="pre">expr</span></tt>, legal C++ identifier <tt class="literal"><span class="pre">message</span></tt>, and |
|---|
| 73 | arbitrary types <tt class="literal"><span class="pre">t1</span></tt>, <tt class="literal"><span class="pre">t2</span></tt>,... <tt class="literal"><span class="pre">tn</span></tt>:</p> |
|---|
| 74 | <pre class="literal-block"> |
|---|
| 75 | <a href="./assert-msg.html" class="identifier">BOOST_MPL_ASSERT_MSG</a>( expr, message, (t1, t2,... tn) ); |
|---|
| 76 | </pre> |
|---|
| 77 | <table class="field-list" frame="void" rules="none"> |
|---|
| 78 | <col class="field-name" /> |
|---|
| 79 | <col class="field-body" /> |
|---|
| 80 | <tbody valign="top"> |
|---|
| 81 | <tr class="field"><th class="field-name">Return type:</th><td class="field-body">None.</td> |
|---|
| 82 | </tr> |
|---|
| 83 | <tr class="field"><th class="field-name">Precondition:</th><td class="field-body"><tt class="literal"><span class="pre">t1</span></tt>, <tt class="literal"><span class="pre">t2</span></tt>,... <tt class="literal"><span class="pre">tn</span></tt> are non-<tt class="literal"><span class="pre">void</span></tt>.</td> |
|---|
| 84 | </tr> |
|---|
| 85 | <tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first">Generates a compilation error if <tt class="literal"><span class="pre">expr::value</span> <span class="pre">!=</span> <span class="pre">true</span></tt>, otherwise |
|---|
| 86 | has no effect.</p> |
|---|
| 87 | <p>When possible within the compiler's diagnostic capabilities, |
|---|
| 88 | the error message will include the <tt class="literal"><span class="pre">message</span></tt> identifier and the parenthized |
|---|
| 89 | list of <tt class="literal"><span class="pre">t1</span></tt>, <tt class="literal"><span class="pre">t2</span></tt>,... <tt class="literal"><span class="pre">tn</span></tt> types, and have a general form of:</p> |
|---|
| 90 | <pre class="last literal-block"> |
|---|
| 91 | <em>...</em> ************( <em>...</em>::message )************)(t1, t2,... tn) <em>...</em> |
|---|
| 92 | </pre> |
|---|
| 93 | </td> |
|---|
| 94 | </tr> |
|---|
| 95 | </tbody> |
|---|
| 96 | </table> |
|---|
| 97 | <pre class="literal-block"> |
|---|
| 98 | <a href="./assert-msg.html" class="identifier">BOOST_MPL_ASSERT_MSG</a>( expr, message, (types<t1, t2,... tn>) ); |
|---|
| 99 | </pre> |
|---|
| 100 | <table class="field-list" frame="void" rules="none"> |
|---|
| 101 | <col class="field-name" /> |
|---|
| 102 | <col class="field-body" /> |
|---|
| 103 | <tbody valign="top"> |
|---|
| 104 | <tr class="field"><th class="field-name">Return type:</th><td class="field-body">None.</td> |
|---|
| 105 | </tr> |
|---|
| 106 | <tr class="field"><th class="field-name">Precondition:</th><td class="field-body">None.</td> |
|---|
| 107 | </tr> |
|---|
| 108 | <tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first">Generates a compilation error if <tt class="literal"><span class="pre">expr::value</span> <span class="pre">!=</span> <span class="pre">true</span></tt>, otherwise |
|---|
| 109 | has no effect.</p> |
|---|
| 110 | <p>When possible within the compiler's diagnostics capabilities, |
|---|
| 111 | the error message will include the <tt class="literal"><span class="pre">message</span></tt> identifier and the list of |
|---|
| 112 | <tt class="literal"><span class="pre">t1</span></tt>, <tt class="literal"><span class="pre">t2</span></tt>,... <tt class="literal"><span class="pre">tn</span></tt> types, and have a general form of:</p> |
|---|
| 113 | <pre class="last literal-block"> |
|---|
| 114 | <em>...</em> ************( <em>...</em>::message )************)(types<t1, t2,... tn>) <em>...</em> |
|---|
| 115 | </pre> |
|---|
| 116 | </td> |
|---|
| 117 | </tr> |
|---|
| 118 | </tbody> |
|---|
| 119 | </table> |
|---|
| 120 | </div> |
|---|
| 121 | <div class="section" id="asserts-assert-example"> |
|---|
| 122 | <h3><a class="subsection-title" href="#example" name="example">Example</a></h3> |
|---|
| 123 | <pre class="literal-block"> |
|---|
| 124 | template< typename T > struct my |
|---|
| 125 | { |
|---|
| 126 | // ... |
|---|
| 127 | <a href="./assert-msg.html" class="identifier">BOOST_MPL_ASSERT_MSG</a>( |
|---|
| 128 | is_integral<T>::value |
|---|
| 129 | , NON_INTEGRAL_TYPES_ARE_NOT_ALLOWED |
|---|
| 130 | , (T) |
|---|
| 131 | ); |
|---|
| 132 | }; |
|---|
| 133 | |
|---|
| 134 | my<void*> test; |
|---|
| 135 | |
|---|
| 136 | // In instantiation of `my<void*>': |
|---|
| 137 | // instantiated from here |
|---|
| 138 | // conversion from ` |
|---|
| 139 | // mpl_::failed************(my<void*>:: |
|---|
| 140 | // NON_INTEGRAL_TYPES_ARE_NOT_ALLOWED::************)(void*) |
|---|
| 141 | // ' to non-scalar type `mpl_::assert<false>' requested |
|---|
| 142 | </pre> |
|---|
| 143 | </div> |
|---|
| 144 | <div class="section" id="asserts-assert-see-also"> |
|---|
| 145 | <h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3> |
|---|
| 146 | <p><a class="reference" href="./asserts.html">Asserts</a>, <a class="refentry reference" href="./assert.html"><tt class="refentry literal"><span class="pre">BOOST_MPL_ASSERT</span></tt></a>, <a class="refentry reference" href="./assert-not.html"><tt class="refentry literal"><span class="pre">BOOST_MPL_ASSERT_NOT</span></tt></a>, <a class="refentry reference" href="./assert-relation.html"><tt class="refentry literal"><span class="pre">BOOST_MPL_ASSERT_RELATION</span></tt></a></p> |
|---|
| 147 | <!-- modtime: November 10, 2004 04:45:24 +0000 --> |
|---|
| 148 | <!-- Macros/Asserts//BOOST_MPL_ASSERT_NOT --> |
|---|
| 149 | </div> |
|---|
| 150 | </div> |
|---|
| 151 | |
|---|
| 152 | <div class="footer-separator"></div> |
|---|
| 153 | <table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./assert.html" class="navigation-link">Prev</a> <a href="./assert-not.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./assert.html" class="navigation-link">Back</a> <a href="./assert-not.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./asserts.html" class="navigation-link">Up</a> <a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td> |
|---|
| 154 | </tr></table></body> |
|---|
| 155 | </html> |
|---|