Topic: Why std::optional has checked and unchecked access,


Author: Oleksandr Pikozh <o.pikozh@gmail.com>
Date: Tue, 16 Jan 2018 08:33:44 +0200
Raw View
In std::optional we have:
- operator* =E2=80=94 doesn't check whether an optional contains a value;
- method value =E2=80=94 throws std::bad_optional_access when an optional=
=20
doesn't contain a value.

In std::vector we have:
- operator[] =E2=80=94 doesn't check whether a vector contains specified in=
dex;
- method at =E2=80=94 throws std::out_of_range when a vector doesn't contai=
n=20
specified index.

In std::variant we have:
- ??? =E2=80=94 doesn't check whether a variant contains specified index/ty=
pe;
- method get =E2=80=94 throws std::bad_variant_access when a variant doesn'=
t=20
contain specified index/type.

Why we don't have any fast (unchecked) ways to access std::variant?=20
Assuming context when user has already checked for presence of required=20
item somehow and now needs the fastest access (i.e. he agrees to get UB=20
when absent).

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/959f20d3-0455-951d-70fe-60bf0110cad7%40gmail.com=
..

.