Search code examples
c++c++11reference-wrapper

Comparing addresses of reference_wrappers


How can I compare two std::reference_wrappers by the references they hold? I want to see if the references of two std::reference_wrappers are equal or not.

Edit: Sorry from confusion. I meant how to get the addresses of referents and compare them.


Solution

  • The get() member function returns a reference to the element referred to. You can then take the addresses of the referents directly.

    std::addressof(r1.get()) == std::addressof(r2.get())