slot 0.0.1
A real time UI render framework
载入中...
搜索中...
未找到
YogaEnums.h
浏览该文件的文档.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
10#include <bit>
11#include <iterator>
12#include <type_traits>
13
14namespace facebook::yoga {
15
19template <typename EnumT>
20concept Enumeration = std::is_enum_v<EnumT>;
21
25template <Enumeration EnumT>
26constexpr int32_t ordinalCount();
27
31template <typename EnumT>
32concept HasOrdinality = (ordinalCount<EnumT>() > 0);
33
37template <HasOrdinality EnumT>
38constexpr int32_t bitCount() {
39 return std::bit_width(
40 static_cast<std::underlying_type_t<EnumT>>(ordinalCount<EnumT>() - 1));
41}
42
47constexpr auto to_underlying(Enumeration auto e) noexcept {
48 return static_cast<std::underlying_type_t<decltype(e)>>(e);
49}
50
55template <HasOrdinality EnumT>
56auto ordinals() {
57 struct Iterator {
58 EnumT e{};
59
60 EnumT operator*() const {
61 return e;
62 }
63
64 Iterator& operator++() {
65 e = static_cast<EnumT>(to_underlying(e) + 1);
66 return *this;
67 }
68
69 bool operator==(const Iterator& other) const = default;
70 };
71
72 struct Range {
73 Iterator begin() const {
74 return Iterator{};
75 }
76 Iterator end() const {
77 return Iterator{static_cast<EnumT>(ordinalCount<EnumT>())};
78 }
79 };
80
81 return Range{};
82}
83
84} // namespace facebook::yoga
Definition YogaEnums.h:20
Definition YogaEnums.h:32
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.hpp:14737
Definition Benchmark.cpp:19
constexpr int32_t bitCount()
Definition YogaEnums.h:38
constexpr auto to_underlying(Enumeration auto e) noexcept
Definition YogaEnums.h:47
auto ordinals()
Definition YogaEnums.h:56
constexpr int32_t ordinalCount()
__inline__ __device__ uint3 operator*(uint3 a, dim3 b)
Definition slang-cuda-prelude.h:4314