822. Object with explicit copy constructor no longer CopyConstructible

Hi All,

 From the latest Standard Library active issues list:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2806.html

"
I just noticed that the following program is legal in C++03, but is
forbidden in the current draft:

     #include <vector>
     #include <iostream>

     class Toto
     {
     public:
         Toto() {}
         explicit Toto( Toto const& ) {}
     } ;

     int
     main()
     {
         std::vector< Toto > v( 10 ) ;
         return 0 ;
     }

Is this change intentional? (And if so, what is the justification? I
wouldn't call such code good, but I don't see any reason to break it
unless we get something else in return.)
"

1.  I don't understand why the program is now illegal.  std::vector
still offers a single int constructor that only requires its type to be
default constructable.  Does the explicit copy constructor make the
default constructor not visible?  Is this a language change or a library
change -- if the former, why is this issue in the Library Issues?

2.  Why is the code bad?  Is it because of the explicit copy
constructor?  Could that be a funny way of suppressing assignment form
initializers?  Or is it a no-op?


Geno Rice

-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Eugene
12/12/2008 6:55:12 PM
comp.lang.c++.moderated 10707 articles. 11 followers. allnor (8507) is leader. Post Follow

1 Replies
210 Views

Similar Articles

[PageSpeed] 48
On 13 Dez., 01:55, Eugene Rice <g...@verizon.net> wrote:
>  From the latest Standard Library active issues list:
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2806.html
>
> "
> I just noticed that the following program is legal in C++03, but is
> forbidden in the current draft:
>
>      #include <vector>
>      #include <iostream>
>
>      class Toto
>      {
>      public:
>          Toto() {}
>          explicit Toto( Toto const& ) {}
>      } ;
>
>      int
>      main()
>      {
>          std::vector< Toto > v( 10 ) ;
>          return 0 ;
>      }
>
> Is this change intentional? (And if so, what is the justification? I
> wouldn't call such code good, but I don't see any reason to break it
> unless we get something else in return.)
> "
>
> 1.  I don't understand why the program is now illegal.  std::vector
> still offers a single int constructor that only requires its type to be
> default constructable.  Does the explicit copy constructor make the
> default constructor not visible?  Is this a language change or a library
> change -- if the former, why is this issue in the Library Issues?

The reason, why it is now excluded, is, because the definition of
the requirement CopyConstructible has changed. This happened with
the introduction of the new requirement MoveConstructible as of

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2284.pdf

Interestingly previous papers correctly took into account possibly
explicit c'tors, just compare with

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1771.html

IMO the current concepts related to "constructor" concepts
have the problem, that starting from the most fundamental
constructor-related concept is non-explicit, see 20.2.6 in
N2798:

auto concept HasConstructor<typename T, typename... Args> {
   T::T(Args...);
}

This is a basic weakness, because this would not make
it possible to express any explicit constructor by the
concepts std::HasConstructor, std::Constructible,
std::MoveConstructible, or std::CopyConstructible.
It also makes it impossible to let existing concepts
like std::ArithmeticLike fulfill std::HasConstructor,
which itself requires (at least) explicit c'tors:

explicit T::T(intmax_t);
explicit T::T(uintmax_t);
explicit T::T(long double);

This becomes obvious, if you compare this situation
with the example shown in [concept.map.fct]/4,
bullet 12:

concept IC<typename T> {
   T::T(int);
}
concept EC<typename T> {
   explicit T::T(int);
}
struct X {
   X(int);
};
struct Y {
   explicit Y(int);
};
concept_map IC<X> { } // OK
concept_map EC<X> { } // OK
concept_map IC<Y> { } // error: cannot copy-initialize Y from an int
concept_map EC<Y> { } // OK

So, the current draft definitively has to fix the
current hierarchy of library concepts described
in [utility.concepts].

> 2.  Why is the code bad?  Is it because of the explicit copy
> constructor?  Could that be a funny way of suppressing assignment form
> initializers?  Or is it a no-op?

Explicit copy constructors have some funny and sometimes
astonishing properties, e.g. the fact, that you cannot
invoke a function taking a type with such copy constructor
by value:

struct S {
   S(){}
   explicit S (S const&){}
} s;

