Boost logo

Boost :

Subject: Re: [boost] [review] Review of Outcome (starts Fri-19-May)
From: Peter Dimov (lists_at_[hidden])
Date: 2017-05-16 23:34:51


Gavin Lambert wrote:
> Future uses "T get()". This is established standard.
> Smart pointers use "T* get()", which is equivalent to the above. Also
> standard.
> Boost Optional uses "T& get()" (although also provides value(), presumably
> for standard compatibility).
>
> Std Optional uses "T value()". This is either still experimental or
> approved for C++17; I'm not entirely sure how far along that is.

It's in C++17.

> The different interfaces of the above seem unfortunate (and Std Optional
> seems incorrect in this regard to me).
>
> So why not "T get()"? That's much more consistent with other types.

.get() is when you only have one thing to get; it's for one-element
containers, where there's no ambiguity as to what is being got.

expected<T, E> and friends have two; the value is .value() and the error is
.error(), with their matching queries has_value() and has_error().

It's not that get() is unacceptably wrong, but the
value/has_value/error/has_error convention is legitimate and consistent.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk