It is currently Sat Aug 22, 2020 1:34 pm


All times are UTC




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2, 3

What compilers and versions do you use?
VS2005 (VC++8.0) 4%  4%  [ 1 ]
VS2008 (VC++9.0) 8%  8%  [ 2 ]
VS2010 (VC++10.0) 27%  27%  [ 7 ]
VS2011 (VC++11.0) 4%  4%  [ 1 ]
GCC 4.4 4%  4%  [ 1 ]
GCC 4.5 8%  8%  [ 2 ]
GCC 4.6 35%  35%  [ 9 ]
Clang 2.9 0%  0%  [ 0 ]
Clang 3.0 0%  0%  [ 0 ]
Clang 3.1 12%  12%  [ 3 ]
Total votes : 26
Author Message
 Post subject: Re: C++11 features discussion (and compiler poll)
PostPosted: Fri Nov 02, 2012 9:53 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
For C++03:

Doing a real (deep) copy of a volume is indeed a valid use case, but it's quite uncommon. I don't think we should expose a copy constructor which does this, as the user should instead be forced to use a more explicit method (like the VolumeResampler) which makes it clear that something expensive is happening.

Doing a pointer copy (a shallow copy) results in a messy situation where it's not clear which volume really owns the data, and where modifying one volume results in the other changing. This appears to be the current situation due to the compiler provided copy constructor, but I guess no one is actually calling this so it hasn't ben a problem.

For normal C++ I therefore think the copy constructor should be defined to prevent the compiler creating one, but made protected to prevent the user from calling it. I guess the same would be true of the assignment operator? Does this have any negative implications?

For C++11:

I'm not familier enough with move semantics and rvalue references to know whether a move constructor would still be appropriate or beneficial after the above changes had been made... so I'll leave that discussion to those who have more idea. If it's a good idea then we can include one.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: C++11 features discussion (and compiler poll)
PostPosted: Fri Nov 02, 2012 11:14 am 
Developer
User avatar

Joined: Sun May 11, 2008 4:29 pm
Posts: 198
Location: UK
David Williams wrote:
For normal C++ I therefore think the copy constructor should be defined to prevent the compiler creating one, but made protected to prevent the user from calling it. I guess the same would be true of the assignment operator? Does this have any negative implications?

I believe this is the standard way of making a class non-copyable (like is done in boost::noncopyable) and so I think it would be appropriate here. If we make this change (I guess we could make it before the 0.2 release) we should be sure to add a little documentation showing how to manually copy a volume using the sampler (or perhaps add an explicit clone() method to the class).

David Williams wrote:
For C++11:

I'm not familier enough with move semantics and rvalue references to know whether a move constructor would still be appropriate or beneficial after the above changes had been made... so I'll leave that discussion to those who have more idea. If it's a good idea then we can include one.

I think that a move constructor would be very useful as it would allow the user to do things like pass it to functions or store it in standard library containers (as long as they explicitly move it there).

While it has been suggested (by Scott Meyers no less) that move constructors should just be seen as an optimisation on top of copy constructors, I think that in this case we're using the different semantics of the two to help define our API and recommended usage.

_________________
Matt Williams
Linux/CMake guy


Top
Offline Profile  
Reply with quote  
 Post subject: Re: C++11 features discussion (and compiler poll)
PostPosted: Fri Nov 02, 2012 1:52 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
milliams wrote:
[I believe this is the standard way of making a class non-copyable (like is done in boost::noncopyable) and so I think it would be appropriate here. If we make this change (I guess we could make it before the 0.2 release) we should be sure to add a little documentation showing how to manually copy a volume using the sampler (or perhaps add an explicit clone() method to the class).


Ok, I've added asserting and protected copy constructors and assignment operators to the volume classes. We should indeed have a TestVolumeResampler but I'll get around to that in the future.

milliams wrote:
I think that a move constructor would be very useful as it would allow the user to do things like pass it to functions or store it in standard library containers (as long as they explicitly move it there).


I'll leave that part to you :-)


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2, 3

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net