void f(S){}

void g() {
     f(s); // Error
}

This constraint makes using such types with most
libraries (including the standard library) a pain.
If you would e.g. provide a functor or an iterator
with explicit copy constructor, it could never be
used with the manifold of algorithms provided by
[algorithms], because these basically always take
the arguments by value. Such functions have many
advantages and if you want to define a constexpr
function (a new feature for C++0x) you are required
to take arguments by value there.

HTH & Greetings from Bremen,

Daniel Kr�gler


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
daniel
12/13/2008 4:16:22 PM
Reply:
Similar Artilces:

Copy the depth buffer
Hi all! I want to copy the depth buffer to an other float texture. Is this with glReadBuffer (parameter: GL_DEPTH?) and glCopyTexSubImage2D possible or is there an other fast way to do this? Thank you! Greetings Mario Mario <www.derfordfahrer@gmx.net> writes: > Hi all! > > I want to copy the depth buffer to an other float texture. Is this > with glReadBuffer (parameter: GL_DEPTH?) and glCopyTexSubImage2D > possible or is there an other fast way to do this? glReadBuffer doesn't actually read the buffer, it just specifies which one you want to read from. Usually...

Object composition in PHP
I'm very new to PHP and to programming in general and have a simple question about oject composition in PHP. Here's a couple of simple classes that I have created. The Greeting class 'has-a' Message object as one of its members. The Message class seems to work fine, and the Greeting class lets me create a Greeting object fine. However, I get an error when trying to access the getMessage() function of the Message class from within the Greeting class. All the code is below. Anyone have any idea what the problem is? class Message { protected $message; public function __const...

fmincon derivative objective function
hi everyone; In fmincon: I search the function whose calculate the drift of objective function, and I want to replace this function by my derivative objective function to winer time. thinx On 6/20/2011 10:38 AM, Mouloud wrote: > hi everyone; > > In fmincon: I search the function whose calculate the drift of objective > function, and I want to replace this function by my derivative objective > function to winer time. > > thinx I don't know what you are talking about. Please rephrase your question. Perhaps this documentation section will help: http://www.mathworks....

Passing data between objects and calling all objects of a class in turn
I'm a fairly new Python coder, learning along with my son (actually, hopefully a bit ahead of him...). We're stuck on something. As part of solving a backwards induction problem (purely as a learning experience, we are geeks), we are going to create N objects, each of the class "interview". We will first create the N_th interview, which will calculate, based on data we pass to it, its expected payoff value. We will then create interview N-1, which needs to know the expected payoff of interview N in order to determine a decision and then calculate its own expected ...

[info objects] trouble
I'm having trouble to use the itcl-extended info commands. See below, what is wrong? -Sacha % info patchlevel 8.4.8 (bin) 2 % package require Itcl 3.3 (bin) 3 % namespace import itcl::* (bin) 4 % info objects bad option "objects": must be args, body, cmdcount, commands, complete, default, exists, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, patchlevel, procs, script, sharedlibextension, tclversion, or vars Sacha Sch=E4r wrote: > I'm having trouble to use the itcl-extended info commands. > See below, what is wrong? > > -Sa...

retrieving an object from an array
Hi there, I have an array of objects, and I would like to retreive one of the objects based on a given key and value (ie. name='john'). Is this possible and if so what is the syntax? thanks Stuart "stuart" <stuart_n@webobjectives.com.au> wrote in message news:stuart_n-567E59.23521506012004@news-vip.optusnet.com.au... > Hi there, > I have an array of objects, and I would like to retreive one of the > objects based on a given key and value (ie. name='john'). Is this > possible and if so what is the syntax? > > thanks > Stuart yes an...

Q: PhotoPaint 8, rotate an object
Hi, Although this has to do with an older version of PhotoPaint, I hope someone can answer my question. As I recall it was possible earlier when I used the program to rotate an object (click twice on it, grab the handles, etc.), but now all I get is: "Condition #1000-MSEL-1228 Problem accessing memory." Not a crash with freezes and what have you, it's more like an inconvenience since I can't rotate an object. I believe it's the same number I get on that dialog box all the time. Sadly, the dialog doesn't say with many words what the problem is....

can I turn base object into inherited one?
I have 2 classes, class base { public: some virtual functions } class derived : public base { public: derived(base* b); } is there a simpler way to turn a base object into derived than the following base* b = new base(); b->do some stuff now he becomes derived base* d = new derived(b); thx alexl wrote: > I have 2 classes, > > class base { > public: > some virtual functions > > } > > class derived : public base { > public: > derived(base* b); > > } > > is there a simpler way to turn a base object into derived than the > followi...

Equations for Circular Object collisions-
I am trying to simulate the multiple collisons that take place in the game of curling ( a Canadian game ) which has similar collisions to pool table ball to ball collisions. or shuffleboard. The collisions are actually closer to shuffleboard since there is some interaction between the circular object sliding on a surface like in Shuffleboard. I was hoping that someone from this newsgroup could point me in the right direction to get started on .circular collision equations. I need a) equations for - simple circular collisions - more complex rotation coll...

