Questions tagged [stdmove]
117 questions
1
vote
4 answers
c++ using an array without calling constructor
My task is to create a template type array without calling the T (template) constructor. After that I want to move some value to this array from another with std::move. How can I do this in c++? Here is my code:
void *temp = malloc((end-begin) *…

kbenda
- 430
- 5
- 15
0
votes
0 answers
getting clang warining as pass by value and use std::move?? why am I getting this warning
This build is in C++,
class DataHandler
DataHandler::DataHandler(conststd::shared_ptr

Surendra Reddy
- 1
- 1
0
votes
0 answers
What are the [[msvc::intrinsic]] properties of C++ msvc?
When I was using visual studio 2022, I noticed that its std::move function defines the [[msvc::intrinsic]] attribute as a macro. /std:c++latest produces some non-standard behavior
That is, the lifetime of the temporary object is extended, but in…

归故里
- 9
- 1
0
votes
1 answer
list class is crashing in the destructor, why?
The following code uses placement new to move each value.
The copy constructor and operator = have been deleted, so the only place where new memory is allocated, and old is copied is in the add function.
#include
#include
using…

Dov
- 8,000
- 8
- 46
- 75
0
votes
1 answer
Will std::move() call the destructor of the owned object of a unique_ptr?
Consider the following code:
#include
#include
#include
struct Data {
std::string name;
Data(std::string aName): name(aName) {
std::cout << name << " Constructor is called\n";
}
~Data() {
…

Darshan Bhat
- 245
- 1
- 11
0
votes
0 answers
Why does variable value not change giving std::move as function argument?
I have looked at other posts regarding std::move but those examples were a bit complicated for me to understand so I will try to explain my problem with a very simple example here.
void increaseNum(int num) {
num += 1;
}
int main() {
int…

test
- 93
- 1
- 11
0
votes
0 answers
Why not always take by rvalue ref?
I have an API which just enters a subscription into a vector of callbacks. The vector uses std::function which could be partially heap allocated, hence move operations on std::function make sense. Now I could implement this API in two ways:
Take by…

glades
- 3,778
- 1
- 12
- 34
0
votes
1 answer
C++ new operator with std::move to "copy" pointer
I recently find a code snippet as follows:
// To be specific: the "Item" can be viewed as "std::pair*" here
void moveItemDuringRehash(Item* itemAddr, Item& src) {
// This is basically *itemAddr = src; src = nullptr, but allowing
…

jiexray
- 325
- 4
- 13
0
votes
0 answers
Can a unique_ptr be moved when referenced by a weak_ptr?
I have a bunch of unique_ptrs for database connections. They get checked out by different parts of the code to run database queries, then returned (std::move) back to the container for next use.
I want to keep track of all instances of these…

Sean
- 1
0
votes
2 answers
linked list destructor with std::move c++
I'm learning data structures in C++;
I've written a destructor for a linked list as follows:
~List(){
Node* temporary = new Node;
Node* node = head;
while(node != nullptr){
temporary = node;
node =…

Eric Cardozo
- 23
- 5
0
votes
0 answers
std::move with a function that expects an rvalue reference
I've been doing some examples based around move semantics and I stumbled upon a case that I'm unable to explain and I wasn't able to find a similar question here on stackoverflow either. I suppose there's something obvious that I am not aware of or…

user20082296
- 1
- 1
0
votes
1 answer
Adding an object to std::map doesn't work unless an "empty" (no args) constructor for the class' object exists
I am studying the code of an open source app. I have made a simpler version of this code to isolate something bugging me (though I have several questions with this code that I am hoping C++ gurus will be able to help me with, I will start with the…

user18490
- 3,546
- 4
- 33
- 52
0
votes
1 answer
Initializing unique_ptr causes an "error: use of deleted function" even though it's "std::move"ed
I am writing code that passes a std::unique_ptr through a few layers that look bad, but I don't have a choice but pass it all along for now.
The problem is that I am getting an error when I try to pass the std::unique_ptr to a constructor of the…

user2465084
- 21
- 5
0
votes
0 answers
Using std::move when returning an object
If I have the following function:
MyObject Process(std::string par1, int par2){
MyObject message;
// Do some processing here
return message;
}
Can this be implemented like this:
MyObject Process(std::string par1, int par2){
…

KansaiRobot
- 7,564
- 11
- 71
- 150
0
votes
1 answer
A lvalue reference can bind to a rvalue reference but cannot bind to the result of std::move
I have a function that has a lvalue reference as argument, and I found that I can also pass
a rvalue reference to it. However, when I passing the result of std::move to the function, I get an error which tells me that I cannot bind non-const lvalue…

Nolazuck
- 81
- 4