54 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
2
votes
1
answer
141
views
Must T be unqualified in std::allocator<T>?
gcc, clang, and msvc all reject the following code:
#include <memory>
#include <vector>
int main() {
auto _ = std::vector<int const>{}; // error
auto _ = std::vector<...
1
vote
1
answer
128
views
How to replace ref-qualifiers of member functions with concept?
Is it possible to replace following ref-qualifiers with concepts?
That is, instead of
struct S
{
void func() && {}
void func() & {}
};
have something like this
struct S
{
void ...
0
votes
1
answer
89
views
Is GCC correct in rejecting overload between ref-qualified and non-ref-qualified member function? [duplicate]
If I understand this correctly, [over.load] doesn't exist in c++23, and so what I read in [over.load]/2.3 should not be true anymore, so this code
struct Foo {
int const& bar() const;
int bar()...
3
votes
1
answer
275
views
Overloading ref-qualified member-function without ref-qualifier
Is the non ref-qualified overload of member-function f in accordance with the C++20 standard? Both Clang and GCC seem to accept it. Are they both pulling on the short end of the stick? What does the C+...
4
votes
1
answer
1k
views
When are ref-qualified member functions necessary
As I understand it, ref-qualified member-functions are used to distinguish between operating on an implicit this as an lvalue versus an rvalue. If we define a member function without the ref-...
2
votes
1
answer
110
views
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&& ...
3
votes
1
answer
291
views
Generating the necessary ref-qualified overloads for a member function
I have this class:
template<typename T, size_t N>
class Array {
private:
T array[N];
public:
template <typename... InitValues>
constexpr Array(InitValues......
0
votes
1
answer
159
views
Simplifying the use of ref qualifiers in c++20
#include <string>
struct S
{
std::string s_;
std::string_view get() const &
{
return s_;
}
std::string_view get() const && = delete;
};
// I can't ...
1
vote
1
answer
527
views
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<int>;
struct A ...
2
votes
0
answers
123
views
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?
3
votes
0
answers
154
views
C++ user-defined conversions, ref-qualifiers and overload resolution
Please, help me understand what's wrong with this piece of code:
#include <string>
#include <utility>
class Sample
{
public:
explicit Sample(std::string data):
_data(std::move(...
0
votes
2
answers
93
views
Is there a use-case for std::string's operator= to not be lvalue ref-qualified?
The post here points out that std::string's member operator= is not lvalue ref-qualified. That allows us to write code such as this:
std::string() = "Hello";
The linked post asks why this ...
7
votes
1
answer
240
views
Overloading a parent member function without ref-qualifier with a child member function with ref-qualifier in C++
In C++ one cannot overload in one class a member function with ref-qualifier with a member function without ref-qualifier. But at the same time it is possible to inherit one member function from a ...
1
vote
1
answer
142
views
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 <cstdio>
...
8
votes
1
answer
422
views
Best practice for getters with ref-qualifier
The following code causes undefined behaviour:
class T
{
public:
const std::string& get() const { return s_; }
private:
std::string s_ { "test" };
}
void breaking()
{
const ...