]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | <head> | |
5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
6 | <meta name="generator" content="Docutils 0.7: http://docutils.sourceforge.net/" /> | |
7 | <title>The MPL Reference Manual: Tag Dispatched Metafunction</title> | |
8 | <link rel="stylesheet" href="../style.css" type="text/css" /> | |
9 | </head> | |
10 | <body class="docframe refmanual"> | |
11 | <table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./placeholder-expression.html" class="navigation-link">Prev</a> <a href="./numeric-metafunction.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./placeholder-expression.html" class="navigation-link">Back</a> <a href="./numeric-metafunction.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./metafunctions-concepts.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> | |
12 | <td class="header-group page-location"><a href="../refmanual.html" class="navigation-link">Front Page</a> / <a href="./metafunctions.html" class="navigation-link">Metafunctions</a> / <a href="./metafunctions-concepts.html" class="navigation-link">Concepts</a> / <a href="./tag-dispatched-metafunction.html" class="navigation-link">Tag Dispatched Metafunction</a></td> | |
13 | </tr></table><div class="header-separator"></div> | |
14 | <div class="section" id="tag-dispatched-metafunction"> | |
15 | <h1><a class="toc-backref" href="./metafunctions-concepts.html#id1516">Tag Dispatched Metafunction</a></h1> | |
16 | <div class="section" id="id840"> | |
17 | <h3><a class="subsection-title" href="#summary" name="summary">Summary</a></h3> | |
18 | <p>A <a class="reference internal" href="./tag-dispatched-metafunction.html">Tag Dispatched Metafunction</a> is a <a class="reference internal" href="./metafunction.html">Metafunction</a> that employs a | |
19 | <em>tag dispatching</em> technique in its implementation to build an | |
20 | infrastructure for easy overriding/extenstion of the metafunction's | |
21 | behavior.</p> | |
22 | </div> | |
23 | <div class="section" id="notation"> | |
24 | <h3>Notation</h3> | |
25 | <table border="1" class="docutils table" id="tag-metafunction"> | |
26 | <colgroup> | |
27 | <col width="31%" /> | |
28 | <col width="69%" /> | |
29 | </colgroup> | |
30 | <thead valign="bottom"> | |
31 | <tr><th class="head">Symbol</th> | |
32 | <th class="head">Legend</th> | |
33 | </tr> | |
34 | </thead> | |
35 | <tbody valign="top"> | |
36 | <tr><td><em>name</em></td> | |
37 | <td>A placeholder token for the specific metafunction's name.</td> | |
38 | </tr> | |
39 | <tr><td><em>tag-metafunction</em></td> | |
40 | <td>A placeholder token for the tag metafunction's name.</td> | |
41 | </tr> | |
42 | <tr><td><em>tag</em></td> | |
43 | <td>A placeholder token for one of possible tag types | |
44 | returned by the tag metafunction.</td> | |
45 | </tr> | |
46 | </tbody> | |
47 | </table> | |
48 | </div> | |
49 | <div class="section" id="id841"> | |
50 | <h3><a class="subsection-title" href="#synopsis" name="synopsis">Synopsis</a></h3> | |
51 | <pre class="literal-block"> | |
52 | template< typename Tag > struct <em>name</em>_impl; | |
53 | ||
54 | template< | |
55 | typename X | |
56 | <em>[, ...]</em> | |
57 | > | |
58 | struct <em>name</em> | |
59 | : <em>name</em>_impl< typename <em>tag-<a href="./metafunction.html" class="identifier">metafunction</a></em><X>::type > | |
60 | ::template <a href="./apply.html" class="identifier">apply</a><X <em>[, ...]</em>> | |
61 | { | |
62 | }; | |
63 | ||
64 | template< typename Tag > struct <em>name</em>_impl | |
65 | { | |
66 | template< typename X <em>[, ...]</em> > struct <a href="./apply.html" class="identifier">apply</a> | |
67 | { | |
68 | // <em>default implementation</em> | |
69 | }; | |
70 | }; | |
71 | ||
72 | template<> struct <em>name</em>_impl<<em>tag</em>> | |
73 | { | |
74 | template< typename X <em>[, ...]</em> > struct <a href="./apply.html" class="identifier">apply</a> | |
75 | { | |
76 | // <em>tag-specific implementation</em> | |
77 | }; | |
78 | }; | |
79 | </pre> | |
80 | </div> | |
81 | <div class="section" id="id842"> | |
82 | <h3><a class="subsection-title" href="#description" name="description">Description</a></h3> | |
83 | <p>The usual mechanism for overriding a metafunction's behavior is class | |
84 | template specialization — given a library-defined metafunction <tt class="literal"><span class="pre">f</span></tt>, | |
85 | it's possible to write a specialization of <tt class="literal"><span class="pre">f</span></tt> for a specific type | |
86 | <tt class="literal"><span class="pre">user_type</span></tt> that would have the required semantics <a class="footnote-reference" href="#spec" id="id843">[4]</a>.</p> | |
87 | <p>While this mechanism is always available, it's not always the most | |
88 | convenient one, especially if it is desirable to specialize a | |
89 | metafunction's behavior for a <em>family</em> of related types. A typical | |
90 | example of it is numbered forms of sequence classes in MPL itself | |
91 | (<tt class="literal"><span class="pre">list0</span></tt>, ..., <tt class="literal"><span class="pre">list50</span></tt>, et al.), and sequence classes in general.</p> | |
92 | <p>A <a class="reference internal" href="./tag-dispatched-metafunction.html">Tag Dispatched Metafunction</a> is a concept name for an instance of | |
93 | the metafunction implementation infrastructure being employed by the | |
94 | library to make it easier for users and implementors to override the | |
95 | behavior of library's metafunctions operating on families of specific | |
96 | types.</p> | |
97 | <p>The infrastructure is built on a variation of the technique commonly | |
98 | known as <em>tag dispatching</em> (hence the concept name), | |
99 | and involves three entities: a metafunction itself, an associated | |
100 | tag-producing <a class="reference internal" href="./tag-dispatched-metafunction.html#tag-metafunction">tag metafunctions</a>, and the metafunction's | |
101 | implementation, in the form of a <a class="reference internal" href="./metafunction-class.html">Metafunction Class</a> template | |
102 | parametrized by a <tt class="literal"><span class="pre">Tag</span></tt> type parameter. The metafunction redirects | |
103 | to its implementation class template by invoking its specialization | |
104 | on a tag type produced by the tag metafunction with the original | |
105 | metafunction's parameters.</p> | |
106 | <table class="docutils footnote" frame="void" id="spec" rules="none"> | |
107 | <colgroup><col class="label" /><col /></colgroup> | |
108 | <tbody valign="top"> | |
109 | <tr><td class="label"><a class="fn-backref" href="#id843">[4]</a></td><td>Usually such user-defined specialization is still required | |
110 | to preserve the <tt class="literal"><span class="pre">f</span></tt>'s original invariants and complexity requirements.</td></tr> | |
111 | </tbody> | |
112 | </table> | |
113 | </div> | |
114 | <div class="section" id="id844"> | |
115 | <h3><a class="subsection-title" href="#example" name="example">Example</a></h3> | |
116 | <pre class="literal-block"> | |
117 | #include <<a href="../../../../boost/mpl/size.hpp" class="header">boost/mpl/size.hpp</a>> | |
118 | ||
119 | namespace user { | |
120 | ||
121 | struct bitset_tag; | |
122 | ||
123 | struct bitset0 | |
124 | { | |
125 | typedef bitset_tag tag; | |
126 | // ... | |
127 | }; | |
128 | ||
129 | template< typename B0 > struct bitset1 | |
130 | { | |
131 | typedef bitset_tag tag; | |
132 | // ... | |
133 | }; | |
134 | ||
135 | template< typename B0, <em>...,</em> typename B<em>n</em> > struct bitset<em>n</em> | |
136 | { | |
137 | typedef bitset_tag tag; | |
138 | // ... | |
139 | }; | |
140 | ||
141 | } // namespace user | |
142 | ||
143 | namespace boost { namespace mpl { | |
144 | template<> struct size_impl<user::bitset_tag> | |
145 | { | |
146 | template< typename Bitset > struct <a href="./apply.html" class="identifier">apply</a> | |
147 | { | |
148 | typedef typename Bitset::<a href="./size.html" class="identifier">size</a> type; | |
149 | }; | |
150 | }; | |
151 | }} | |
152 | </pre> | |
153 | </div> | |
154 | <div class="section" id="id845"> | |
155 | <h3><a class="subsection-title" href="#models" name="models">Models</a></h3> | |
156 | <ul class="simple"> | |
157 | <li><a class="reference internal" href="./sequence-tag.html">sequence_tag</a></li> | |
158 | </ul> | |
159 | </div> | |
160 | <div class="section" id="id846"> | |
161 | <h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3> | |
162 | <p><a class="reference internal" href="./metafunction.html">Metafunction</a>, <a class="reference internal" href="./metafunction-class.html">Metafunction Class</a>, <a class="reference internal" href="./numeric-metafunction.html">Numeric Metafunction</a></p> | |
163 | <!-- Metafunctions/Concepts//Numeric Metafunction |60 --> | |
164 | </div> | |
165 | </div> | |
166 | ||
167 | <div class="footer-separator"></div> | |
168 | <table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./placeholder-expression.html" class="navigation-link">Prev</a> <a href="./numeric-metafunction.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./placeholder-expression.html" class="navigation-link">Back</a> <a href="./numeric-metafunction.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./metafunctions-concepts.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> | |
169 | <td><div class="copyright-footer"><div class="copyright">Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams</div> | |
170 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
171 | file LICENSE_1_0.txt or copy at <a class="reference external" href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</div></td></tr></table></body> | |
172 | </html> |