Home > Backend Development > C++ > When Are Const Rvalue References Useful in C ?

When Are Const Rvalue References Useful in C ?

Patricia Arquette
Release: 2024-12-05 21:15:14
Original
173 people have browsed it

When Are Const Rvalue References Useful in C  ?

Are Rvalue References to Const Ever Useful?

In the realm of C programming, an intriguing question arises: Do rvalue references to const class types serve any purpose? While one might initially assume they are redundant, a closer examination reveals that they have occasional utility.

The draft C 0x language standard provides an example of their application. Two function templates, ref and cref, are defined as follows:

template <class T> void ref(const T&&) = delete;
template <class T> void cref(const T&&) = delete;
Copy after login

These overloads serve a critical purpose: preventing the other ref(T&) and cref(const T&) functions from being invoked with rvalues. This would be possible if the rvalue references to const were not defined.

Update:

Upon further examination of the official C standard (N3290), the same function templates appear in section 20.8 [function.objects]/p2. Additionally, the most recent post-C 11 draft (N3485) also includes these templates in the same location.

The above is the detailed content of When Are Const Rvalue References Useful in C ?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template