Wrapper<int&> with std::remove_reference_t

joboc
13.3K views
undefined

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content
#include <iostream>
#include <type_traits>
template<typename T>
class Wrapper
{
public:
Wrapper(T const& value) : value_(value) {}
std::remove_reference_t<T> const& get() const { return value_; }
private:
T value_;
};
int main()
{
using IntRefWrapper = Wrapper<int&>;
int a = 42;
IntRefWrapper intRefWrapper(a);
intRefWrapper.get() = 43;
std::cout << "a is now " << a << '\n';
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content