A way to specify the value category of the *this pointer in a member function.
Questions tagged [ref-qualifier]
47 questions
3
votes
6 answers
How to improve the efficiency of "str1 + str2 + str3 + ..." in C++14?
std::string Concatenate(const std::string& s1,
const std::string& s2,
const std::string& s3,
const std::string& s4,
const std::string& s5)
{
return…

xmllmx
- 39,765
- 26
- 162
- 323
2
votes
1 answer
What's the point of ref-qualified member functions in `std::optional::value`
These are the signatures, according to Cppreference:
constexpr T& value() &;
constexpr const T& value() const &;
constexpr T&& value() &&;
constexpr const T&& value() const &&;
What's the point of using &/const& and &&/const&&?
Especially, I don't…

BIuesky
- 97
- 5
2
votes
0 answers
Why `std::vector::reserve` is not l-value ref-qualified?
Are there any use cases for std::vector::reserve() on an r-value std::vector, or is reserve() not l-value ref-qualified only because of backward compatibility?

blonded04
- 147
- 9
2
votes
1 answer
Non-static member functions with no ref-qualifier
This is a follow-up to my previous post
With reference to Non-static member functions
Under
const-, volatile-, and ref-qualified member functions
A non-static member function can be declared with no ref-qualifier,...
During overload resolution,…

Vinod
- 925
- 8
- 9
1
vote
1 answer
Conversion operator with ref-qualifers: rvalue ref and const lvalue ref overloads ambiguity
While answering another question, I noticed something peculiar about conversion operators when dealing with ref-qualifiers.
Consider the following code:
using P = std::unique_ptr;
struct A {
P p;
operator P() && { return std::move(p);…

Nelfeal
- 12,593
- 1
- 20
- 39
1
vote
1 answer
Why do ref-qualifier together with cv-qualifier on operator overloading allow rvalue assignment?
Adding a ref-qualifier to an operator will remove the possibility to do rvalue assignment
for example, compiling the following with g++ -std=c++14 bar.cpp && ./a.out
#include
struct foo
{
void operator+=(int x) & { printf("%d\n", x+2);…

mattsson
- 1,132
- 12
- 18
1
vote
1 answer
Wording of GCC's error message when calling lvalue-ref qualified member function on temporary object
The following code does not compile, expectedly:
struct A {
void doWork() & {}
};
int main() {
A{}.doWork();
}
My understanding is that the temporary A{} cannot bind to the &-qualified member function doWork, and this seems in line with…

Enlico
- 23,259
- 6
- 48
- 102
1
vote
0 answers
Bug in gcc-9 with implicit conversion via ref-qualified type-operators?
Consider this:
struct Man
{
operator int const& () const& { return m_ban ; }
operator int && () && { return std::move(m_ban); }
int m_ban;
};
void ff(int const& ) { std::cerr << "==== void ff(int const& )" << std::endl;…

Vahagn
- 4,670
- 9
- 43
- 72
1
vote
1 answer
c++ - const member func, that can be called upon lvalue instances only, using a ref-qualifier
I'm trying to enforce a const 'getter' method of a class to be called upon only lvalue instances of the class, via a ref-qualifier and for some reason getting an unexpected result (I'm compiling with clang 6.0.1 with C++ 17 support, via c++1z flag,…

golosovsky
- 638
- 1
- 6
- 19
1
vote
0 answers
Conditional ref qualifier
I have CRTP-like hierarchy where derived classes may be implemented a bit differently and for one class some methods are allowed to call on rvalue references but for another class this would be undesired:
template
struct Base {
…

eXXXXXXXXXXX2
- 1,540
- 1
- 18
- 32
1
vote
0 answers
Reference as last symbol in C++ function declaration?
Looking at Boost::Optional optional class template header I come across this:
T const& operator*() const&
T& operator*() &;
T&& operator*() &&;
For the life of me I can't find this syntax anywhere else (a reference as the last symbol) I…

A-n-t-h-o-n-y
- 410
- 6
- 14
1
vote
1 answer
Difference between l-value ref-qualified member function and unqualified member function?
Is there a difference between l-value ref-qualified member functions and unqualified member functions? If so, what is it?
I.e., are these two ways of declaring func() different?
class Foo
{
void func();
void func() &;
};
I don't mean "are they…

Kyle Strand
- 15,941
- 8
- 72
- 167
1
vote
0 answers
Can I make reference easily for more resources?
I am developping a game. I would like a picture to be shown on the screen. It should fill the screen's 90% in width (about 90%). I don't want the system to resize my images (I don't like the quality it results)
I would like to put the pictures…

Tomi
- 3,370
- 1
- 16
- 26
1
vote
1 answer
Can I make reference for whole resource folder?
I would like to support many different screen types with the drawable resources.
But I can use some drawables with the same size on more screens.
For example: -xxhdpi-normal and -mdpi-xlarge could use the same sized drawable image
I don't wan't to…

Tomi
- 3,370
- 1
- 16
- 26
0
votes
1 answer
Simplifying the use of ref qualifiers in c++20
#include
struct S
{
std::string s_;
std::string_view get() const &
{
return s_;
}
std::string_view get() const && = delete;
};
// I can't change this
struct T
{
T(std::string_view const sv); // does…

zrb
- 851
- 7
- 16