Questions tagged [reference-wrapper]
107 questions
1
vote
1 answer
std variant and forward declarations
It's my understanding that std::variant cannot directly hold references.
However, std::reference_wrapper is a fully qualified type that can be put into things like std::vector, and since one can make a vector of reference wrappers, I imagined that…

markt1964
- 2,638
- 2
- 22
- 54
1
vote
2 answers
runtime polymorphic invocation of pure virtual function via std::reference_wrapper behaving inconsistently
I present to you this code riddle:
Using this compiler:
user@bruh:~/test$ g++ --version
g++ (Ubuntu 7.3.0-16ubuntu3) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is…

MK-Ultra-
- 11
- 2
1
vote
1 answer
Design concerning std::reference_wrapper removals
I am trying to use std::reference_wrapper on all elements of another vector. But when I delete the original element, I want to automatically delete the element in the vector of references. I did some workarounds but they're ugly. Any…

user1000
- 79
- 2
- 9
1
vote
1 answer
ROS subscribe callback - using boost::bind with member functions
I'm trying to subscribe to different topics in ROS (one for every vehicle that pops up) using the same callback for all of them. The idea is that boost::bind will pass the topic name as an additional argument so I know which vehicle I should access…

Pronex
- 274
- 3
- 14
1
vote
4 answers
Passing references to a variadic-templates use the std::reference-wrapper
I try to pass to a variadic template function a list of references and pass it to another function. The code that I wrote is the following:
template
void fun(cv::Point_ & pt) { pt.x++; pt.y++; }
template
void…

thewoz
- 499
- 2
- 4
- 23
1
vote
1 answer
reference_wrapper to abstract class serialization in boost
I must serialize in Boost vector (or any other container) of abstract class.
Because it is impossible to create vector of abstract class directly, I created vector of reference_wrapper's to this abstract class.
But how to serialize in Boost…
user4334597
1
vote
1 answer
std::reference_wrapper on MS Visual Studio 2013
I try to compile some code which is very similar to:
#include
#include
class A{
};
int main(int argc, char* argv[]){
std::unordered_map> stringToRef;
A a;
const A& b = a;
…

Constantin
- 8,721
- 13
- 75
- 126
1
vote
2 answers
Using reference_wrapper as condition_variable predicate
Note: The following applies equally to Boost.Thread and C++11 threads.
I have a condition variable which condition is actually a simple boolean variable.
// assume these are global
mutex m;
condition_variable c;
boolean b = false;
I wanted to use…

jdehesa
- 58,456
- 7
- 77
- 121
1
vote
1 answer
reference_wrapper does not change addresses accordingly
This question is an extension of this question. I understand that due to push_back() new memory allocation takes place and the address of the first element of std::vector v changes but should not std::vector v2 change its address…

Shibli
- 5,879
- 13
- 62
- 126
0
votes
2 answers
How to save an object inside another object in C++
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();
private:
int counter = 0;
};
I want to pass an…

heyloo
- 35
- 3
0
votes
2 answers
C2676 error with reference_wrapper and custom class
I am working on my C++ home-project and got into trouble with the following C2676 error:
binary '==': 'std::reference_wrapper' does not define this operator or a conversion to a type acceptable to the predefined operator
I have this in…

Sarungard
- 1
- 1
0
votes
0 answers
how to initialize a vector member variable of reference_wrapper inside a class?
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::vector vec) :vec_r(begin(vec), end(vec)) //…

Arun AC
- 417
- 7
- 17
0
votes
1 answer
How to correctly resize a complex vector?
I have a class like so:
class A {
std::vector<
std::vector<
std::pair<
uint32_t, std::reference_wrapper>>>>
table;
};
In the constructor of the class I resize the vector, like so…

Fotiadis M.
- 95
- 1
- 12
0
votes
0 answers
Using std::ref, content does not change after exiting function
I have been implementing Strassen algorithm with threads. I have passed data to threads by structures and launching them by function pthread_create() . The problem is I'm operating on std::vector < std::vector > and I can't pass this to…

kjtn99
- 51
- 1
- 8
0
votes
1 answer
non-template std::reference_wrapper assignment operator and template constructor
In the C++ 20 Standard the constructor of the class template std::reference_wrapper is a template.
template
constexpr reference_wrapper(U&&) noexcept(see below );
while the assignment operator is not a template
constexpr…

Vlad from Moscow
- 301,070
- 26
- 186
- 335