move-semantics Questions
4
Solved
Let's say that I have a main class SomeManager for keeping track of instances of another class SomeClass. When SomeClass is constructed it calls a method of SomeManager passing a pointer to itself....
Snow asked 13/2, 2015 at 4:8
3
Solved
I have a class member that looks like this
class Controller {
protected:
// other stuff
std::vector<Task<event_t, stackDepth>> taskHandlers;
//some more stuf
}
The Task class is ...
Fluviatile asked 6/7, 2020 at 7:49
2
Solved
Simplified program as follows
struct S {
S() {}
S(const S &) {}
S(S &&) = delete;
};
S x;
S y = false ? S() : x;
is accepted just fine by GCC and Clang, but the latest Visual Studi...
Omar asked 8/6 at 13:58
1
When examining the constructors of std::tuple on the cppreference site, I came across the move constructor defined below, which is available in C++23.
template< class... UTypes >
constexpr tu...
Hadrian asked 5/5 at 13:42
3
Solved
I'm looking for a method that consumes a Vec and returns one element, without the overhead of restoring Vec's invariants the way remove and swap_remove do:
fn take<T>(vec: Vec<T>, inde...
Functional asked 21/8, 2017 at 19:2
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
2
Solved
In order to make this code with C++11 reference qualifiers work as expected I have to introduce a std::move(*this) that doesn't sound right.
#include<iostream>
struct A{
void gun() const&...
Interrupter asked 15/8, 2014 at 21:48
12
Solved
I've just finished listening to the Software Engineering radio podcast interview with Scott Meyers regarding C++11. Most of the new features made sense to me, with the exception of one. I still don...
Breban asked 23/6, 2010 at 22:46
7
Solved
In Rust, there are two possibilities to take a reference
Borrow, i.e., take a reference but don't allow mutating the reference destination. The & operator borrows ownership from a value.
Borr...
Chokebore asked 17/5, 2015 at 15:46
1
Solved
class C
{
public:
C(C&&) = default; // (1)
C& operator=(C&&) = default; // (1)
C(C&&) noexcept = default; // (2)
C& operator=(C&&) noexcept = default; ...
Chafe asked 15/1 at 6:10
5
Solved
Suppose we have this class:
class X {
public:
explicit X (char* c) { cout<<"ctor"<<endl; init(c); };
X (X& lv) { cout<<"copy"<<endl; init(lv.c_); };
X (X&& r...
Evitaevitable asked 27/10, 2012 at 11:6
2
Solved
Sometimes in a function I use std::move to pass on a variable I'm no longer using, like this:
void f(std::vector<int> v)
{
for (int i: v)
{
std::cout << i << ", ";
}...
Serrulate asked 30/9, 2019 at 7:10
3
Solved
I've got an API that looks like this:
void WriteDefaultFileOutput(std::wostream &str, std::wstring target)
{
//Some code that modifies target before printing it and such...
}
I'm wondering ...
Macy asked 15/3, 2012 at 17:18
1
Solved
I'm reading Nicolai M. Josuttis's C++ Move Semantics - The Complete Guide book (which is pretty good imho) and I'm not sure I agree with the comments in one of the examples.
Quote (from 6.1.2 - Gua...
Outfight asked 16/8, 2023 at 18:16
2
I think I understand functions with signatures like:
void f(std::string&&):
It will be applied to rvalues to reuse their resources. However, I've seen occasionally code like:
std::string t...
Overmaster asked 30/6, 2023 at 18:10
4
Solved
This post rambles a bit so before I get into it I want to be clear what I'm asking: Have you added move-enabled setters to your code and have you found it's worth the effort? And how much of the be...
Tarpley asked 21/5, 2012 at 20:43
3
Solved
Let's say you have a variable of type std::vector<std::string> and you initialize it with an initializer list:
using V = std::vector<std::string>;
V v = { "Hello", "little", "wor...
Chiropractor asked 2/4, 2016 at 19:22
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
1
The following code:
#include <iostream>
struct A {
A() { std::cout << "()" << std::endl; }
A(A&&) { std::cout << "(A&&)" <&...
Conchaconchie asked 8/5, 2023 at 10:32
4
Suppose I have the following:
#include <memory>
struct A { int x; };
class B {
B(int x, std::unique_ptr<A> a);
};
class C : public B {
C(std::unique_ptr<A> a) : B(a->x, st...
Batch asked 17/7, 2014 at 22:41
2
Solved
I don't understand the error cannot move out of borrowed content. I have received it many times and I have always solved it, but I've never understood why.
For example:
for line in self.xslg_file...
Coquillage asked 26/1, 2015 at 21:4
1
Solved
I have a follow-up question to this one: Move unique_ptr: reset the source vs. destroy the old object
For a quick summary of the original question, there is this sample code on cppreference:
struct...
Wolverhampton asked 8/4, 2023 at 15:39
1
I have a function that gets a "Config" struct, which at the moment is simply a struct that contains an array
class ShmConfig {
public:
std::int64_t shellShmSize[ShellId_Count];
};
And I...
Saveloy asked 18/5, 2021 at 11:50
1
The convenient initializer_list syntax seems to come at a price of not being able to move members of the list, creating unnecessary copies.
struct A
{
// some members which are dynamic resources.....
Rectangular asked 20/3, 2023 at 22:55
1
Solved
I'm confused by a Boost.Asio idiom I frequently see - calling a handler (function object) like this:
std::move(handler)(param1, param2);
What is the reason for writing it this way? My understandin...
Lo asked 16/3, 2023 at 11:14
1 Next >
© 2022 - 2024 — McMap. All rights reserved.