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

Im wondering if there is a better, more typesafe, way to return "a selection" than I do at the moment. If we only ever have one selected element at a time, we can just return a reference, ...
darune's user avatar
  • 11.5k
0 votes
2 answers
98 views

I have multiple child classes derived of a parent class. I would like to resolve one of the static fields of one of the child classes, based on a parameter that is unique across the children through a ...
Gábor DANI's user avatar
  • 2,135
0 votes
1 answer
107 views

Consider following snippet: #include <bits/stdc++.h> using namespace std; int main() { int x=3; int y=1; int z=2; cout<<(&x)<<' '<<(&y)<<' '<&...
Rupa's user avatar
  • 110
1 vote
1 answer
114 views

I have a function that accepts N position vectors and updates them: using Vector3r = Eigen::Matrix<Real, 3, 1, Eigen::DontAlign>; template<unsigned int N> using Vectorr = Eigen::Matrix<...
Sin3point14's user avatar
2 votes
1 answer
547 views

What happens to a std::reference_wrapper if the reference used to create it goes out of scope? Can it still still provide access to the underlying object (which would still exist), or would it be ...
Chris's user avatar
  • 23
0 votes
2 answers
135 views

I have 2 classes lets say Class A and Class B, class A { public: A(B b); B GetB(); private: B b; }; class B { public: B(); void IncrementCounter(); int GetCounter(); ...
heyloo's user avatar
  • 37
3 votes
0 answers
483 views

std::reference_wrapper is a standard library that wraps a reference in a copyable, assignable object. My view is that it has a weird design and seems like a hack to trick classes that store objects by ...
alfC's user avatar
  • 16.8k
0 votes
0 answers
310 views

How to initialize a vector of reference_wrapper member variable in a class. I have tried to initialize with a vector in constructor initialisation_list. class Test { public: Test(std::...
Arun AC's user avatar
  • 417
4 votes
1 answer
1k views

From my understanding, reference wrapper is just a wrapper on reference, nothing too special about it. But why it is treated as the reference itself (rather than the wrapper) inside the function when ...
yuhao's user avatar
  • 91
3 votes
2 answers
176 views

Recently, I've decided to write a class storing a variant with reference_wrapper<const vector> and vector for having a choice either to own the value or having only a reference of it. That is, ...
koleydoscope's user avatar
1 vote
1 answer
459 views

I am a bit stuck on this, I'm using a std::array to store reference wrappers to vectors. I was trying to sort these by the vector's size using std::sort but am unable for reasons I am not quite sure ...
VevsVire's user avatar
3 votes
1 answer
496 views

I was trying out the std::reference_wrapper with the following snippet int a = 42, b = 52; std::tuple<std::reference_wrapper<int>> t = std::make_tuple(std::ref(a)); std::get<0>(t) = ...
YHC's user avatar
  • 88
2 votes
1 answer
1k views

I've fallen over a bad assumption that I made. I discovered that std::pair<int &, int &> is a thing. However I didn't expect the following to fail int a = 10; int b = 20; int c = 30; ...
bradgonesurfing's user avatar
1 vote
0 answers
41 views

I've noticed the implementation of std::reference_wrapper in C++11, however, I'm wondering why I should use the std::reference_wrapper instead of a "raw" reference variable. I've understood ...
Evethir's user avatar
  • 41
1 vote
1 answer
659 views

#include <vector> #include <array> int main() { typedef std::array<int,2> point; typedef std::vector<std::reference_wrapper<point>> route; std::vector<...
yushizhao's user avatar
  • 861
0 votes
1 answer
61 views

I'm using boost::variant to implement type erasure when sending data across network. When the data arrives to the client or server, I'm inspecting its structure to retrieve the underlying information ...
tsuki's user avatar
  • 907
1 vote
2 answers
488 views

I'm trying to use reference wrappers in C++, since I want to be able to directly alter objects' values, but their values are all wrong. Here's an example that demonstrates this problem: #include <...
Jason's user avatar
  • 386
3 votes
1 answer
640 views

I found out the nice tool provided by std::reference_wrapper, but this behaviour sounds weird to me. #include <iostream> #include <string> #include <algorithm> #include <...
Luca Jungla's user avatar
4 votes
1 answer
280 views

I recently learnt that std::reference_wrapper<T> has an overload for the the function call operator in case T is function-like. I wonder whether there is a reason given by the standard committee ...
Albjenow's user avatar
  • 379
4 votes
1 answer
735 views

I'm currently work on a large code project and wanted to take the opportunity to learn about and use namespaces. All of the classes I've defined reside within a single namespace, Test. One of my ...
user avatar
0 votes
2 answers
801 views

I have a number of inheritance-related types that I want to use from standard container (std::reference_wrapper is a proper value type for such a container, AFAIU). However, I do not understand, how ...
Student4K's user avatar
  • 960
10 votes
2 answers
748 views

Consider the case in which I've enough storage to host a void * and therefore to construct in-place a pointer. Is there any guarantee that the same storage is big enough to always store also an std::...
skypjack's user avatar
  • 50.9k
0 votes
2 answers
168 views

I'm new to C++11 and I'm confused about the usage of std::refence_wrapper class. let's consider the example shown in https://en.cppreference.com/w/cpp/utility/functional/reference_wrapper ,which ...
Marco Randazzo's user avatar
0 votes
1 answer
856 views

I am trying to build an unordered_map to vector variables which are members of my class. I can do this using standard pointers * but this requires the use of (*x) to access the vector. I wondered if ...
Simon Woodward's user avatar
2 votes
1 answer
553 views

I was reading up on r-value references and move semantics. Experimenting this with std::function and std::reference_wrapper unfortunately confused me a bit more. #include <iostream> #include &...
xworder's user avatar
  • 111