Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
2 votes
1 answer
122 views

I have a function of the form void foo(std::string str); I want to use it in two scenarios: send a copy of the original value to it: std::string myString = "any data that I want to keep in its ...
altchist's user avatar
5 votes
1 answer
164 views

If we have an initialized std::vector std::vector<T> v = ...; then construct a span into that vector std::span<T> s = std::span<T>(v.begin(), 10); and then move the original vector ...
bradgonesurfing's user avatar
0 votes
0 answers
125 views

I played with a snippet of code below and had it compiled by GCC to compare std::move vs RVO( return value optimization ) #include <iostream> #include <chrono> #include <array> #...
PkDrew's user avatar
  • 2,301
1 vote
2 answers
197 views

I was reading up on rvalues and ran into something while trying a code snippet on compiler explorer. Here's a contrived example: class A { public: A&& func(A& rhs) { //...
san216's user avatar
  • 95
-1 votes
2 answers
231 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
2 votes
1 answer
166 views

#include <iostream> #include <vector> #include <utility> // simple user-defined class class MyClass { public: MyClass(int val) : value(val) {} private: int value; }; int ...
Mathieu's user avatar
  • 332
2 votes
2 answers
164 views

In the case of the example below Implicitly, the move constructor and move assignment operator are not created. I knew. So, are the copy constructor and copy assignment operator generated? Is the ...
tux Neoh's user avatar
1 vote
0 answers
41 views

I want to be able to initialize a class that holds a boost::container::flat_map<std::string, std::unique_ptr<AbstractBaseClass>> in the constructor. Example: class MapHolder { public: ...
bustus_primus's user avatar
1 vote
1 answer
128 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
0 votes
0 answers
174 views

While working on my own array types, I encountered this issue, where one of my unit tests passes for Clang, but fails on MSVC with the following messages: error C7595: 'UnitTest': call to immediate ...
BeigeAlert's user avatar
0 votes
0 answers
55 views

I'm trying to understand which is the most optimized way to pass arguments to functions. I got the answer for the book professional c++ but during some test I ran into a weird behavior. It's clear ...
DarioZ's user avatar
  • 29
0 votes
1 answer
117 views

This is a Josephus Permutation problem, it was solved by using std::move(), but now I have to switch to using std::move_iterator (by using std::make_move_iterator()) However, this doesn't compile: ...
Pavel Sh's user avatar
1 vote
1 answer
424 views

I'm actually working to delete most of my copy constructor/assignation, and I faced an issue when comming to lambda use: ThreadPool: using Task = std::function<void()>; template<size_t S> ...
DipStax's user avatar
  • 572
0 votes
1 answer
87 views

If I'm constructing a non-trivial container like a custom map for example, and want to share code between the emplace and insert functions, one approach would be to have the insert function simply ...
metamorphosis's user avatar
5 votes
1 answer
219 views

In the MSVC STL, the implementation of std::apply is as follows: template <class _Callable, _Tuple_like _Tuple, size_t... _Indices> constexpr decltype(auto) _Apply_impl(_Callable&& _Obj, ...
LeiXiangyu's user avatar

15 30 50 per page
1
2 3 4 5
10