Questions tagged [stdmove]

117 questions
0
votes
2 answers

Cannot insert std::unique_ptr with custom deleter with std::move

I use a std::unique_ptr with a custom deleter as a value of a std::map as follows: #include #include #include void deleter(int* p){ std::cout<<"Deleting..."<
yawara
  • 11
  • 2
0
votes
1 answer

move or copy when passing arguments to the constructor and member functions

The following is an example of my typical code. A have a lot of objects that look like this: struct Config { Config(); Config(const std::string& cType, const std::string& nType); //additional variables omitted Config(Config&&) =…
CorellianAle
  • 645
  • 8
  • 16
0
votes
1 answer

Interaction between std::move, return value optimization and destructors

There are many threads on Stack Overflow about the interaction between std::move and copy elision, e.g. What are copy elision and return value optimization? How to be confident of copy elision / return-value optimization c++11 Return value…
cero
  • 158
  • 7
0
votes
1 answer

Confusion between std::move and std::forward

So I was just writing a sample and contrived example of std::forward for my understanding, but it didn't work the way I expected. In the program below #include #include struct A { A(const std::string& m) : m_(m) {}; …
avi007
  • 73
  • 1
  • 6
0
votes
1 answer

Passing rvalue reference to QVariant does not work with QString

I am trying to return a rvalue reference from a function to a QVariant. It works for bool and int, but when I pass a string I get an 'invalid' QVariant. My function: QVariant &&AudioSettings::getValueFromTable(const QString &name) { QSqlQuery…
Szpaqn
  • 545
  • 5
  • 17
0
votes
1 answer

Why am I getting no known conversion error?

I have such a code: Link to Wandbox When I try to compile it I'm getting this: ./type_holder.h:45:14: error: no matching constructor for initialization of 'test_class' return new T(args...); ^…
s0nicYouth
  • 470
  • 3
  • 15
-1
votes
1 answer

My own Smart pointer Implementation is creating issue with move operation

In the below code, the output is turning out to be blank instead of constructor and destructor printouts. Without move operation, the code is working well. I am somehow messing up the move operation, please go through and give your inputs to guide…
Tej Ravi
  • 17
  • 4
-1
votes
1 answer

When are function arguments copied?

I am interested to know when the arguments of a function are copied. #include void foo (std::vector a) { std::vector y = std::move(a); //do something with vector y } int main() { std::vector x {1.0f, 2.0f,…
-1
votes
1 answer

Overload a class constructor that takes an rvalue reference

I would like to do something like the following: class Foo { Foo(int &&a, int b, std::string s=""); // does not compile because a is not an rvalue: // Foo(int &&a, std::string s) : Foo(a, 0, s) {} Foo(int &&a, std::string s) :…
-2
votes
1 answer

Move semantic and how it works?

Is there a language syntax for move rather than std::move()? And how does std::move() work? In the rule of five I have to define move constructor. Code using std::move() #include #include #include #include using…
Ibrahim zawra
  • 317
  • 1
  • 2
  • 11
-2
votes
1 answer

Why C++ std::move does not really do a cast on elements in std::initializer_list ? Rvalue

In the funtions bellow, doA is overrided to accept const& and && of std::string, doA_ is overrided to accept these two types of std::initializer_list. But what seems to be wrong is that, in the fisrt doA_ function, a std::move does not correctly…
-3
votes
1 answer

Will std::move() upon object construction in return statement help or prevent RVO?

Due to widely ranging responses from the community, I am asking this in hopes to debunk implementation-specific responses from stack-overflow users. Which of these is best-practice (offers greatest optimization)? // version 1 MyObject…
Roman
  • 13
  • 3
1 2 3 4 5 6 7
8