473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Re: CopyConstructible requirement for standard library containers

* James Kanze <james.ka...@gmail.comwrote:

Suppose I have kept the copy ctor of the element type T as 'explicit'.
Then, can I say that T is still CopyConstructible ?

Only if the implementation of the particular standard library uses
copy-initialization on some container(vector in this case) operations,
then those operations cannot be performed. Am I correct ?

Kindly clarify.

Thanks
V.Subramanian
Sep 30 '08 #1
3 1302
On Sep 30, 8:27 am, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.comwrote:
* James Kanze <james.ka...@gmail.comwrote:
Suppose I have kept the copy ctor of the element type T as 'explicit'.
Then, can I say that T is still CopyConstructible ?
Apparently, according to the text in the standard. I wouldn't
declare a copy constructor explicit, however---I'm not sure what
that means, or even what it should mean, logically.
Only if the implementation of the particular standard library
uses copy-initialization on some container(vector in this
case) operations, then those operations cannot be performed.
Am I correct ?
I'm not sure what you're trying to say, but if I understand
explicit copy constructors correctly, copy initialization isn't
allowed if the copy constructor is explicit. In practice,
however, I don't think it's an issue, since the objects are
passed by reference, and normally "copied" by using an explicit
invocation of placement new (since allocation and initialization
are separated), which is direct initialization.

(BTW: I wouldn't worry about these sort of things unless I were
actually writing a compiler. They just don't affect real code,
and there are a lot of more important issues to be concerned
with.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Sep 30 '08 #2
On 2008-09-30 05:59:23 -0400, James Kanze <ja*********@gmail.comsaid:
On Sep 30, 8:27 am, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.comwrote:
>* James Kanze <james.ka...@gmail.comwrote:
>Suppose I have kept the copy ctor of the element type T as 'explicit'.
Then, can I say that T is still CopyConstructible ?

Apparently, according to the text in the standard. I wouldn't
declare a copy constructor explicit, however---I'm not sure what
that means, or even what it should mean, logically.
One implication is this:

T t0;
T t1(t0); // OK: explicit copy construction
T t2 = t0; // error: implicit copy construction

And that's a very good reason not to do it.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Sep 30 '08 #3
On Sep 30, 12:51 pm, Pete Becker <p...@versatilecoding.comwrote:
On 2008-09-30 05:59:23 -0400, James Kanze <james.ka...@gmail.comsaid:
On Sep 30, 8:27 am, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.comwrote:
* James Kanze <james.ka...@gmail.comwrote:
Suppose I have kept the copy ctor of the element type T as
'explicit'. Then, can I say that T is still
CopyConstructible ?
Apparently, according to the text in the standard. I
wouldn't declare a copy constructor explicit, however---I'm
not sure what that means, or even what it should mean,
logically.
One implication is this:
T t0;
T t1(t0); // OK: explicit copy construction
T t2 = t0; // error: implicit copy construction
And that's a very good reason not to do it.
That's what I understand as well. But only as a result of some
discussions in the newsgroups. This means that you can't pass
objects with explicit copy constructors to functions, or return
them from functions, which (IMHO) pretty much makes copying
useless (or irrelevant)---perhaps it would make sense if you
only want to support copy so that you can implement some form of
generic clone function. But even that seems exoteric enough
that I wouldn't use it.

It also means, of course, that an implementation of the standard
library cannot pass the instantiation type by value, or return
it, since the requirements are only that the expression T(t) is
legal, and this is the case even if the copy constructor is
explicit.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 1 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sks_cpp | last post by:
Are the standard library functions pertinent to both sequence containers and associative containers? For example, if "find_if", "remove_if", etc... valid for both lists, deques, vectors, sets,...
14
by: Michael Winter | last post by:
Is the Standard Template Library capable of storing complete objects rather than pointers. For example, would either of the vectors below (a, c) function correctly (note the member in C). class...
6
by: James Egan | last post by:
I've seen some networking toolkits for C++, but was wondering if there were (or plans for) a standard set of networking classes for C++? Also, can someone tell me where I can find a...
43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
13
by: Ioannis Vranos | last post by:
So to be more excited, will it be possible to use standard library containers with handles in VC++ 2005/.NET 2.0 era? Like this: vector<Button ^>buttonArray;
9
by: Richard Brown | last post by:
Can anyone give me a good argument one way or another? I have an 'address' set of fields that are used in various situations (a client has an address, a destination has an address, etc). These...
7
by: Steven Woody | last post by:
hi, are those containers provided in std thread safe? if not, does the std ( or the language itself ) provide any method to protect critical section in a thread unsafe operation? thanks. -...
16
by: subramanian100in | last post by:
Program 1: --------------- #include <cstdlib> #include <iostream> #include <vector> using namespace std; int main() {
5
by: disappearedng | last post by:
Hi guys, I am planning to write a web crawler in standard C. I can't seem to find standard libraries provided by C that deals with networks and regular expression. Anyone here knows a good engine...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.