dimanche 25 avril 2021

Remove duplication in equivalent const and non-const members when returning optional reference by value

This answer explains how to remove duplication in equivalent const and non-const member functions which return by reference. It doesn't help, however, in the case where your function returns an optional reference to another type. Is there a solution for this case? E.g.,

class Foo {
    const boost::optional<const Bar&> get_bar() const;
    boost::optional<Bar&> get_bar();
}

Aucun commentaire:

Enregistrer un commentaire