Git Product home page Git Product logo

Comments (5)

gulipalli123 avatar gulipalli123 commented on May 21, 2024 1

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.

AnthonyCalandra avatar AnthonyCalandra commented on May 21, 2024

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.

gulipalli123 avatar gulipalli123 commented on May 21, 2024

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.

Screenshot from 2022-03-12 08-49-46
.

from modern-cpp-features.

gulipalli123 avatar gulipalli123 commented on May 21, 2024

Kindly let me know if there is some misunderstanding from myside.

from modern-cpp-features.

AnthonyCalandra avatar AnthonyCalandra commented on May 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.