Questions tagged [stdmove]
117 questions
0
votes
3 answers
Why is static_cast
Trying to understand std::move, I found this answer to another question.
Say I have this function
Object&& move(Object&& arg)
{
return static_cast

Gradient
- 2,253
- 6
- 25
- 36
0
votes
1 answer
Can someone please tell me if I'm using unique pointers correctly
I'm trying to use smart pointers more but am not sure if I'm using them correctly. I seem to need to use std::move all over the place. Don't quite understand why, but it's working. What my example code does isn't important (nothing as happens :)),…

user1408542
- 83
- 6
0
votes
1 answer
Correctly move from a data member of a temporary object
Consider the following C++-Code
#include
using namespace std;
struct WrapMe
{
WrapMe() { cout << "WrapMe Default Ctor of: " << this << endl; }
WrapMe(const WrapMe& other) { cout << "WrapMe Copy Ctor of " << this << " from " <<…

Ruperrrt
- 489
- 2
- 13
0
votes
0 answers
Implementing Stack using Linked List ( With Templates, Lvalue & Rvalue references, Universal References, Perfect Forwarding )
I have recently learned concepts like Lvalue & Rvalue references, Universal References, Perfect Forwarding, std::move(), std::forward() etc.
I tried to implement templatized version of Stack (Using Linked List) and was wondering how can I use the…

Pulkit Saini
- 41
- 4
0
votes
2 answers
What does std::move do when called on a function?
I'm working on making some changes to a piece of code, and have a doubt in understanding the behavior of std::move in below case:
struct Timer {
Timer (boost::asio::io_service& ios) : timer_{ios} {}
boost::asio::steady_timer timer_;
};
struct…

void
- 338
- 5
- 19
0
votes
2 answers
Why does static_cast in the std::move() wipe value of argument?
My question contains two parts:
Does function static_cast<Т>(arg) alter the innards of arg? Obviously not, according to such code:
float i1 = 11.5;
int x = static_cast(i1);
std::cout << i1<

Max Popov
- 357
- 2
- 12
0
votes
0 answers
unique_ptr returns junk values with move semanitics
I have the generic class which can store a value and a type of the value encoded as a string.
#include
#include
#include
#include
struct IValueHolder
{
virtual ~IValueHolder() = default;
virtual const…

Indri
- 41
- 1
- 6
0
votes
1 answer
Move constructor for a list of Person objects
I am writing a simple code, in which I have a list of objects of class Person.
The Person class
class Person
{
private:
std::string name;
std::string surname;
int year;
public:
Person(const…

vaeVictis
- 484
- 1
- 3
- 13
0
votes
0 answers
Update a struct by returning a moved parameter instead of passing by reference
Say we have a struct:
struct S{ int _i = 1; };
I would like to write a function which updates an instance of S, like this:
void update(S& s) { s._i += 1; }
I usually prefer to return values rather than passing an argument by reference and changing…

mfnx
- 2,894
- 1
- 12
- 28
0
votes
1 answer
Boost asio post with shared ptr passed as argument with std::move
I am new to boost:asio. I need to pass shared_ptr as argument to handler function.
E.g.
boost::asio::post(std::bind(&::function_x, std::move(some_shared_ptr)));
Is using std::move(some_shared_ptr) correct? or should I use as…
0
votes
1 answer
why using std::move and assign to rvalue does not steal internal content?
As is known to all that c++ std::move would steal internal content if used with non-fundamental type. I suddenly have a brainwave that what will happen to rvalue if move a lvalue to it. I initially thought it would still steal the content. But…

Caiyi Zhou
- 143
- 1
- 9
0
votes
1 answer
Move of local variable that have move c-tor into function with parameter by value
Trying to clear my understanding when move happens, and when it's better to write functions that pass values by value, instead of reference, to gain from moves.
void foo()
{
std::string localStr;
//
foo1(localStr);
}
void foo1(const std::string…

Bruice
- 543
- 3
- 11
0
votes
0 answers
Perfect Forwarding and move
I have a program where i have a struct with 2 data members
struct myStruct{
uint64_t promotionID;
int32_t amount;
};
I have to add them to an unordered_map where i had many copy operations. Right now I am searching…
0
votes
1 answer
C++20 std::move in self assignment
Most answers, including this one, point out that std::move is not meant to be used in self-assignment.
I do, however, see the Possible Implementation of accumulate in official reference via self move assignment:
template

user2376997
- 501
- 6
- 22
0
votes
2 answers
what will happen when std::move with c style array or not movable object
For a C style array, what will happen when I run float *fp1 = std::move(fp);, as seen in the following code marked (1)? Is it the same as float *fp1 = fp;, as seen in the following code marked (2)?
I printed the results and it seems they are the…

Biao Cao
- 141
- 1
- 10