Comments (5)
Hi @AnthonyCalandra ,
Thank you for clarifying. My interpretation of your statement was incorrect, I thought you are referring xr2 as lvalue reference but after reading carefully, I understood.
from modern-cpp-features.
Hi @gulipalli123 , this is a common misconception; the comment is actually correct as xr2
is itself an lvalue, with type int&&
. See the following post which describes this in detail: http://thbecker.net/articles/rvalue_references/section_05.html
from modern-cpp-features.
Hi Anthony,
From Item24: Distinguish universal references from rvalue references of "Effective Modern C++" , it is clear that it is a rvalue references. Also I have tried compiling with an example, the results are as in the attachment.
from modern-cpp-features.
Kindly let me know if there is some misunderstanding from myside.
from modern-cpp-features.
Hi @gulipalli123 ,
xr2
is absolutely an rvalue reference -- there's no doubt about it, I agree. :) However, because the rvalue reference has a name (the name of the variable is xr2
), it will behave as an lvalue, which is what the comment tries to make clear. There is a distinction between what the value category the reference binds to, and what the variable's value category is itself.
To help show you the above explanation in a code example, I have a small one here I want you to try running: https://godbolt.org/z/TvWYvP3aY
Notice there are no universal references here, just an lvalue reference and an rvalue reference. What does it print and why?
from modern-cpp-features.
Related Issues (20)
- Add constinit to c++20 HOT 4
- Add C++20 semaphore HOT 1
- Add std::sample HOT 1
- fallthrough example is misleading. c++17 HOT 2
- Add CTAD for C++17 HOT 1
- Is C++20 section missing __VA_OPT language attribute for better support of variadic macros?
- std::span 2nd example does not compile HOT 2
- C++20 modules is missing HOT 1
- std::bind_front, std::bind_back, version header introduced in C++20 not mentioned
- std::erase, std::erase_if introduced in C++20 not mentioned
- std::to_address to convert a pointer to raw pointer and smart pointer default initialization in C++20 missed HOT 1
- C++20 missing std::destroying_delete_t, std::destroying_delete HOT 1
- Add Ranges to C++ 20 HOT 1
- Add CTAD for C++ 17 HOT 1
- "Class types in non-type template parameters" example doesn't compile HOT 1
- Would be nice to include the new rounding functions in chrono in C++17
- generator<T> is C++23, not C++20 HOT 1
- Regarding where C++20's likely, unlikely attribute should appear within a statement HOT 1
- C++17 __has_include HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modern-cpp-features.