// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef MOJO_PUBLIC_CPP_BINDINGS_ENUM_UTILS_H_ #define MOJO_PUBLIC_CPP_BINDINGS_ENUM_UTILS_H_ #include <optional> #include <type_traits> #include "base/numerics/safe_conversions.h" namespace mojo { // Converts |int_value| to |TMojoEnum|. If |int_value| represents a known enum // value, then a corresponding |TMojoEnum| value will be returned. Returns // |std::nullopt| otherwise. // // Using base::StrictNumeric as the parameter type prevents callers from // accidentally using an implicit narrowing conversion when calling this // function (e.g. calling it with an int64_t argument, when the enum's // underlying type is int32_t). template <typename TMojoEnum> std::optional<TMojoEnum> ConvertIntToMojoEnum( base::StrictNumeric<int32_t> int_value) { … } } // namespace mojo #endif // MOJO_PUBLIC_CPP_BINDINGS_ENUM_UTILS_H_