• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>BOOST_DECLARE_HAS_MEMBER</title>
5<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../index.html" title="Chapter 1. Boost.Convert 2.0">
8<link rel="up" href="../supporting_tools.html" title="Supporting Tools">
9<link rel="prev" href="boost__cnv__is_range.html" title="boost::cnv::is_range">
10<link rel="next" href="boost_declare_is_callable.html" title="BOOST_DECLARE_IS_CALLABLE">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="boost__cnv__is_range.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../supporting_tools.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="boost_declare_is_callable.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h3 class="title">
27<a name="boost_convert.supporting_tools.boost_declare_has_member"></a><a class="link" href="boost_declare_has_member.html" title="BOOST_DECLARE_HAS_MEMBER">BOOST_DECLARE_HAS_MEMBER</a>
28</h3></div></div></div>
29<p>
30        The BOOST_DECLARE_HAS_MEMBER macro allows to declare a trait which would
31        then let introspect the existence of a class member (a data member or a member
32        function) with the specified name.
33      </p>
34<p>
35        For example, the following declarations introduce <code class="computeroutput"><span class="identifier">local</span><span class="special">::</span><span class="identifier">has_begin</span></code>
36        and <code class="computeroutput"><span class="identifier">local</span><span class="special">::</span><span class="identifier">has_funop</span></code> traits which then allow to test
37        if the supplied class has respectively <code class="computeroutput"><span class="identifier">begin</span></code>
38        and <code class="computeroutput"><span class="keyword">operator</span><span class="special">()</span></code>
39        members:
40      </p>
41<p>
42</p>
43<pre class="programlisting"><span class="keyword">namespace</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">local</span>
44<span class="special">{</span>
45    <span class="identifier">BOOST_DECLARE_HAS_MEMBER</span><span class="special">(</span><span class="identifier">has_begin</span><span class="special">,</span> <span class="identifier">begin</span><span class="special">);</span>
46    <span class="identifier">BOOST_DECLARE_HAS_MEMBER</span><span class="special">(</span><span class="identifier">has_funop</span><span class="special">,</span> <span class="keyword">operator</span><span class="special">());</span>
47<span class="special">}}</span>
48</pre>
49<p>
50      </p>
51<p>
52        Now these traits can be used as follows:
53      </p>
54<p>
55</p>
56<pre class="programlisting"><span class="keyword">namespace</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">local</span>
57<span class="special">{</span>
58    <span class="keyword">struct</span> <span class="identifier">test01</span> <span class="special">{</span> <span class="keyword">int</span>   <span class="identifier">begin</span><span class="special">;</span> <span class="special">};</span>
59    <span class="keyword">struct</span> <span class="identifier">test02</span> <span class="special">{</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">begin</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> <span class="special">}</span> <span class="special">};</span>
60    <span class="keyword">struct</span> <span class="identifier">test22</span> <span class="special">{</span> <span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()()</span> <span class="special">{}</span> <span class="special">};</span>
61<span class="special">}}</span>
62</pre>
63<p>
64      </p>
65<p>
66</p>
67<pre class="programlisting"><span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">local</span><span class="special">::</span><span class="identifier">has_begin</span><span class="special">&lt;</span><span class="identifier">local</span><span class="special">::</span><span class="identifier">test01</span><span class="special">&gt;::</span><span class="identifier">value</span> <span class="special">==</span> <span class="keyword">true</span><span class="special">);</span>
68<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">local</span><span class="special">::</span><span class="identifier">has_begin</span><span class="special">&lt;</span><span class="identifier">local</span><span class="special">::</span><span class="identifier">test02</span><span class="special">&gt;::</span><span class="identifier">value</span> <span class="special">==</span> <span class="keyword">true</span><span class="special">);</span>
69<span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">local</span><span class="special">::</span><span class="identifier">has_funop</span><span class="special">&lt;</span><span class="identifier">local</span><span class="special">::</span><span class="identifier">test22</span><span class="special">&gt;::</span><span class="identifier">value</span> <span class="special">==</span> <span class="keyword">true</span><span class="special">);</span>
70</pre>
71<p>
72      </p>
73<p>
74        As it can be seen from the example the traits only check for the existence
75        of a member (be that a data member or a member function) with the specified
76        name.
77      </p>
78</div>
79<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
80<td align="left"></td>
81<td align="right"><div class="copyright-footer">Copyright © 2009-2016 Vladimir Batov<p>
82        Distributed under the Boost Software License, Version 1.0. See copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>.
83      </p>
84</div></td>
85</tr></table>
86<hr>
87<div class="spirit-nav">
88<a accesskey="p" href="boost__cnv__is_range.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../supporting_tools.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="boost_declare_is_callable.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
89</div>
90</body>
91</html>
92