Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 589279414
  • Loading branch information
gribozavr authored and copybara-github committed Dec 9, 2023
1 parent faae68e commit 4e78e64
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions mediapipe/framework/deps/strong_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
// 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:
//
// int64 foo = 123;
// int64 bar = 456;
// int64 baz = foo + bar;
// constexpr int64 fubar = 789;
// int64_t foo = 123;
// int64_t bar = 456;
// int64_t baz = foo + bar;
// constexpr int64_t fubar = 789;
//
// ...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 bar(456);
// MyStrongInt baz = foo + bar;
Expand Down Expand Up @@ -97,6 +97,7 @@
#ifndef MEDIAPIPE_DEPS_STRONG_INT_H_
#define MEDIAPIPE_DEPS_STRONG_INT_H_

#include <cstdint>
#include <iosfwd>
#include <limits>
#include <ostream>
Expand Down Expand Up @@ -179,11 +180,11 @@ struct NullStrongIntValidator {
}
// Verify lhs << rhs.
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.
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.
template <typename T>
Expand Down Expand Up @@ -224,8 +225,8 @@ class StrongInt {
//
// Example: Assume you have two StrongInt types.
//
// DEFINE_STRONG_INT_TYPE(Bytes, int64);
// DEFINE_STRONG_INT_TYPE(Megabytes, int64);
// DEFINE_STRONG_INT_TYPE(Bytes, int64_t);
// DEFINE_STRONG_INT_TYPE(Megabytes, int64_t);
//
// 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
Expand Down Expand Up @@ -337,12 +338,12 @@ class StrongInt {
value_ %= arg;
return *this;
}
StrongInt &operator<<=(int64 arg) { // NOLINT(whitespace/operators)
StrongInt &operator<<=(int64_t arg) { // NOLINT(whitespace/operators)
ValidatorType::template ValidateLeftShift<ValueType>(value_, arg);
value_ <<= arg;
return *this;
}
StrongInt &operator>>=(int64 arg) { // NOLINT(whitespace/operators)
StrongInt &operator>>=(int64_t arg) { // NOLINT(whitespace/operators)
ValidatorType::template ValidateRightShift<ValueType>(value_, arg);
value_ >>= arg;
return *this;
Expand Down Expand Up @@ -378,19 +379,19 @@ std::ostream &operator<<(std::ostream &os,
return os << arg.value();
}

// Provide the << operator, primarily for logging purposes. Specialized for int8
// so that an integer and not a character is printed.
// Provide the << operator, primarily for logging purposes. Specialized for
// int8_t so that an integer and not a character is printed.
template <typename TagType, typename ValidatorType>
std::ostream &operator<<(std::ostream &os,
StrongInt<TagType, int8, ValidatorType> arg) {
StrongInt<TagType, int8_t, ValidatorType> arg) {
return os << static_cast<int>(arg.value());
}

// 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>
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());
}

Expand Down

0 comments on commit 4e78e64

Please sign in to comment.