Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Optional references
PrevUpHomeNext

This library allows the template parameter T to be of reference type: T&, and to some extent, T const&.

However, since references are not real objects some restrictions apply and some operations are not available in this case:

  • Converting constructors
  • Converting assignment
  • InPlace construction
  • InPlace assignment
  • Value-access via pointer

Also, even though optional<T&> treats it wrapped pseudo-object much as a real value, a true real reference is stored so aliasing will ocurr:

  • Copies of optional<T&> will copy the references but all these references will nonetheless reefer to the same object.
  • Value-access will actually provide access to the referenced object rather than the reference itself.

PrevUpHomeNext