copy-elision Questions
3
Solved
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 optimizat...
Highspirited asked 27/7 at 21:25
4
Solved
I have an uncopiable class. Copying this would be problematic. I want to guarantee that it won't be ever copied, so I made its copy constructor deleted:
class A {
public:
A();
A(const A&) =...
Interleaf asked 6/7, 2016 at 13:8
1
Solved
In the following code, struct B is an aggregate with base struct A, and B-object is aggregate initialized B b{ A{} }:
#include <iostream>
struct A {
A() { std::cout << "A ";...
Inigo asked 28/1, 2022 at 18:25
3
Solved
It's stated in [C++11: 12.8/31] :
This elision of copy/move operations, called copy elision, is permitted [...] :
— in a return statement in a function with a class return type, when the expressio...
Clouded asked 25/2, 2012 at 13:40
4
Solved
Copy elision is a neat optimization technique and in some cases relying on copy elision can actually be faster than passing around references "by hand".
So, let's assume you have identified a crit...
Coeliac asked 26/5, 2011 at 14:42
2
Solved
Is there any warning, which allows us to know whether NRVO/RVO performed or not, in GCC?
I found that -fno-elide-constructors turns off NRVO/RVO, but NRVO/RVO has its own conditions to occur and s...
Dorkas asked 19/12, 2013 at 5:41
3
The standard library utility declval is defined as:
template<class T> add_rvalue_reference_t<T> declval() noexcept;
To add a rvalue reference here seemed like a good idea, if you think...
Holyhead asked 3/6, 2021 at 17:40
1
Solved
Preamble
This is a description of what I am trying to do with the code, skip to the next section to see the actual issue.
I want to use coroutines in an embedded system, where I can't afford too ma...
Inflexed asked 9/6, 2023 at 15:23
3
Solved
i was fooling around with the following code and got different results using my visual studio 2017 application and two different online compilers. in release mode visual studio does elide the copy/...
Quassia asked 12/2, 2018 at 15:6
4
(This is a follow-up from "Are there any realistic use cases for `decltype(auto)` variables?")
Consider the following scenario - I want to pass a function f to another function invoke_log_return w...
Sphacelus asked 10/8, 2019 at 18:59
3
Solved
I want to store a non-trivial type that is immovable and not copyable in an std::optional. However the object is constructed by a free function. (example)
struct Foo {
Foo();
Foo(Foo const&) ...
Opheliaophelie asked 10/1, 2023 at 9:23
1
Solved
std::variant has a constructor that accepts std::in_place_t<Type>, Args &&... arguments that results in in-place construction.
{
std::cout << "in_place_type:\n";
co...
Mining asked 16/9, 2022 at 11:55
1
In C++17 and above, guaranteed copy elision means that it's possible to return non-moveable objects frun a chain of functions, all the way to the ultimate caller:
struct NonMoveable {
NonMoveable(...
Labdanum asked 5/7, 2022 at 9:51
3
Solved
Consider this code, which defines a simple struct Test (with a default constructor and copy constructor) and returns a std::pair <Test, Test> from a function.
#include <iostream>
#inclu...
Eustatius asked 2/7, 2022 at 19:28
2
I had an interview, where I get the following function declaration:
int f1(const std::vector<int> vec)
I suggested that instead of copying the vector, we should use a const-reference(not to ...
Iodoform asked 3/6, 2022 at 9:2
2
The following code compiles with MSVC (/permissive-) and fails to compile with GCC/Clang for m_ptr1 and m_ptr2.
#include <memory>
struct ForwardDeclared;
class A {
public:
explicit A();
...
Continuative asked 14/12, 2020 at 9:23
2
Solved
It is known that std::move should not be applied to the function return values because it can prevent RVO (return value optimization). I am interested in the question what should we do if we certai...
Confirmand asked 14/1, 2018 at 15:4
1
Solved
I have a simple code:
#include <atomic>
int main()
{
std::atomic<int> a = 0;
}
This code compiles fine with GCC 11.1.0 with -std=c++17, but fails with -std=c++14 and -std=c++11.
usi...
Tripoli asked 10/7, 2021 at 13:43
2
Solved
At the 2016 Oulu ISO C++ Standards meeting, a proposal called Guaranteed copy elision through simplified value categories was voted into C++17 by the standards committee.
How exactly does guarante...
Dibromide asked 26/6, 2016 at 21:23
2
Solved
I have the following code.
#include <iostream>
struct Box {
Box() { std::cout << "constructed at " << this << '\n'; }
Box(Box const&) { puts("cop...
Murdocca asked 18/6, 2021 at 11:23
3
Solved
I've recently learned about move constructors, but a lot of the online resources don't talk about copy elision. Copy elision makes sense to me too, but it left me wondering when is the move constru...
Caput asked 1/6, 2021 at 14:48
2
Consider the following example code in C++ >=17:
struct A{
A() = default;
A(const A&) = delete;
};
const A f(){ return A{}; }
int main(){
const A& a = f(); // OK
// A& b = f();...
Eley asked 24/4, 2021 at 17:39
2
Solved
While fiddling around with copy elision I came across this strange behavior:
class Obj {
public:
Obj() = default;
Obj(Obj&&) = delete;
Obj(const Obj&) { std::cout << "Co...
Flasher asked 27/2, 2021 at 23:26
5
Solved
What is copy elision? What is (named) return value optimization? What do they imply?
In what situations can they occur? What are limitations?
If you were referenced to this question, you're prob...
Grievous asked 18/10, 2012 at 11:3
2
Solved
I would expect that in C++20 the following code prints nothing between prints of A and B (since I expect guaranteed RVO to kick in). But output is:
A
Bye
B
C
Bye
Bye
So presumably one temporary i...
Pronghorn asked 24/8, 2020 at 11:21
1 Next >
© 2022 - 2024 — McMap. All rights reserved.