Questions tagged [reference-wrapper]
107 questions
0
votes
1 answer
const correctness for custom reference wrapper
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 and reporting errors when the structure does not…

tsuki
- 907
- 4
- 17
0
votes
1 answer
std::ref implicit conversion to reference confusion
I know that a std::ref(object) creates a std::reference_wrapper(object), and that std::reference_wrapper has a non-explicit type conversion operator member function
operator T&() const
and I know that this influences how I use it when template…

Luca
- 1,658
- 4
- 20
- 41
0
votes
2 answers
Const correctness of STL library with reference-wrapper?
I have the following class:
class Data;
class A
{
public:
A(Data& _data) : data(_data) {}
Data& getData() {return data;}
const Data& getData() const {return data;}
private:
Data& data;
};
Now imagine I need to keep not one, but…

Jakub Zaverka
- 8,816
- 3
- 32
- 48
0
votes
2 answers
Initializing vector with reference_wrapper's locally
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 to initialize such a container when the values,…

Student4K
- 916
- 2
- 9
- 20
0
votes
1 answer
Initializing vector with reference_wrappers
I am trying to run an example with vector of reference wrappers, but run into compilation error at the vector variable declaration. Here is the code:
#include
#include
#include
using namespace std;
struct Base
{
…

Student4K
- 916
- 2
- 9
- 20
0
votes
2 answers
how to obtain a C array from an std::vector
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 shuffles the elements contained in a standard…

Marco Randazzo
- 19
- 2
0
votes
1 answer
How to pass data to reference wrapper
Consider following piece of code:
//option no 1
struct foo{
foo(baz &b) : _b(b){}
std::reference_wrapper _b;
};
//option no 2
struct bar{
bar(std::reference_wrapper b) : _b(b){}
std::reference_wrapper _b;
};
I am…

bartop
- 9,971
- 1
- 23
- 54
0
votes
1 answer
Accessing class members using reference_wrapper instead of standard pointers in C++11
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 std::reference_wrapper would be cleaner, but can't…

Simon Woodward
- 1,946
- 1
- 16
- 24
0
votes
1 answer
`push_back` to `vector< reference_wrapper >` cause string at index 0 to be empty
I have two classes which is a direct inheritance with no override, so they are basically: vector list and vector< reference_wrapper > filtered. The idea is I want to store all values into list and then fill the filtered with selected…

T.N.
- 33
- 8
0
votes
1 answer
Serialization of non default constructible and std::reference wrapper alternatives
I tried serialising my (neural) network and am currently stuck-ish.
The issue seems to be that you can't serialize a std::reference_wrapper. I am unsure whether I should either change the way the references to the upper nodes are stored or come up…

Gladaed
- 211
- 1
- 8
0
votes
1 answer
What does it mean to "unwrap" a reference_wrapper?
I am writing a utility class to "unwrap" a std::reference_wrapper, but I'm a bit conflicted as to what this means.
boost::unwrap_reference::type is defined as U (where T is std::reference_wrapper), but this seems counterintuitive. If a…

monkey0506
- 2,489
- 1
- 21
- 27
0
votes
1 answer
error: no matching function for call to 'std::reference_wrapper::reference_wrapper()
Book and Article are derived classes from Medium.
Why am I getting this error when trying to insert Medium / Book / Article in the bibliography?
error: no matching function for call to…

Gicu Mironica
- 585
- 8
- 22
0
votes
1 answer
vector of reference wrapper, push_back failure?
I have a problem that is giving me trouble; my goal is to create an octree.
Actually, it's very cheap (but it's nearly enough for what I want to do with that octree).
My problem is that my std::vector> is filled with…

Raph Schim
- 528
- 7
- 30
0
votes
1 answer
C++ how to use vector of reference_wrapper
I am totally new to reference_wrapper, so I need a very simple example to understand, please.
I declare two vectors:
std::vector vec;
std::vector> vec_r;
I fill vec with some values, then I want vec_r to store…

Hybridslinky
- 131
- 1
- 13
0
votes
2 answers
std::reference_wrapper and polymorphic containers
I am trying to make a polymorphic vector using std::reference_wrapper for these classes:
struct Int2TypeBase{
virtual void which(){ std::cout << "Int2TypeBase" << "\n";}
};
template
struct Int2Type : public Int2TypeBase
{
enum
…

lo tolmencre
- 3,804
- 3
- 30
- 60