copy-elision Questions

1

Solved

I was reading the documentation for std::for_each here http://en.cppreference.com/w/cpp/algorithm/for_each and saw that the return value is std::move(f) Why does the standard enforce moving the in...
Phenanthrene asked 2/4, 2017 at 1:46

4

Solved

How can I initialize an array without copy or move-constructing temporary elements? When the element has an explicitly deleted copy or move constructor, I can initialize the array only if the eleme...
Intravasation asked 18/2, 2017 at 0:3

2

Solved

Let's say I have the following type: struct X { X& operator+=(X const&); friend X operator+(X lhs, X const& rhs) { lhs += rhs; return lhs; } }; And I have the declaration (assum...
Fraternity asked 10/2, 2017 at 18:4

2

Solved

Suppose I have a weird string type, that either owns or doesn't own it's underlying buffer: class WeirdString { private: char* buffer; size_t length; size_t capacity; bool owns; public: // N...
Munich asked 23/1, 2017 at 22:47

4

Solved

So my understanding of move semantics is that they allow you to override functions for use with temporary values (rvalues) and avoid potentially expensive copies (by moving the state from an unname...

1

I found GCC 7 has implemented guaranteed copy elision, and I tried the code below in wandbox: #include <iostream> struct NonMovable { NonMovable() noexcept = default; NonMovable(NonMovabl...
Aqua asked 7/10, 2016 at 15:32

1

Solved

There is a paragraph about guaranteed copy elision in c++ draft n4606 [dcl.init] 17.6: If the destination type is a (possibly cv-qualified) class type: If the initializer expression is a ...
Axum asked 6/8, 2016 at 8:1

1

Solved

If I write a factory method that instantiates an object locally and then returns by value, intending to take advantage of NRVO (as per some of the answers here: c++11 Return value optimization or m...
Eveliaevelin asked 30/6, 2016 at 13:21

1

Solved

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0135r0.html The above proposal for 'Guaranteed Copy Elision' was voted into the C++ working paper in the June 2016 meeting in Oulu, Finland...
Chloric asked 26/6, 2016 at 19:43

4

Solved

I have a static_assert in a move constructor of a template struct of mine. Is this static_assert required to be considered by the compiler, even if copy elision is possible? This is the stripped-d...
Katharinekatharsis asked 2/4, 2016 at 9:35

2

Solved

I have two pieces of code here to show you. They are two classes and each one provides a Move Constructor and a function which returns a temporary. In the first case, the function returning a temp...
Loyalty asked 19/2, 2016 at 13:38

2

Solved

Consider the following program: #include<iostream> using namespace std; struct S { S() = default; S(const S& other) = delete; S(S&& other) = delete; int i; }; S nakedBrace(...
Sapphirine asked 27/1, 2016 at 15:35

2

Solved

Given struct Range{ Range(double from, double to) : from(from), to(to) {} double from; double to; // if it matters to the compiler, we can add more fields here to make copying expensive }; st...
Diann asked 23/11, 2015 at 14:8

4

Solved

Given struct Range{ Range(double from, double to) : from(from), to(to) {} double from; double to; }; struct Box{ Box(Range x, Range y) : x(x), y(y) {} Range x; Range y; }; suppose we run ...
Fostoria asked 23/11, 2015 at 13:15

2

Here is a complete program: #include <iostream> using std::cout; using std::endl; using std::move; int count {0}; // global for monitoring class Triple { public: Triple() = default; // C...
Upholsterer asked 18/11, 2015 at 21:33

5

Solved

Consider this code: #include <iostream> struct Test { int x; int y; }; Test func(const Test& in) { Test out; out.x=in.y; out.y=in.x; return out; } int main() { Test test{1,2}; ...
Brambling asked 23/10, 2015 at 14:48

1

Solved

gcc, clang and VS2015 don't elide the call to the move constructor in the code below, after throwing object a. It seems to me the conditions established in bullet point (31.2) of §8.12[class.copy]/...
Snowman asked 27/9, 2015 at 19:37

3

Solved

Lots of discussions here about when RVO can be done but not much about when it is actually done. As stated may times, RVO can not be guaranteed according to the Standard but is there a way to guara...
Overdress asked 9/10, 2013 at 2:27

2

Solved

Some people are not aware that it's possible to pass and return structs by value in C. My question is about the compiler making unnecessary copies when returning structs in C. Do C compilers such a...
Enthrone asked 4/5, 2015 at 15:41

2

Solved

#include <iostream> struct A { A() { std::cout << "Def Constr\n"; } A(const A&) { std::cout << "Copy Constr\n"; } }; A func1() { return A{}; } void func2(A a) {} int ...
Morphogenesis asked 6/3, 2015 at 12:31

1

Solved

In the code below an object s of class S is used to initialize an object of class D with a direct-initialization D d(s);. The conversion function S::operator D() is used to convert the object s int...
Tittivate asked 2/12, 2014 at 12:38

2

Solved

Consider the following code: #include <iostream> using namespace std; class A { public: int a; A(): a(5) { cout << "Constructor\n"; } A(const A &b) { a = b.a; cout <...

2

Solved

std::unique_ptr<int> ptr() { std::unique_ptr<int> p(new int(3)); return p; // Why doesn't this require explicit move using std::move? } // Why didn't the data pointed to by 'p' ...
Stick asked 17/9, 2014 at 7:49

2

Solved

I have this piece of code: #include <iostream> #include <vector> using namespace std; class Foo{ public: Foo() noexcept {cout << "ctor" << endl;} Foo(const Foo&) no...
Edgebone asked 17/7, 2014 at 0:26

3

Solved

The following code compiles fine in Visual C++ 2013, but not under GCC or Clang. Which is correct? Is an accessible copy constructor required when returning an object via an implicit conversion? ...
Kerosene asked 16/6, 2014 at 7:43

© 2022 - 2024 — McMap. All rights reserved.