From c730fc8ae879a46fbe46aa982c12a9e202ad4198 Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Mon, 19 Oct 2020 08:07:45 +0300 Subject: [PATCH] Document _to_index, _from_index, etc. Follow-on to #59. [skip ci] --- doc/ApiReference.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/doc/ApiReference.md b/doc/ApiReference.md index ce035af..f764bbc 100644 --- a/doc/ApiReference.md +++ b/doc/ApiReference.md @@ -370,6 +370,34 @@ constants. +### Index lookup + +#### member constexpr std::size_t _to_index() const + +Returns the index of a Better Enum value within its enum declaration. The index +is determined from the value only; if two constants in the declaration have the +same value, this function may return the index of either constant. + +If the value does not correspond to any constant in the declaration (for +example, if it was obtained using an unchecked conversion or a cast), then the +behavior of `value._to_index` is undefined. + +#### static constexpr Enum _from_index(size_t) + +Returns the value of the constant with the given index. Throws +`std::runtime_error` if not given the index of one of the constants. + +#### static constexpr Enum _from_index_unchecked(size_t) + +Returns the value of the constant with the given index. If not given one of the +constants in the declaration of the enum, the returned value is undefined. + +#### static constexpr optional _from_index_nothrow(size_t) + +Returns the value of the constant with the given index. + + + ### Stream operators #### non-member std::ostream& operator <<(std::ostream&, const Enum&)