Skip to main content
Filter by
Sorted by
Tagged with
3 votes
2 answers
124 views

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<...
Dwij Dixit's user avatar
2 votes
2 answers
123 views

#include <fstream> #include <string> #include <vector> int main() { auto fin = std::ifstream("tmp.txt"); auto pos = std::istream_iterator<std::string>(fin);...
xmllmx's user avatar
  • 44.6k
1 vote
2 answers
101 views

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::...
Oersted's user avatar
  • 3,732
4 votes
1 answer
94 views

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::...
Stégosaure's user avatar
2 votes
2 answers
134 views

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 ...
toliveira's user avatar
  • 1,857
6 votes
1 answer
469 views

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 ) { ...
PkDrew's user avatar
  • 2,281
-1 votes
1 answer
68 views

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 ...
kesarling's user avatar
  • 2,322
1 vote
0 answers
94 views

Why is the output of the below code a reference: foo and not moved: foo? #include <iostream> void process(std::string& v) { std::cout << "reference: " << v <<...
Jacob Krieg's user avatar
  • 3,282
4 votes
3 answers
192 views

#include <iostream> #include <vector> class Car{ public: int weight; Car(int weight): weight(weight){ }; Car(const Car& other){ std::cout<<&...
simply lemon's user avatar
1 vote
0 answers
88 views

I have a very simple fixed-buffer string class. I am targeting embedded and don't want dynamic allocations. I am including it for reference, but the question is more general. template <auto ...
Tomáš Zato's user avatar
  • 53.9k
1 vote
3 answers
91 views

I'm working on a function that converts a json value into an i32, returning an error if any step of the conversion fails. fn json_to_block_height(height: Value) -> Result<i32, RPCError> { ...
PiRK's user avatar
  • 1,105
2 votes
0 answers
103 views

Inspecting the constructor std::vector::vector( size_type count, const T& value, const Allocator& alloc = Allocator() );(ref), we can read that it: Constructs a vector with count copies of ...
Fureeish's user avatar
  • 13.5k
3 votes
1 answer
85 views

I am reading through Programming: Principles and Practice in C++, 4th edition by Stroustrup and I am confused about the output of some code that is intended to illustrate the copy constructor/copy ...
Sprotte's user avatar
  • 201
5 votes
2 answers
474 views

When I have a C++ lambda that captures an object by value, and that object can throw an exception in its copy constructor, clang-tidy will show a warning: warning: an exception may be thrown in ...
oliver's user avatar
  • 6,890
-1 votes
2 answers
223 views

I created a little parser and would like to make the looped part as fast as possible. Thus I would like to avoid copying using move semantics instead. But I can't understand how to combine move ...
Max Cury's user avatar
1 vote
2 answers
112 views

Consider the following scenario. We have a class bar that owns a foo data object via a unique pointer. A bar must always be constructible into a valid state; that is, bar must always own some data, so ...
Involute's user avatar
  • 245
1 vote
1 answer
143 views

In the minimum needed code snippet, in the move assignment, why is the commented line *arg = nullptr; illegal and arg.p = nullptr; okay? If I understand correctly, both are modifying rvalue, yet on ...
Bruno Mraz's user avatar
4 votes
2 answers
261 views

I have a large number of large objects in my program. They are currently stored in an std::set with a customer comparison functor. The set starts empty and I keep emplacing objects into it. I also ...
Alberto Santini's user avatar
3 votes
2 answers
177 views

When exactly does an object cast with std::moved get moved? For instance, does the following code constitute use after move? f(std::move(a), a.Something()) Where f = f(A a, int x) and a is an ...
c z's user avatar
  • 9,356
2 votes
1 answer
468 views

I am curious about the "move semantics" in Rust and whether data is copied when ownership is transferred. Here's some demo code: #[derive(Debug)] struct Foo { name: i32, age: i32, } ...
Archsx's user avatar
  • 1,052
2 votes
0 answers
92 views

Is it an acceptable pattern to return a moved function parameter in case some kind of problem occurred? For example when trying to store data in a database, but validation failed and the data handle ...
Michael's user avatar
  • 958
0 votes
0 answers
67 views

Consider the following code: class Widget { public: Widget() { std::cout << "\nCtor"; } Widget(const Widget& obj) { std::cout << "\nCopy ctor&...
exect's user avatar
  • 1
0 votes
0 answers
110 views

In an answer to this question, under the label: "Why does that work?" , it was noted that: Now, if other is being initialized with an rvalue, it will be move-constructed. Perfect. In the ...
CS Student's user avatar
0 votes
2 answers
139 views

I have a function which takes an rvalue reference: void foo(int&& x); I would like to create another function which supplies a universal interface with the original function: template <...
Arc_Angle's user avatar
1 vote
1 answer
125 views

I see this subject was discussed in StackOverflow, but I could not find the right answer. I've been using C++ for many years, and I am still in doubt about how to write a simple setter method for a ...
Andrey Rubliov's user avatar

1
2 3 4 5
44