Return value of non-initialized reference_wrapper

Shibli

Where does reference_wrapper point to when I resize() the vector below? Is this an undefined behavior? What should I do for safety?

std::vector < std::reference_wrapper <int> > vec;
vec.resize(10);
ecatmur

Your code doesn't compile, because reference_wrapper doesn't have a default constructor.

error: no matching function for call to ‘std::reference_wrapper<int>::reference_wrapper()’

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Can a function return a value that is initialized in it?

How is it possible to Lerp from a non initialized value to an initialized value?

Value of a non-initialized variable in C++

How to return an initialized value in user control to the form

Assign a reference return value to a non-reference variable

Enum initialized with a non-existent rawValue does not fail and return nil

unordered_map value assignation when value type is reference_wrapper

Why r-value reference to pointer to const initialized with pointer to non-const doesn't create an temporary and bind it with it?

Return constant reference from non-const function return reference value

Why is returning a non-initialized value considered undefined behavior?

Flutter using ".withOpacity" leads to "the field is initialized with a non constant value"

Why is Unity ignoring the initialized value of a non-static public field?

Is it possible within a function to get the memory address of the variable initialized by the return value?

Why non const reference cannot be initialized to an object of different type?

reference_wrapper: Is this UB?

take nullable and return non-nullable reference and value types in single method

Delphi return value by reference

Return value or rvalue reference?

Constructor initialized by function return

Return the first non empty/blank value?

return first non NaN value in python list

unexpected non void return value in void function

C initialized and non initialized array with variable size

return a const and non const wrapper object

Reference to const T initialized by value of type other than T

Does return an address ensures non-NULL return value?

Kotlin property declared as non-nullable is nullable even if it has initialized value

modifying the value of a non static variable which was initialized with a static variable modifies the static variable as well

Can't define the 'const' constructor because the field 'currentUser' is initialized with a non-constant value