3 ms·
In all seriousness, reference_wrapper lets you: 1. Have a container of non-null references. As the example in your cppreference link shows, that’s convenient f
by evincarofautumn 9y ago
In all seriousness, reference_wrapper lets you:
1. Have a container of non-null references. As the example in your cppreference link shows, that’s convenient for efficiently providing multiple “views” of the same values.
2. Pass a value with reference semantics to a function that takes an argument by value. Mainly useful to avoid copying or reuse a function object.
3. Explicitly say “this is a reference to something I don’t own”, complementing unique_ptr’s “reference to something I own exclusively”, shared_ptr’s “reference to something I share ownership of”, and raw pointers’ “reference to something I may or may not own”.