No public description
PiperOrigin-RevId: 589279414
This commit is contained in:
parent
faae68e81d
commit
4e78e645d0
|
@ -31,14 +31,14 @@
|
||||||
// A StrongInt<T> with a NullStrongIntValidator should compile away to a raw T
|
// A StrongInt<T> with a NullStrongIntValidator should compile away to a raw T
|
||||||
// in optimized mode. What this means is that the generated assembly for:
|
// in optimized mode. What this means is that the generated assembly for:
|
||||||
//
|
//
|
||||||
// int64 foo = 123;
|
// int64_t foo = 123;
|
||||||
// int64 bar = 456;
|
// int64_t bar = 456;
|
||||||
// int64 baz = foo + bar;
|
// int64_t baz = foo + bar;
|
||||||
// constexpr int64 fubar = 789;
|
// constexpr int64_t fubar = 789;
|
||||||
//
|
//
|
||||||
// ...should be identical to the generated assembly for:
|
// ...should be identical to the generated assembly for:
|
||||||
//
|
//
|
||||||
// DEFINE_STRONG_INT_TYPE(MyStrongInt, int64);
|
// DEFINE_STRONG_INT_TYPE(MyStrongInt, int64_t);
|
||||||
// MyStrongInt foo(123);
|
// MyStrongInt foo(123);
|
||||||
// MyStrongInt bar(456);
|
// MyStrongInt bar(456);
|
||||||
// MyStrongInt baz = foo + bar;
|
// MyStrongInt baz = foo + bar;
|
||||||
|
@ -97,6 +97,7 @@
|
||||||
#ifndef MEDIAPIPE_DEPS_STRONG_INT_H_
|
#ifndef MEDIAPIPE_DEPS_STRONG_INT_H_
|
||||||
#define MEDIAPIPE_DEPS_STRONG_INT_H_
|
#define MEDIAPIPE_DEPS_STRONG_INT_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
@ -179,11 +180,11 @@ struct NullStrongIntValidator {
|
||||||
}
|
}
|
||||||
// Verify lhs << rhs.
|
// Verify lhs << rhs.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static void ValidateLeftShift(T lhs, int64 rhs) { /* do nothing */
|
static void ValidateLeftShift(T lhs, int64_t rhs) { /* do nothing */
|
||||||
}
|
}
|
||||||
// Verify lhs >> rhs.
|
// Verify lhs >> rhs.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static void ValidateRightShift(T lhs, int64 rhs) { /* do nothing */
|
static void ValidateRightShift(T lhs, int64_t rhs) { /* do nothing */
|
||||||
}
|
}
|
||||||
// Verify lhs & rhs.
|
// Verify lhs & rhs.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -224,8 +225,8 @@ class StrongInt {
|
||||||
//
|
//
|
||||||
// Example: Assume you have two StrongInt types.
|
// Example: Assume you have two StrongInt types.
|
||||||
//
|
//
|
||||||
// DEFINE_STRONG_INT_TYPE(Bytes, int64);
|
// DEFINE_STRONG_INT_TYPE(Bytes, int64_t);
|
||||||
// DEFINE_STRONG_INT_TYPE(Megabytes, int64);
|
// DEFINE_STRONG_INT_TYPE(Megabytes, int64_t);
|
||||||
//
|
//
|
||||||
// If you want to be able to (explicitly) construct an instance of Bytes from
|
// If you want to be able to (explicitly) construct an instance of Bytes from
|
||||||
// an instance of Megabytes, simply define a converter function in the same
|
// an instance of Megabytes, simply define a converter function in the same
|
||||||
|
@ -337,12 +338,12 @@ class StrongInt {
|
||||||
value_ %= arg;
|
value_ %= arg;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
StrongInt &operator<<=(int64 arg) { // NOLINT(whitespace/operators)
|
StrongInt &operator<<=(int64_t arg) { // NOLINT(whitespace/operators)
|
||||||
ValidatorType::template ValidateLeftShift<ValueType>(value_, arg);
|
ValidatorType::template ValidateLeftShift<ValueType>(value_, arg);
|
||||||
value_ <<= arg;
|
value_ <<= arg;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
StrongInt &operator>>=(int64 arg) { // NOLINT(whitespace/operators)
|
StrongInt &operator>>=(int64_t arg) { // NOLINT(whitespace/operators)
|
||||||
ValidatorType::template ValidateRightShift<ValueType>(value_, arg);
|
ValidatorType::template ValidateRightShift<ValueType>(value_, arg);
|
||||||
value_ >>= arg;
|
value_ >>= arg;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -378,19 +379,19 @@ std::ostream &operator<<(std::ostream &os,
|
||||||
return os << arg.value();
|
return os << arg.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provide the << operator, primarily for logging purposes. Specialized for int8
|
// Provide the << operator, primarily for logging purposes. Specialized for
|
||||||
// so that an integer and not a character is printed.
|
// int8_t so that an integer and not a character is printed.
|
||||||
template <typename TagType, typename ValidatorType>
|
template <typename TagType, typename ValidatorType>
|
||||||
std::ostream &operator<<(std::ostream &os,
|
std::ostream &operator<<(std::ostream &os,
|
||||||
StrongInt<TagType, int8, ValidatorType> arg) {
|
StrongInt<TagType, int8_t, ValidatorType> arg) {
|
||||||
return os << static_cast<int>(arg.value());
|
return os << static_cast<int>(arg.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provide the << operator, primarily for logging purposes. Specialized for
|
// Provide the << operator, primarily for logging purposes. Specialized for
|
||||||
// uint8 so that an integer and not a character is printed.
|
// uint8_t so that an integer and not a character is printed.
|
||||||
template <typename TagType, typename ValidatorType>
|
template <typename TagType, typename ValidatorType>
|
||||||
std::ostream &operator<<(std::ostream &os,
|
std::ostream &operator<<(std::ostream &os,
|
||||||
StrongInt<TagType, uint8, ValidatorType> arg) {
|
StrongInt<TagType, uint8_t, ValidatorType> arg) {
|
||||||
return os << static_cast<unsigned int>(arg.value());
|
return os << static_cast<unsigned int>(arg.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user