What is use of the ref-qualifier `const &&`?

后端 未结 4 609
予麋鹿
予麋鹿 2020-12-13 19:06

I\'ve been digging around ref-qualifiers a bit, following on a previous question.

Given the code sample below;

#include 
#include <         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 19:28

    We can find a similar exploration of this issue in the article What are const rvalue references good for? and the one use that stood out is this example form the standard library:

    template  void ref (const T&&) = delete;
    template  void cref (const T&&) = delete;
    

    which disables ref and cref for rvalues altogether. We can find these declarations in the draft C++11 standard section 20.8 Function objects paragraph 2.

    Scott Meyers alludes to this use in Universal References in C++11:

    Even the simple addition of a const qualifier is enough to disable the interpretation of “&&” as a universal reference:

提交回复
热议问题