Skip to content

[Question] Item 24 - Universal Reference 와 Rvalue Reference를 구별하라 #5

@JayCheck

Description

@JayCheck

Item 24의 내용 중 아래와 같은 내용이 나옵니다.

Even the simple presence of a const qualifier is enough to disqualify a reference from being universal:

template<typename T> 
void f(const T&& param);         // param is an rvalue reference

그런데 이유는 전혀 나오지 않습니다.
저자는 단지 "Universal reference(== forwarding reference) 는 반드시 type deduction 이 있으면서 "T&&" 형태가 아니면 Universal reference 가 안된다" 라고만 설명하고 있습니다.
Scott mayers 의 다른 article

StackOverflow 에서도 동일한 의문을 제기하는 글이 있습니다.
https://stackoverflow.com/questions/38814939/why-adding-const-makes-the-universal-reference-as-rvalue
답변에 따르면 먼저 표준에는 forwarding reference 의 정의 자체가 "A forwarding reference is an rvalue reference to a cv-unqualified template parameter"로 const 가 없는 Rvalue reference 형태라고 되어 있습니다. 그리고 이렇게 한 이유는 const T&& 도 universal reference 로 허용하게 되면 rvalue 만 받고자 하는 함수 overloading 을 만들 수가 없기 때문이라고 설명하고 있습니다.

The problem is that we would have no way to overload a template function who takes only rvalue reference as parameter if both T && and const T && are allowed to use as forwarding references. – Carousel

  • 추후 업데이트 필요

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions