ref-qualifier Questions

1

Solved

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

The following code causes undefined behaviour: class T { public: const std::string& get() const { return s_; } private: std::string s_ { "test" }; } void breaking() { const auto&...
Feudist asked 23/8, 2021 at 11:54

1

Is there a reason (other than because the standard says so) to why the following code is not allowed? struct Foo { ~Foo() && {} ~Foo() & {} }; I know that it is illegal, but I wann...
Eulogistic asked 28/2, 2020 at 8:28

1

Solved

I have watched a talk (exact timestamp, not explained by him) by Nicolai Josuttis (member of C++ standard committee) and he stated that ever since C++11, getters should be written like so: const st...
Exacting asked 22/2, 2019 at 6:46

2

Could anyone explain why compilers (g++, visual c++) fail to deduce the template argument in this case? struct MyClass { void Foo(int x)& {} void Foo(int x)&& {} }; template<type...
Storekeeper asked 5/1, 2017 at 18:25

1

Solved

Why element access member functions of STL containers, e.g. std::array::operator[] or std::vector::operator[] do not have rvalue ref-qualifier overloads? Of course I can do std::move(generate_vecto...
Gaiety asked 22/2, 2018 at 9:31

3

Solved

In the following C++11+ code which return statement construction should be preferred? #include <utility> struct Bar { }; struct Foo { Bar bar; Bar get() && { return std::move...
Arbela asked 28/1, 2018 at 11:35

2

Solved

I can't remember which talk it was, but recently I watched some talks from CppCon 2017 and there someone mentioned as some kind of side-note, that the only true way of overloading operator= would b...
Kendre asked 29/10, 2017 at 16:53

1

If there are no another overloadings (say, f(T &) or f(volatile T &&)) of a (member) function template template< typename T > f(T &&);, then T && is so-called forw...
Southeasterly asked 30/9, 2015 at 6:39

1

Solved

It just occurred to me that operator+ & co can operate on this for rvalues; i.e. given a class C, it's possible to do this: class C { // ... C operator-( const C& rhs ) const & { C ...
Britten asked 3/9, 2015 at 17:2

2

Solved

Recently I learned about function's reference qualifiers, e.g. struct foo { void bar() {} void bar1() & {} void bar2() && {} }; Where I might need this feature, is there any real ...
Catherinacatherine asked 19/1, 2015 at 14:1

1

Solved

Given the following conversion operators struct A { template<typename T> explicit operator T&& () &&; template<typename T> explicit operator T& () &; templat...
Saundrasaunter asked 30/4, 2014 at 0:29

1

Solved

I found a strange behaviour, when compliling my code with G++ (gcc 4.8.1 and MinGW 4.8.2 with -std=gnu++1y flag). In spirit of SSCCE I isolating the following snippet: struct C { template< ty...

1

Solved

While reading http://en.cppreference.com/w/cpp/language/member_functions, I came across something, I haven't seen before: lvalue/rvalue Ref-qualified member functions. What would be their pur...
Coastward asked 20/10, 2013 at 5:54

1

Solved

This compiles fine in clang 3.3: template <typename T> struct M; template <typename R, typename C, typename... A> struct M <R (C::*)(A...)> { }; template <typename R, typena...
Magnificat asked 11/9, 2013 at 16:11

1

Solved

While working with ref-qualified function overloads, I'm getting different results from GCC (4.8.1) and Clang (2.9 and trunk). Consider the following code: #include <iostream> #include <u...

3

Solved

Came across a proposal called "rvalue reference for *this" in clang's C++11 status page. I've read quite a bit about rvalue references and understood them, but I don't think I know about this. I a...
Associative asked 22/12, 2011 at 22:47
1

© 2022 - 2024 — McMap. All rights reserved.