Skip to main content
2 votes
2 answers
159 views

How does the concept of trivial relocatability from C++26 change how we reason about value categories? Do they interact at all (e.g., temporary-materialization rules)? For instance, if I have a ...
vinipsmaker's user avatar
  • 2,262
Best practices
1 vote
17 replies
6k views

NRVO/RVO rules allow/require copy elision if a (non-conditional) return value is constructed by the called function - it is to be constructed on the caller's stack frame return value location (though ...
ags's user avatar
  • 729
Advice
0 votes
7 replies
134 views

C++11 value categories (lvalues, xvalues, and prvalues) are deeply entangled to the core of C++ itself in a way that's not possible to reason about C++ w/o reasoning about value semantics. C++17 ...
vinipsmaker's user avatar
  • 2,262
5 votes
0 answers
177 views

According to this article by Raymond Chen, ternary expression is not a copy elision candidate. The problem with the ternary is that the ternary expression is not a copy elision candidate. The rule ...
許恩嘉's user avatar
  • 1,321
7 votes
1 answer
339 views

Look at this program (godbolt): #include <cstdio> struct Foo { ~Foo() { printf("~Foo\n"); } }; void foo(Foo) { } int main() { foo(Foo()); } Based on my previous ...
geza's user avatar
  • 30.5k
3 votes
2 answers
59 views

I'd like to understand copy elision rules (if these are the one that apply) in a conversion sequence, during an object direct initialization. #include <cstdio> class To { public: To() { ...
Oersted's user avatar
  • 4,279
1 vote
1 answer
106 views

I'm puzzled as to how this code compiles: (https://godbolt.org/z/hjY4ca4rr) class A { public: A() = default; A(A &&other) = default; int x = 0; }; A f(A a) { a.x = 1; ...
Uri Simchoni's user avatar
0 votes
0 answers
66 views

This has been bothering me for some time. Say we have a constructor that takes many parameters (copies or rvalues): Object(A a, B b, C c, D d, ...); When you need to use this constructor you can do ...
tjzel's user avatar
  • 115
0 votes
0 answers
143 views

I have the following C++ code that returns a std::tuple<std::vector<int>, std::vector<int>>. My question is about copy elision and named return value optimisation. As I understand, ...
Ramneet Singh's user avatar
0 votes
1 answer
154 views

I've been experimenting with the following C++ code using different compiler flags and versions, observing differing behaviors in object construction between C++11 and C++17. I noticed that with the -...
sam's user avatar
  • 911
1 vote
1 answer
114 views

I have a class Foo class Foo { public: Foo(std::string s) : s_(std::move(s)) { std::cout << "Constructor " << s_ << "\n"; } ~Foo() { ...
Bruce's user avatar
  • 35.6k
0 votes
0 answers
63 views

According to some sources, Named Return Value Optimization (NRVO) is performed when a return object; statement in a function is executed. Nevertheless, the execution of int foo(int a_func) { std::...
rdabra's user avatar
  • 138
3 votes
1 answer
117 views

According to cppreference In constant expression and constant initialization, copy elision is never performed. Still it looks that it is not always so on practice. In the following program, function ...
Fedor's user avatar
  • 25.4k
15 votes
3 answers
996 views

Is the following C program guaranteed to exit with 0 or is the compiler allowed to identify the objects s and t with one another as is permitted in C++ as the so-called named return value optimization ...
user17732522's user avatar
  • 78.3k
4 votes
1 answer
136 views

In the following C++23 program struct A { A() {} A(A&&) = default; void f(this A) {} void operator() (this A) {} }; int main() { A{}.f(); // ok A{}(); // Clang error ...
Fedor's user avatar
  • 25.4k

15 30 50 per page
1
2 3 4 5
21