move-constructor Questions
2
Solved
I've got the following implementation of the c++ concept move_constructible from cppreference
template<typename _Tp>
concept move_constructible =
constructible_from<_Tp, _Tp> &&...
Beneath asked 22/11, 2021 at 4:40
4
Solved
I want to refresh my memory on the conditions under which a compiler typically auto generates a default constructor, copy constructor and assignment operator.
I recollect there were some rules, bu...
Cailly asked 9/2, 2011 at 11:1
2
Solved
I was working on some C++ code using std::move on shared_ptr and got really weird output. I've simplified my code as below
int func(std::shared_ptr<int>&& a) {
return 0;
}
int main(...
Multiped asked 9/5, 2023 at 11:17
4
Solved
I'm confused about when a move constructor gets called vs a copy constructor.
I've read the following sources:
Move constructor is not getting called in C++0x
Move semantics and rvalue reference...
Manet asked 29/10, 2012 at 16:22
2
As per this post, which says that[emphasise mine]:
The move assignment operator is auto-generated if there is no user-declared copy constructor, copy assignment operator or destructor, and if the ...
Montserrat asked 4/5, 2022 at 3:54
1
Solved
For move construction:
After the move, other is guaranteed to be empty(). 1
For move assignment, the oft-quoted:
other is in a valid but unspecified state afterwards. 2
Why is the state of othe...
Verda asked 24/2, 2022 at 6:2
3
Solved
Synopsis
How can I safely design a move constructor when a class uses multiple inheritance?
Details
Consider the following scenario:
struct T { };
struct U { };
struct X : public T, public U
{...
Myrt asked 11/4, 2012 at 22:11
3
Solved
Firstly, I really checked if there is a question already been asked but I could not find any. Error message should not deceive you my situation is a bit different I guess or I am just missing somet...
Siderite asked 21/9, 2019 at 10:48
1
Why does an explicitly defaulted destructor disable default move constructor in the class? I know that it does, as explained in several existing answers. (e.g. Explicitly defaulted destructor disab...
Saraband asked 2/12, 2021 at 22:3
1
Solved
I'm working through Stroustrup's "Tour of C++ v2". It's certainly not a C++ beginner's book, but enjoyable.
I've had a google and look through SO but no joy on this one.
Now, I thought I ...
Northnorthwest asked 9/9, 2021 at 7:32
3
Solved
Ok so I ran into a problem when implementing a c# property like system in c++ (see: https://mcmap.net/q/16573/-c-like-properties-in-native-c).
Consider the following example:
struct TransformCmp
{
...
Phagy asked 28/7, 2021 at 11:46
1
Solved
I'm using VS Code to compile and debug with g++ in Linux.
Needed includes and usings:
#include <string>
#include <iostream>
using namespace std;
Here is my class which is moveab...
Hurtado asked 25/6, 2021 at 7:33
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
3
Solved
Is there a better way to build a move constructor for a union-like class? If I were to have a union-like class like the class in the following code, is there a way to build the class or the move co...
Weinman asked 12/3, 2015 at 0:57
3
Solved
It compiles with /permissive but fails with /permissive-. What is not conforming and how to fix it?
Why it's fine in (2) but fails in (4)(3)?
If I remove operator long it also fine.
How to fix it...
Intracutaneous asked 6/9, 2019 at 11:43
2
Solved
I am trying to understand the implementation of move-constructor.
We all know if we need to manage resources in a C++ class, we need to implement Rule of five (C++ programming).
Microsoft gives us...
Gesso asked 4/4, 2016 at 14:26
3
Assume I have an object with both copy and move assignment operators defined. When I write this:
Object a(/*parameters 1*/);
/* some code */
a = Object(/*parameters 2*/);
the third line will mos...
Annmarie asked 30/1, 2020 at 15:27
2
Solved
According to the answer of this question, a default move constructor can be defined as noexcept under certain conditions. For instance, the following class generates a noexcept move constructor:
c...
Cropeared asked 22/1, 2020 at 8:55
1
Solved
What is the feature that allows me use auto for non-copyable (and non-movable) types in C++17 and didn't for C++14?
Consider the following code:
struct A{
A(A const&)=delete;
A(A&&)...
Within asked 20/10, 2019 at 3:22
2
Solved
Just came from is_assignable and std::unique_ptr. @Angew tells me that because std::unique_ptr<int, do_nothing> and std::unique_ptr<int> are different types, so static_assert(not std::i...
Cordierite asked 21/12, 2018 at 13:23
1
Solved
I recently stumbled upon some strange behaviour (strange from my point of view) from move constructor. The result is different when compiling with GCC and Visual Studio. I would like to hear the ex...
Riyadh asked 15/12, 2018 at 15:14
6
Solved
The MSDN article, How to: Write a Move Constuctor, has the following recommendation.
If you provide both a move constructor and a move assignment operator for your class, you can eliminate redun...
Lowering asked 14/6, 2013 at 22:36
4
Solved
The below code can be compiled successfully using Visual Studio 2015, but it failed using Visual Studio 2017. Visual Studio 2017 reports:
error C2280: “std::pair::pair(const std::pair &)”: a...
Mullite asked 6/11, 2018 at 9:14
6
Solved
Minimal working example.
#include <cassert>
#include <list>
#include <queue>
//#define USE_PQ
struct MyClass
{
const char* str;
MyClass(const char* _str) : str(_str) {}
MyCla...
Mckeever asked 22/11, 2013 at 16:14
4
Solved
In several places I've seen the recommended signatures of copy and move constructors given as:
struct T
{
T();
T(const T& other);
T(T&& other);
};
Where the copy constructor takes...
Eclosion asked 26/5, 2012 at 22:11
1 Next >
© 2022 - 2024 — McMap. All rights reserved.