move-semantics Questions
2
Solved
I tried implementing std::move, which uses std::remove_reference, however it seems to work without it. Please, give me an example in which my implementation will fails whithout std::remove_re...
Altruist asked 4/9, 2020 at 15:3
4
Solved
my class has string variables and I want to initialize them with values passed to the constructor.
My teacher thought us to pass strings as a const-reference:
MyClass::MyClass(const std::str...
Extenuatory asked 18/8, 2020 at 10:40
5
Solved
My default behaviour for any objects in local scopes is to make it const. E.g.:
auto const cake = bake_cake(arguments);
I try to have as little non-functional code as I can as this increases rea...
Orvah asked 24/5, 2020 at 14:46
4
Solved
The description for static cast says
If new_type is an rvalue reference type, static_cast converts the value of expression to xvalue. This type of static_cast is used to implement move semantics...
Aponte asked 17/6, 2013 at 7:14
2
Solved
Let's say I have the function:
void foo(Object& o) {
/* only query o, dont alter it*/
}
Is it possible to call this function only with already constructed objects and have Visual Studio throw...
Panne asked 20/7, 2020 at 8:30
1
I'm writing some custom library like stl, but without allocations in ctors and with disabled copy ctors in resource owning classes (because the environment doesn't support exceptions and all allocs...
Prejudge asked 22/4, 2020 at 12:37
2
Solved
The best practice regarding exceptions in C++ seems to be throw by value, catch by reference. I had a look at <exception> and cppreference and I see that std::exception has a copy-constructor...
Malkin asked 15/7, 2020 at 6:35
2
Solved
According to cppreference, std::copyable is defined as follows:
template <class T>
concept copyable =
std::copy_constructible<T> &&
std::movable<T> && // <-- ...
Pneumatic asked 9/7, 2020 at 8:23
2
Solved
How can I move the contents of std::vector into an array safely without copying or iterating over all elements?
void someFunc(float* arr, std::size_t& size)
{
std::vector<float> vec(5, ...
Chesty asked 2/10, 2019 at 15:33
1
Solved
#include <iostream>
#include <time.h>
class A
{
public:
A() { std::cout << "a ctor\n"; }
A(const A&) { std::cout << "a copy ctor\n"; }
A(A&&a...
Pedometer asked 27/6, 2020 at 14:4
2
Solved
When move-constructing a std::function object from a lambda, where that lambda has by-value captures, it appears that the move-constructor of the object that is value-captured is called twice. Cons...
Procrustean asked 26/6, 2020 at 8:54
1
Solved
I'm trying to work out how move semantics affect referential transparency.
Referential transparency (RT) allows us to replace any expression with its result without changing the meaning of the pro...
Tout asked 11/1, 2020 at 16:57
3
Solved
For example (taken from the Rust docs):
let v = vec![1, 2, 3];
let handle = thread::spawn(move || {
println!("Here's a vector: {:?}", v);
});
This is not a question about what move does, but ab...
Gilolo asked 7/6, 2020 at 23:31
3
Solved
I have read in some others posts that move is unnecessary and even deoptimizes mechanisms like NRVO. But it was in most cases about a local field.
Consider this example:
A class stores a tempora...
Ketch asked 10/6, 2020 at 21:6
6
Solved
I'm trying to fill a std::vector with objects created in a function like so:
class Foo
{
public:
Foo() { std::cout << "Foo created!\n"; }
Foo(const Foo& other) { std::cout << "Fo...
Eryneryngo asked 10/6, 2020 at 15:38
2
Solved
Consider the following function accept that takes a "universal reference" of type T and forwards that to a parse<T>() function object with an overload for lvalues and one for rvalues:
templa...
Indulgence asked 25/11, 2013 at 14:44
8
Solved
Am I allowed to move elements out of a std::initializer_list<T>?
#include <initializer_list>
#include <utility>
template<typename T>
void foo(std::initializer_list<T>...
Ramon asked 19/11, 2011 at 9:26
2
Solved
In the c++ reference I do not see a std::stringstream constructor accepting rvalue reference of std::string. Is there any other helper function to move string to stringstream without an overhead or...
Cash asked 14/5, 2016 at 17:18
1
Solved
I have been trying to capture packaged_task into lambda, but I've failed.
I understand move-semantics at all, also read some modern literature and I was thinking I didn't miss anything. Also I hav...
Ashkhabad asked 16/5, 2020 at 12:26
3
Solved
When you have a derived object with a move constructor, and the base object also has move semantics, what is the proper way to call the base object move constructor from the derived object move con...
Tousle asked 3/11, 2010 at 11:59
2
Solved
Making a vector of a map of move-only types doesn't seem to work properly on Windows.
See code here: https://godbolt.org/z/yAHmzh
#include <vector>
#include <map>
#include <memory&g...
Lawrenson asked 1/5, 2020 at 23:37
2
Solved
I tried extending std::ifstream with one function to make it easier to read binary variables, and to my surprise, with using std::ifstream::ifstream; the move constructor is not inherited. Worse ye...
Mixedup asked 2/5, 2020 at 17:58
2
Solved
Suppose that I am implementing a collection and I want to add an element to it, something like.
template <typename T>
class MyCollection
{
void add(const T& element);
};
Now, since ad...
Dollarfish asked 27/4, 2020 at 20:21
2
Solved
I have a general struct with settings and an extra variable setting that I want to tune and play around with.
For all possible values in an integer range, I want to start a (scoped) thread with th...
Peacock asked 19/10, 2019 at 0:52
2
Solved
Opencv's documentation on cv::Mat seems to indicate that there are no move constructors at the moment, so something like cv::Mat A=std::move(some_other_cv_mat) doesn't make much sense. My current (...
Strade asked 24/5, 2018 at 13:21
© 2022 - 2024 — McMap. All rights reserved.