473,804 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: rvalue references and default constructors

So my question is: will the rvalue-copy-constructor and the
rvalue-copy-operator be automaticall generated or will we have to write it
on our own?
Using gcc-4.3.0 it silenty(!) invokes the Test::operator= (Test const&
t) for

Test a;
Test b = std::move(a);
Test c = std::moved(T()) ;

- if i disable the Test::operator= (Test&& t) in source file.
(But uses Test::operator= (Test&& t) if it is availabled.)

Though using std::move() might be considered to be an explicit request
for rvalue reference argumented function.
Moreover:
One MUST use std::move(t) for explicit invocation of
Base::operator= (Base&& rhs) in Test::operator= (Test&& t)

Test &operator=(T est &&t)
{
Base::operator= (std::move(t)); // HERE
a = std::move(t);
return *this;
}

Otherwise it calls Base::operator= (Base const& rhs) silently again.

Using member functions with rvalue reference arguments seems just to
be a "fits better" for the compiler.
Member functions with rvalue reference type arguments attract for
applying actual rvalue references to some overloaded member function
set - as forced by std::move().

Worse in my view is, that inside those functions itself- which have
rvalue reference arguments - those types are treated like lvalue
references again (see the need for explicit std::move(t) in
Test::operator= (Test&& t).
I guess the reason is that it MIGHT be given some lvalue reference as
well - for invocation
(For test you can also do the other way around: provide rvalue
reference member functions and drop/disable the old "Test const& t"
images.)
So it falls back to that restriction level - unless you explicitly
recover rvalue reference conditions (using std::move() again).
This is feels like sapping type-safety.
Or let me say: if i declare a rvalue reference argument for my member
function i would like to keep treating it as rvalue reference inside
that function.

rgds!

Frank
Jun 27 '08 #1
0 1345

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

Similar topics

14
10479
by: Vinodh Kumar | last post by:
class A { int myIntVal; }; int main() { A a; return 0; }
3
6800
by: swengtoo | last post by:
In his book "More Effective C++", Scott Meyer suggests in "Item 4" to "Avoid gratuitous default constructors". To summarize his claims against default constructors for "the right classes" he states that: ================== START QUOTE ============= "A default constructor is the C++ way of saying you can get something for nothing. Constructors initialize objects, so default constructors initialize objects without any information from...
1
2290
by: Hemant Mohan | last post by:
Consider the following program snipet: <snip> typedef struct { unsigned char a ; unsigned char b ; unsigned char c ;
12
2712
by: Edward Diener | last post by:
Given value class X { public: // Not allowed: X():i(100000),s(10000) { } // Allowed void InitializeDefaults() { i = 100000; s = 10000; } private: int i;
74
16040
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the creation of this implicit default constructor, to force the creation of a struct via my constructor only? Zytan
4
3717
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and value-initialization. I think default-init calls default constructor for class objects and sets garbage values to PODs. Value-init also calls default constructor for class objects and sets 0s to POD types. This is what I've learned from the books (especially...
1
1727
by: Chris Fairles | last post by:
Take the following snip (pretend A its a std::pair if you wish ;) ) template <class T1,class T2> struct A { A(A const&){cout<<"A(const&) ";} A(A&&){cout<<"A(A&&) ";} A(T1 const&, T2 const&){cout<<"A(T1,T2) ";} template<class U1, class U2> A(A<U1,U2&&) {cout<<"A(A<U1,U2>&&) ";}
0
1102
by: Jerry Coffin | last post by:
In article <9f60e411-a5b1-4571-9d3d-005432378cd4@ 56g2000hsm.googlegroups.com>, aitorf666@gmail.com says... That's not the real reason for rvalue references. There are two primary reasons for rvalue references: providing move semantics, and providing forwarding semantics. The ability to modify the original object with impunity is the _mechanism_ behind the move semantics. Looking at this as 'mutable', however is looking at how you do...
3
1933
by: jerry.teshirogi | last post by:
I have the following class and main: ////////////////////////////////////////////////////////// #include <iostream.h> class myVector { public: double x, y, z:
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9577
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10315
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9140
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.