Skip to content

Commit

Permalink
RichEnum::value_of() - Return OptionalReference
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkaratarakis committed Sep 15, 2024
1 parent 318ce28 commit ba7bb88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ cc_library(
strip_include_prefix = strip_include_prefix_config(),
deps = [
":assert_or_abort",
":optional_reference",
"@com_github_neargye_magic_enum//:magic_enum",
],
copts = ["-std=c++20"],
Expand Down
18 changes: 10 additions & 8 deletions include/fixed_containers/enum_utils.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "fixed_containers/assert_or_abort.hpp"
#include "fixed_containers/optional_reference.hpp"

#include <magic_enum.hpp>

Expand Down Expand Up @@ -501,22 +502,23 @@ class SkeletalRichEnumLite
using InfusedData = typename InfusedDataProvider::DataType;

public:
static constexpr std::optional<std::reference_wrapper<const RichEnumType>> value_of(
const std::string_view& name)
static constexpr OptionalReference<const RichEnumType> value_of(const std::string_view& name)
{
return rich_enums_detail::value_of<RichEnumType>(name);
return rich_enums_detail::value_of<RichEnumType, OptionalReference<const RichEnumType>>(
name);
}

static constexpr std::optional<std::reference_wrapper<const RichEnumType>> value_of(
const BackingEnum& backing_enum)
static constexpr OptionalReference<const RichEnumType> value_of(const BackingEnum& backing_enum)
{
return rich_enums_detail::value_of<RichEnumType>(backing_enum);
return rich_enums_detail::value_of<RichEnumType, OptionalReference<const RichEnumType>>(
backing_enum);
}

static constexpr std::optional<std::reference_wrapper<const RichEnumType>> value_of(
static constexpr OptionalReference<const RichEnumType> value_of(
std::underlying_type_t<BackingEnum> enum_integer)
{
return rich_enums_detail::value_of<RichEnumType>(enum_integer);
return rich_enums_detail::value_of<RichEnumType, OptionalReference<const RichEnumType>>(
enum_integer);
}

protected:
Expand Down

0 comments on commit ba7bb88

Please sign in to comment.