2,176 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
2
votes
1
answer
197
views
list<unique_ptr<int[]>> giving error use of deleted function [duplicate]
I need a list of unique pointers to ints (I need the underlying int arrays because of MPI compatibility, they are buffers that are getting tracked for work done). I have a workaround but would like to ...
3
votes
2
answers
127
views
Moving underlying container (std::vector or std::deque) for std::stack and std::queue [duplicate]
I had a usecase where I use a stack to process some data. Once processed, I want to output the data as a vector. But since underlying containers in stack are protected, it is now allowed to:
stack<...
1
vote
1
answer
232
views
Are swaps allowed to self-check?
While checking &other != this is generally not a good idea in move/copy assignment and the copy-and-swap idiom should be preferred, is it allowed for a swap to perform such a check?
Copy-and-swap ...
2
votes
2
answers
125
views
Why can I not efficiently move the strings when using std::istream_iterator<std::string>?
#include <fstream>
#include <string>
#include <vector>
int main() {
auto fin = std::ifstream("tmp.txt");
auto pos = std::istream_iterator<std::string>(fin);...
2
votes
1
answer
144
views
Using std::move with Constructor(Type t) or Constructor(Type&& t). What's the difference?
I'm studying std::move semantics and I would like this to be clarified to me:
Say I have:
// Message.h
class Message
{
private:
std::array<uint8_t, BUFFER_SIZE> buffer;
std::queue<...
1
vote
2
answers
104
views
making an invocable concept more accurate with respect to argument value category
As far as I understand, std::invocable<callable_type,args_type...> treats the callable arguments as rvalue references to the types args_type.
As a consequence, std::invocable<void(std::...
5
votes
2
answers
183
views
What is the rationale behind container types in std defining their own swap function even if their move-semantics have been correctly implemented?
Below is the most common implementation of std::swap:
template<typename T>
void std::swap(T& a, T& b) {
auto tmp = std::move(a);
a = std::move(b);
b = std::move(...
4
votes
1
answer
119
views
Clang-tidy bugprone-use-after-move with perfect forwarding
clang-tidy reports the following piece of code as bugprone-use-after-move
template <typename F, typename Tuple, size_t... I>
auto transform_tuple_impl(F&& f, Tuple&& tuple, std::...
2
votes
0
answers
117
views
MSVC calling deleted destructor when wrapping rvalue in struct (C++23)
I'm experimenting, with wrapping move semantics into a wrapper type:
#include <utility>
#include <type_traits>
// Type that will get moved
struct NonDestructible {
~NonDestructible() =...
2
votes
2
answers
140
views
Value categories in C++: What does "can be moved from" mean?
In C++, the value category of an expression is determined by two independent properties:
Whether the expression has an identity
Whether the expression can be moved from
(References: cppreference and ...
3
votes
1
answer
95
views
Doing std::move in constructors initialization segment
I have an issue with clang-tidys recommendation
Clang-tidy: arg is passed by value and only used once; consider moving it.
So the code is essentially this:
struct S{
kinda_heavy obj;
S(...
6
votes
1
answer
471
views
Is const T& effectively the same as T&& with std::forward for rvalue argument when be passed into another function?
Say I have a const T& version:
template <typename T>
void yetAnotherFunc( const T &input ) {
// do something...
}
template <typename T>
void myFunc( const T &input ) {
...
6
votes
1
answer
244
views
Static assertion failed: result type must be constructible from input type when moving objects into std::vector
I'm experimenting with move semantics in C++, and I have a simple class Entity that should only be movable — copying is disabled.
Here’s the class:
class Entity {
public:
//...
Entity() = ...
-1
votes
1
answer
70
views
How do I move a Sender object out of a mutable reference to a Vector of tuples of Strings and Sender Objects?
This is not a solution to my problem. The suggested answer replaces the values with Nones. I quite literally require the size of my vector to reduce.
MRE:
use tokio::sync::mpsc;
#[tokio::main]
async ...
26
votes
3
answers
2k
views
Only copiable type not accepted in msvc std::vector implementation
In the following code:
struct copy_only
{
copy_only() = default;
copy_only(const copy_only&) = default;
copy_only& operator=(const copy_only&) = default;
...