1 | <HTML> |
---|
2 | <!-- |
---|
3 | -- Copyright (c) Jeremy Siek 2000 |
---|
4 | -- |
---|
5 | -- Permission to use, copy, modify, distribute and sell this software |
---|
6 | -- and its documentation for any purpose is hereby granted without fee, |
---|
7 | -- provided that the above copyright notice appears in all copies and |
---|
8 | -- that both that copyright notice and this permission notice appear |
---|
9 | -- in supporting documentation. Silicon Graphics makes no |
---|
10 | -- representations about the suitability of this software for any |
---|
11 | -- purpose. It is provided "as is" without express or implied warranty. |
---|
12 | --> |
---|
13 | <Head> |
---|
14 | <Title>Copy Constructible</Title> |
---|
15 | </HEAD> |
---|
16 | <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" |
---|
17 | ALINK="#ff0000"> |
---|
18 | <IMG SRC="../../boost.png" |
---|
19 | ALT="C++ Boost" width="277" height="86"> |
---|
20 | <!--end header--> |
---|
21 | <BR Clear> |
---|
22 | <H1>Copy Constructible</H1> |
---|
23 | |
---|
24 | <h3>Description</h3> |
---|
25 | A type is Copy Constructible if it is possible to copy objects of that |
---|
26 | type. |
---|
27 | |
---|
28 | <h3>Notation</h3> |
---|
29 | <Table> |
---|
30 | <TR> |
---|
31 | <TD VAlign=top> |
---|
32 | <tt>T</tt> |
---|
33 | </TD> |
---|
34 | <TD VAlign=top> |
---|
35 | is type that is a model of Copy Constructible |
---|
36 | </TD> |
---|
37 | </TR> |
---|
38 | |
---|
39 | <TR> |
---|
40 | <TD VAlign=top> |
---|
41 | <tt>t</tt> |
---|
42 | </TD> |
---|
43 | <TD VAlign=top> |
---|
44 | is an object of type <tt>T</tt> |
---|
45 | </TD> |
---|
46 | </tr> |
---|
47 | |
---|
48 | <TR> |
---|
49 | <TD VAlign=top> |
---|
50 | <tt>u</tt> |
---|
51 | </TD> |
---|
52 | <TD VAlign=top> |
---|
53 | is an object of type <tt>const T</tt> |
---|
54 | </TD> |
---|
55 | </tr> |
---|
56 | |
---|
57 | </table> |
---|
58 | <h3>Definitions</h3> |
---|
59 | <h3>Valid expressions</h3> |
---|
60 | <Table border> |
---|
61 | <TR> |
---|
62 | <TH> |
---|
63 | Name |
---|
64 | </TH> |
---|
65 | <TH> |
---|
66 | Expression |
---|
67 | </TH> |
---|
68 | <TH> |
---|
69 | Return type |
---|
70 | </TH> |
---|
71 | <TH> |
---|
72 | Semantics |
---|
73 | </TH> |
---|
74 | </TR> |
---|
75 | <TR> |
---|
76 | <TD VAlign=top> |
---|
77 | Copy constructor |
---|
78 | </TD> |
---|
79 | <TD VAlign=top> |
---|
80 | <tt>T(t)</tt> |
---|
81 | </TD> |
---|
82 | <TD VAlign=top> |
---|
83 | <tt>T</tt> |
---|
84 | </TD> |
---|
85 | <TD VAlign=top> |
---|
86 | <tt>t</tt> is equivalent to <tt>T(t)</tt> |
---|
87 | </TD> |
---|
88 | </TR> |
---|
89 | |
---|
90 | |
---|
91 | <TR> |
---|
92 | <TD VAlign=top> |
---|
93 | Copy constructor |
---|
94 | </TD> |
---|
95 | <TD VAlign=top> |
---|
96 | <pre> |
---|
97 | T(u) |
---|
98 | </pre> |
---|
99 | </TD> |
---|
100 | <TD VAlign=top> |
---|
101 | <tt>T</tt> |
---|
102 | </TD> |
---|
103 | <TD VAlign=top> |
---|
104 | <tt>u</tt> is equivalent to <tt>T(u)</tt> |
---|
105 | </TD> |
---|
106 | </TR> |
---|
107 | |
---|
108 | |
---|
109 | <TR> |
---|
110 | <TD VAlign=top> |
---|
111 | Destructor |
---|
112 | </TD> |
---|
113 | <TD VAlign=top> |
---|
114 | <pre> |
---|
115 | t.~T() |
---|
116 | </pre> |
---|
117 | </TD> |
---|
118 | <TD VAlign=top> |
---|
119 | <tt>T</tt> |
---|
120 | </TD> |
---|
121 | <TD VAlign=top> |
---|
122 | |
---|
123 | </TD> |
---|
124 | </TR> |
---|
125 | |
---|
126 | <TR> |
---|
127 | <TD VAlign=top> |
---|
128 | Address Operator |
---|
129 | </TD> |
---|
130 | <TD VAlign=top> |
---|
131 | <pre> |
---|
132 | &t |
---|
133 | </pre> |
---|
134 | </TD> |
---|
135 | <TD VAlign=top> |
---|
136 | <tt>T*</tt> |
---|
137 | </TD> |
---|
138 | <TD VAlign=top> |
---|
139 | denotes the address of <tt>t</tt> |
---|
140 | </TD> |
---|
141 | </TR> |
---|
142 | |
---|
143 | <TR> |
---|
144 | <TD VAlign=top> |
---|
145 | Address Operator |
---|
146 | </TD> |
---|
147 | <TD VAlign=top> |
---|
148 | <pre> |
---|
149 | &u |
---|
150 | </pre> |
---|
151 | </TD> |
---|
152 | <TD VAlign=top> |
---|
153 | <tt>T*</tt> |
---|
154 | </TD> |
---|
155 | <TD VAlign=top> |
---|
156 | denotes the address of <tt>u</tt> |
---|
157 | </TD> |
---|
158 | </TR> |
---|
159 | |
---|
160 | |
---|
161 | |
---|
162 | </table> |
---|
163 | |
---|
164 | |
---|
165 | </table> |
---|
166 | <h3>Models</h3> |
---|
167 | |
---|
168 | <UL> |
---|
169 | <LI><tt>int</tt> |
---|
170 | <LI><tt>std::pair</tt> |
---|
171 | </UL> |
---|
172 | |
---|
173 | <h3>Concept Checking Class</h3> |
---|
174 | |
---|
175 | <pre> |
---|
176 | template <class T> |
---|
177 | struct CopyConstructibleConcept |
---|
178 | { |
---|
179 | void constraints() { |
---|
180 | T a(b); // require copy constructor |
---|
181 | T* ptr = &a; // require address of operator |
---|
182 | const_constraints(a); |
---|
183 | ignore_unused_variable_warning(ptr); |
---|
184 | } |
---|
185 | void const_constraints(const T& a) { |
---|
186 | T c(a); // require const copy constructor |
---|
187 | const T* ptr = &a; // require const address of operator |
---|
188 | ignore_unused_variable_warning(c); |
---|
189 | ignore_unused_variable_warning(ptr); |
---|
190 | } |
---|
191 | T b; |
---|
192 | }; |
---|
193 | </pre> |
---|
194 | |
---|
195 | <h3>See also</h3> |
---|
196 | <A |
---|
197 | href="http://www.sgi.com/tech/stl/DefaultConstructible.html">Default Constructible</A> |
---|
198 | and |
---|
199 | <A hrefa="./Assignable.html">Assignable</A> |
---|
200 | |
---|
201 | <br> |
---|
202 | <HR> |
---|
203 | <TABLE> |
---|
204 | <TR valign=top> |
---|
205 | <TD nowrap>Copyright © 2000</TD><TD> |
---|
206 | <A HREF=http://www.lsc.nd.edu/~jsiek>Jeremy Siek</A>, Univ.of Notre Dame (<A HREF="mailto:jsiek@lsc.nd.edu">jsiek@lsc.nd.edu</A>) |
---|
207 | </TD></TR></TABLE> |
---|
208 | |
---|
209 | </BODY> |
---|
210 | </HTML> |
---|