how to create an array of objects initializing each object?
hi, how to create an array of objects initializing each object? thanks in advance On 7/15/2011 8:12 AM, vaysagekv wrote: > how to create an array of objects initializing each object? You can initialize them if you provide a brace-enclosed initialiser list for the array. You can't do it with a dynamic array, however. V -- I do not respond to top-posted replies, please don't ask On Jul 15, 1:21=A0pm, Victor Bazarov <v.baza...@comcast.invalid> wrote: > On 7/15/2011 8:12 AM, vaysagekv wrote: > > > how to create an array of objects initializing each object? ...

Make file with objects in one directory
Hi, I am new to unix make and so, this question may sound little silly. But please help. I need to compile a list of .c and .cpp source files that are in a big directory structure. Ex: /code_root /design/tools/test1.c /design/tools/test2.c /design/src/tcpstack.cpp /design/src/tcpsrlze.c /design/src/util/charconv.cpp /arch/src/frmwrk/frmroot.cpp like wise there are about 700 files in the directory structure. I need to write a unix make file that can compile all these files and then create the objects in one directory namely /code_root/obj Can some please help on how to write? I hav...

static Collection of objects
Hello, what is the best solution to hold the collection of Objects. Lets say I have such class: class Task{ private: CString title; CString description; CString owner; CString date; CString state; public: /* some public methods */ Task(); ~Task(); }; This class is used only to hold the data and perform no business logic. And I have another class, where I want to hold public _static_ variable of Tasks' collection. It's public and static because I use this class as mediator in my application. So what collection "manager" should I use (vector, CObjList, ...)? And c...

Extracting Object Model from an existing VisualAge Smalltalk Application?
Hi I am using VisualAge Smalltalk 6.0. Could you please suggest your views for extracting Object Model from an existing VisualAge Smalltalk Application into a tool like Rational Rose or Together ?. Are there free connecting tools exist for accomplishing the same ? Your help is appreciated in advance. Thanks Darbin ...

Many objects slow down Max
Hi! I am currently working on a scene with approx. 1,000 separate simple animated objects. MAX should be able to handle the number of vertices easily, but it seems to have problems with the large number of separate objects (the "Preparing Objects" phase is very long). Attaching them all to a single object is no solution as they lose their animation keys in the process. Thank you for your ideas :-) Best regards, Andreas On 14 May 2005 15:36:00 -0700, hufflehuffle@west.de wrote: >I am currently working on a scene with approx. 1,000 separate simple >anima...

Browser Object
Hi, i hope u can help me. i need to indicate with javascript or php, which objects in the browser "IE, Mozilla etc" are deactivate. example: Popups Blocked, please activate the popups! the object what i need to indicate if they are deactivate are: Session Cache, Browser Name, Full Version, Cookies Enabled, Popups Blocked, Image Enabled, PNG Supported, Frames Supported, Iframes Supported, Adobe Acrobat Installed, Adobe Acrobat Version, Proxy Used, JavaScript Supported, JavaScript Enabled, JavaScript Version, JavaScript Build, Browser Date Time, thanks for ur support :) best wishes, ...

