• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
3<html>
4<head>
5  <meta http-equiv="Content-Language" content="en-us">
6  <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
7
8  <title>Copy Constructible</title>
9</head>
10
11<body bgcolor="#FFFFFF" link="#0000EE" text="#000000" vlink="#551A8B" alink=
12"#FF0000">
13  <img src="../../boost.png" alt="C++ Boost" width="277" height=
14  "86"><br clear="none">
15
16  <h1>Copy Constructible</h1>
17
18  <h3>Description</h3>
19
20  <p>A type is Copy Constructible if it is possible to copy objects of that
21  type.</p>
22
23  <h3>Notation</h3>
24
25  <table summary="">
26    <tr>
27      <td valign="top"><tt>T</tt></td>
28
29      <td valign="top">is type that is a model of Copy Constructible</td>
30    </tr>
31
32    <tr>
33      <td valign="top"><tt>t</tt></td>
34
35      <td valign="top">is an object of type <tt>T</tt></td>
36    </tr>
37
38    <tr>
39      <td valign="top"><tt>u</tt></td>
40
41      <td valign="top">is an object of type <tt>const T</tt></td>
42    </tr>
43  </table>
44
45  <h3>Definitions</h3>
46
47  <h3>Valid expressions</h3>
48
49  <table border summary="">
50    <tr>
51      <th>Name</th>
52
53      <th>Expression</th>
54
55      <th>Return type</th>
56
57      <th>Semantics</th>
58    </tr>
59
60    <tr>
61      <td valign="top">Copy constructor</td>
62
63      <td valign="top"><tt>T(t)</tt></td>
64
65      <td valign="top"><tt>T</tt></td>
66
67      <td valign="top"><tt>t</tt> is equivalent to <tt>T(t)</tt></td>
68    </tr>
69
70    <tr>
71      <td valign="top">Copy constructor</td>
72
73      <td valign="top">
74        <pre>
75T(u)
76</pre>
77      </td>
78
79      <td valign="top"><tt>T</tt></td>
80
81      <td valign="top"><tt>u</tt> is equivalent to <tt>T(u)</tt></td>
82    </tr>
83
84    <tr>
85      <td valign="top">Destructor</td>
86
87      <td valign="top">
88        <pre>
89t.~T()
90</pre>
91      </td>
92
93      <td valign="top"><tt>T</tt></td>
94
95      <td valign="top">&nbsp;</td>
96    </tr>
97
98    <tr>
99      <td valign="top">Address Operator</td>
100
101      <td valign="top">
102        <pre>
103&amp;t
104</pre>
105      </td>
106
107      <td valign="top"><tt>T*</tt></td>
108
109      <td valign="top">denotes the address of <tt>t</tt></td>
110    </tr>
111
112    <tr>
113      <td valign="top">Address Operator</td>
114
115      <td valign="top">
116        <pre>
117&amp;u
118</pre>
119      </td>
120
121      <td valign="top"><tt>T*</tt></td>
122
123      <td valign="top">denotes the address of <tt>u</tt></td>
124    </tr>
125  </table>
126
127  <h3>Models</h3>
128
129  <ul>
130    <li><tt>int</tt></li>
131
132    <li><tt>std::pair</tt></li>
133  </ul>
134
135  <h3>Concept Checking Class</h3>
136  <pre>
137  template &lt;class T&gt;
138  struct CopyConstructibleConcept
139  {
140    void constraints() {
141      T a(b);            // require copy constructor
142      T* ptr = &amp;a;       // require address of operator
143      const_constraints(a);
144      ignore_unused_variable_warning(ptr);
145    }
146    void const_constraints(const T&amp; a) {
147      T c(a);            // require const copy constructor
148      const T* ptr = &amp;a; // require const address of operator
149      ignore_unused_variable_warning(c);
150      ignore_unused_variable_warning(ptr);
151    }
152    T b;
153  };
154</pre>
155
156  <h3>See also</h3>
157
158  <p><a href="http://www.sgi.com/tech/stl/DefaultConstructible.html">Default
159  Constructible</a> and <a href="./Assignable.html">Assignable</a><br></p>
160  <hr>
161
162  <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
163  "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
164  height="31" width="88"></a></p>
165
166  <p>Revised
167  <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->05
168  December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38516" --></p>
169
170  <table summary="">
171    <tr valign="top">
172      <td nowrap><i>Copyright &copy; 2000</i></td>
173
174      <td><i><a href="http://www.lsc.nd.edu/~jsiek">Jeremy Siek</a>, Univ.of
175      Notre Dame (<a href=
176      "mailto:jsiek@lsc.nd.edu">jsiek@lsc.nd.edu</a>)</i></td>
177    </tr>
178  </table>
179
180  <p><i>Distributed under the Boost Software License, Version 1.0. (See
181  accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
182  copy at <a href=
183  "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
184</body>
185</html>
186