bloaty/third_party/abseil-cpp/absl/random/internal/traits.h
Go to the documentation of this file.
1 // Copyright 2017 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ABSL_RANDOM_INTERNAL_TRAITS_H_
16 #define ABSL_RANDOM_INTERNAL_TRAITS_H_
17 
18 #include <cstdint>
19 #include <limits>
20 #include <type_traits>
21 
22 #include "absl/base/config.h"
23 
24 namespace absl {
26 namespace random_internal {
27 
28 // random_internal::is_widening_convertible<A, B>
29 //
30 // Returns whether a type A is widening-convertible to a type B.
31 //
32 // A is widening-convertible to B means:
33 // A a = <any number>;
34 // B b = a;
35 // A c = b;
36 // EXPECT_EQ(a, c);
37 template <typename A, typename B>
38 class is_widening_convertible {
39  // As long as there are enough bits in the exact part of a number:
40  // - unsigned can fit in float, signed, unsigned
41  // - signed can fit in float, signed
42  // - float can fit in float
43  // So we define rank to be:
44  // - rank(float) -> 2
45  // - rank(signed) -> 1
46  // - rank(unsigned) -> 0
47  template <class T>
48  static constexpr int rank() {
49  return !std::numeric_limits<T>::is_integer +
50  std::numeric_limits<T>::is_signed;
51  }
52 
53  public:
54  // If an arithmetic-type B can represent at least as many digits as a type A,
55  // and B belongs to a rank no lower than A, then A can be safely represented
56  // by B through a widening-conversion.
57  static constexpr bool value =
58  std::numeric_limits<A>::digits <= std::numeric_limits<B>::digits &&
59  rank<A>() <= rank<B>();
60 };
61 
62 // unsigned_bits<N>::type returns the unsigned int type with the indicated
63 // number of bits.
64 template <size_t N>
65 struct unsigned_bits;
66 
67 template <>
68 struct unsigned_bits<8> {
69  using type = uint8_t;
70 };
71 template <>
72 struct unsigned_bits<16> {
73  using type = uint16_t;
74 };
75 template <>
76 struct unsigned_bits<32> {
77  using type = uint32_t;
78 };
79 template <>
80 struct unsigned_bits<64> {
81  using type = uint64_t;
82 };
83 
84 #ifdef ABSL_HAVE_INTRINSIC_INT128
85 template <>
86 struct unsigned_bits<128> {
87  using type = __uint128_t;
88 };
89 #endif
90 
91 template <typename IntType>
92 struct make_unsigned_bits {
93  using type = typename unsigned_bits<std::numeric_limits<
95 };
96 
97 } // namespace random_internal
99 } // namespace absl
100 
101 #endif // ABSL_RANDOM_INTERNAL_TRAITS_H_
uint16_t
unsigned short uint16_t
Definition: stdint-msvc2008.h:79
absl::random_internal::unsigned_bits< 64 >::type
uint64_t type
Definition: abseil-cpp/absl/random/internal/traits.h:108
absl::random_internal::make_unsigned_bits::type
typename unsigned_bits< std::numeric_limits< typename MakeUnsigned< IntType >::type >::digits >::type type
Definition: abseil-cpp/absl/random/internal/traits.h:129
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
absl::random_internal::unsigned_bits
Definition: abseil-cpp/absl/random/internal/traits.h:92
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
absl::random_internal::unsigned_bits< 32 >::type
uint32_t type
Definition: abseil-cpp/absl/random/internal/traits.h:104
absl::random_internal::unsigned_bits< 8 >::type
uint8_t type
Definition: abseil-cpp/absl/random/internal/traits.h:96
absl::random_internal::is_widening_convertible::value
static constexpr bool value
Definition: abseil-cpp/absl/random/internal/traits.h:59
absl::random_internal::unsigned_bits< 16 >::type
uint16_t type
Definition: abseil-cpp/absl/random/internal/traits.h:100
absl::random_internal::is_widening_convertible::rank
static constexpr int rank()
Definition: bloaty/third_party/abseil-cpp/absl/random/internal/traits.h:48
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:40