Iseries Navigator/Do Not See SAVF objects
I tried to find SAVF objects using ISERIES Navigator, anyone know of a way to see these. I tried the drill down via File Systems, I am thinking the only way would be via copying it to the IFS. I was hoping for a DSPOBJD equivalent with Navigator. ...

Object Rexx and Access
Where can I find an example of using Object Rexx to read data from an MSAccess data base? Simply, grab RexxSQL ODBC edition and away you go. Additionally you can use the ORexxSQL class library to wrap the DLL calls into nice neat objects. There is one bug fix proposed to the class library in the bug track for RexxSQL but since it is not Mark's code you must apply the patch yourself. This interface works very well! -- Michael Lueck Lueck Data Systems Remove the upper case letters NOSPAM to contact me directly. On Wed, 01 Dec 2004 01:22:25 GMT, "jerry chapman" <jerryc31...

RFC 822 continuations
Hello, http://docs.python.org/lib/module-ConfigParser.html writes: "with continuations in the style of RFC 822; " what is meant with these continuations? Thanks, Florian Florian Lindner wrote: > Hello, > http://docs.python.org/lib/module-ConfigParser.html writes: > > "with continuations in the style of RFC 822; " > > what is meant with these continuations? > > Thanks, > > Florian From ConfigParser source code: Continuations are represented by an embedded newline then leading whitespace. -Larry Bates Larry Bates wrote: > Florian ...

FAQ: comp.lang.objective-c: pointer (Dec 07)
Welcome to comp.lang.objective-c Objective-C programming language and runtime environment This is a weekly pointer to the Objective-C FAQ (frequently asked questions) Plain Text Version : ftp://rtfm.mit.edu/pub/faqs/computer-lang/Objective-C/faq ...

Persistent Objects and ObjectLists
Hi In many examples illustrating OO principles/ideas etc I have seen the Model part of the illustration implemented as a List or "ObjectList" e.g. EmployeeList containing a list of Employees. So creating an Employee would have the EmployeeListEditor create a new Employee and pass it to the add() method on the EmployeeList. I have also seen these examples persist the EmployeeList when they show how to use Persistence. Now I realise that these are simple examples used to illustrate the point in hand (and they do this extremely well) but it leaves me a bit confused about the use of ...

Composability and concurrecy and Object oriented programming
Hello, I have come to an interresting subject... I have offen read some comments about parallel programming and Object oriented programming and Functional programming, and i will bring my comments about them... You will read about parallel programming that it's hard/difficult , cause parallel programming adds more layers to serial programming, in those added layers in parallel programming we have to think not only about serial programming algorithmic and such... but we have also to think about parallel correctness and parallel performance... and i have heared comments tha...

last object of array
Hello, I have a script that is echo'ing the values of a mysql query using a while. What I need to do is right before the last value is echo'd I need to write "last item". Is there a way to do this: figure out how many array values there are then out put all but the last one, then write some text, then write the last value of the array. Thanks in advance. Adam Carolla wrote: > Hello, > > I have a script that is echo'ing the values of a mysql query using a > while. What I need to do is right before the last value is echo'd I > need to write "la...

Change Objects Color in RGB Image
I'm currently working on an image processing project where I need to change an objects color to another color while preserving the light to dark shade. I need to extract 3 of 5 red images and change them to blue. The objects are 3 red ties men are wearing in the image. I have experience with the image processing toolbox but more for black and white images. Any help with the functions I should look into would be great. thanks joe Joe Krystofik wrote: > > > I'm currently working on an image processing project where I need > to > change an objects color to another color ...

object.property syntax
Could someone send me a link to the object.property syntax in the help files? I can only find one reference to it in the help files and it does not discuss its useage or limitations. Thanks ...

Objection!
I am doing everything and getting paid nothing. I have almost no friends l= eft. No one will talk to me or spend time with me. I talk to myself all d= ay. Obama doesn't care, the FBI doesn't care, the NSA doesn't care, no one= cares. I am not your slave. I do not know why I am treated this way by p= eople. I see that I have secret service protection. I also see that no on= e will hire me. I also see that aside from ONE of my neighbors and my mom,= no one tries to talk to me. This isn't fair. I am not your slave. I can= not be forced to keep doing this forev...