copy-elision Questions
2
Solved
I expected to see copy elision from Named Return Value Optimization (NRVO) from this test program but its output is "Addresses do not match!" so NRVO didn't happen. Why is this?
// test.c...
Kampmann asked 19/7, 2020 at 21:24
2
Solved
Consider the following program:
#include <functional>
#include <iostream>
class RvoObj {
public:
RvoObj(int x) : x_{x} {}
RvoObj(const RvoObj& obj) : x_{obj.x_} { std::co...
Thapsus asked 29/1, 2020 at 21:11
2
Solved
When performing member initialization for non-copyable variable (such as std::atomic<int>), it's required to use direct-initialization rather than copy-initialization according to answer here...
Mythomania asked 30/9, 2019 at 8:44
1
Solved
I have this type:
struct immobile {
// other stuff omitted
immobile(immobile&) = delete;
immobile(immobile&&) = delete;
};
immobile mk_immobile();
// e.g. this compiles
// mk_immobi...
Sipple asked 4/6, 2019 at 0:12
2
Solved
I was exploring the ugly world of std::intializer_list.
As far as I've understood from the standard:
§ 11.6.4:
An object of type std::initializer_list is constructed from an initializer list...
Paregmenon asked 2/2, 2019 at 23:41
3
Solved
It seems like a silly question, but is the exact moment at which return xxx; is "executed" in a function unambiguously defined?
Please see the following example to see what I mean (here live):
#i...
Bebeeru asked 22/10, 2018 at 13:53
2
I am attempting to delete the copy constructor using the c++ type system to prevent copying an object.
struct DeleteCopyConstructor {
DeleteCopyConstructor() {};
DeleteCopyConstructor(DeleteCopy...
Tomchay asked 25/6, 2017 at 20:56
1
Solved
Today I encountered something I don't really understand about copy constructor.
Consider the next code:
#include <iostream>
using namespace std;
class some_class {
public:
some_cl...
Hemihedral asked 21/9, 2018 at 14:59
0
In a generic context, it is quite often we write something like
return_type f(arg_type1 arg1, ...)
noexcept(noexcept(statement_1) && noexcept(statement_2) && ... && noexce...
Syringa asked 13/7, 2018 at 12:24
2
Solved
My question is different because I may "know" copy-elision. I am learning copy initialization. However,the following code confused me because I have already turned off the copy-elision using -fno-e...
Ideology asked 10/7, 2018 at 5:34
3
Solved
I have this piece of C++ code:
class Args {};
class MyClass {
public:
MyClass(Args& a) {}
MyClass(MyClass &&) = delete;
};
int main() {
Args a;
MyClass c1 = MyClass(a);
MyClas...
Cb asked 27/6, 2018 at 10:5
2
So I was learning about constructor initializer list and I wrote the following code :
class Mango
{
public:
Mango(){cout<<"Mango::ctor()";}
Mango(const Mango& other){cout<&...
Bacitracin asked 20/6, 2018 at 6:33
3
Solved
I see a lot of code at work where people use emplace and emplace_back with a temporary object, like this:
struct A {
A::A(int, int);
};
vector<A> v;
vector<A>.emplace_back(A(1, 2));
...
Senegal asked 7/6, 2018 at 12:2
1
Solved
Background:
Consider the following example:
#include <iostream>
#include <vector>
int main() {
std::vector<bool> vectorBool{false, true};
for(const auto &element : vectorBo...
Pickax asked 27/4, 2018 at 15:54
3
Solved
Let's say I have a function that looks like this:
SomeObject copy_maybe(bool make_new, const SomeObject& def)
{
if (make_new)
return SomeObject();
else
return def;
}
And I call it like t...
Shipyard asked 11/4, 2018 at 17:49
1
Solved
Consider the following program:
#include <iostream>
#include <utility>
class T {
public:
T() { printf("address at construction: %zx\n", (uintptr_t)this); }
// T(const T&) { prin...
Dubose asked 7/4, 2018 at 7:39
1
Solved
In [dcl.init]/17.6, it is explicitly written that for the case of parenthesis initialization, copy elision occurs:
If the initializer expression is a prvalue and the cv-unqualified version of th...
Eighteenmo asked 28/3, 2018 at 12:52
1
Solved
The following code behaves differently with or without user-defined copy constructor under GCC 8.0.1:
#include <cassert>
struct S {
int i;
int *p;
S() : i(0), p(&i) {}
// S(const S ...
Poniard asked 20/2, 2018 at 6:34
1
Solved
Consider the following:
struct X {
X() {}
X(X&&) { puts("move"); }
};
X x = X();
In C++14, the move could be elided despite the fact that the move constructor has side effects thanks t...
Tatiana asked 8/2, 2018 at 9:7
4
Solved
I decided to ask this question after reading items 20 and 22 of the book "More Effective C++" by Scott Meyers.
Let's say you wrote a class to represent rational numbers:
class Rational
{
public...
Postfree asked 24/1, 2018 at 14:15
3
Solved
I cannot figure out why in the last case is the move constructor called when copy elision is enabled (or even mandatory such as in C++17):
class X {
public:
X(int i) { std::clog << "conver...
Fleshings asked 12/1, 2018 at 12:23
2
Solved
A class must have a valid copy or move constructor for any of this syntax to be legal:
C x = factory();
C y( factory() );
C z{ factory() };
In C++03 it was fairly common to rely on copy elision ...
Banks asked 17/6, 2012 at 7:20
1
Solved
Consider the following code:
#include <iostream>
struct Thing
{
Thing(void) {std::cout << __PRETTY_FUNCTION__ << std::endl;}
Thing(Thing const &) = delete;
Thing(Thing &a...
Gustav asked 6/9, 2017 at 9:47
2
Solved
Does mandatory copy elision apply to decomposition via structured bindings? Which of the following cases does that apply to?
// one
auto [one, two] = std::array<SomeClass>{SomeClass{1}, Some...
Mandelbaum asked 15/8, 2017 at 17:35
2
Solved
If I understood correctly, starting from C++17, this code now requires that no copy will be done:
Foo myfunc(void) {
return Foo();
}
auto foo = myfunc(); // no copy
Is it also true for functio...
Pekan asked 29/5, 2017 at 16:7
© 2022 - 2024 — McMap. All rights reserved.