/usr/local/lib64/python3.6/site-packages/torch/include/c10/util
NameSizeModeActions
accumulate.h42050644editdlrm
AlignOf.h48350644editdlrm
Array.h113540644editdlrm
ArrayRef.h90580644editdlrm
Backtrace.h3640644editdlrm
BFloat16-inl.h92220644editdlrm
BFloat16-math.h52170644editdlrm
BFloat16.h23720644editdlrm
Bitset.h34140644editdlrm
C++17.h133290644editdlrm
complex.h175420644editdlrm
complex_math.h109020644editdlrm
complex_utils.h9580644editdlrm
ConstexprCrc.h66330644editdlrm
copysign.h8660644editdlrm
DeadlockDetection.h19200644editdlrm
Deprecated.h35790644editdlrm
either.h64230644editdlrm
env.h8350644editdlrm
Exception.h247230644editdlrm
ExclusivelyOwned.h47590644editdlrm
Flags.h100560644editdlrm
flat_hash_map.h616550644editdlrm
FunctionRef.h23010644editdlrm
Half-inl.h86740644editdlrm
Half.h189650644editdlrm
hash.h50840644editdlrm
IdWrapper.h23480644editdlrm
intrusive_ptr.h355630644editdlrm
in_place.h3500644editdlrm
irange.h26790644editdlrm
LeftRight.h60160644editdlrm
llvmMathExtras.h291680644editdlrm
Logging.h112560644editdlrm
logging_is_google_glog.h20310644editdlrm
logging_is_not_google_glog.h82710644editdlrm
MathConstants.h8580644editdlrm
math_compat.h72960644editdlrm
MaybeOwned.h66890644editdlrm
Metaprogramming.h152880644editdlrm
numa.h6960644editdlrm
Optional.h355920644editdlrm
order_preserving_flat_hash_map.h654820644editdlrm
overloaded.h7090644editdlrm
python_stub.h560644editdlrm
qint8.h4720644editdlrm
qint32.h3190644editdlrm
quint4x2.h3660644editdlrm
quint8.h3200644editdlrm
Registry.h122420644editdlrm
reverse_iterator.h87960644editdlrm
ScopeExit.h13450644editdlrm
signal_handler.h31540644editdlrm
SmallBuffer.h12430644editdlrm
SmallVector.h344560644editdlrm
sparse_bitset.h265110644editdlrm
StringUtil.h45380644editdlrm
string_utils.h39890644editdlrm
string_view.h201890644editdlrm
tempfile.h60290644editdlrm
ThreadLocal.h38830644editdlrm
ThreadLocalDebugInfo.h26030644editdlrm
thread_name.h1480644editdlrm
Type.h6070644editdlrm
TypeCast.h69720644editdlrm
typeid.h187930644editdlrm
TypeIndex.h52510644editdlrm
TypeList.h169010644editdlrm
TypeTraits.h53680644editdlrm
Unicode.h2950644editdlrm
UniqueVoidPtr.h41170644editdlrm
Unroll.h6670644editdlrm
variant.h951820644editdlrm
win32-headers.h8580644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/include/c10/util/either.h (6423B)
// Originally taken from // https://github.com/cryfs/cryfs/blob/14ad22570ddacef22d5ff139cdff68a54fc8234d/src/cpp-utils/either.h #pragma once #include #include #include namespace c10 { /** * either is a tagged union that holds either an object of type A * or an object of type B. */ template class either final { public: template < class Head, class... Tail, std::enable_if_t< std::is_constructible::value && !std::is_constructible::value>* = nullptr> either(Head&& construct_left_head_arg, Tail&&... construct_left_tail_args) : _side(Side::left) { _construct_left( std::forward(construct_left_head_arg), std::forward(construct_left_tail_args)...); } template < class Head, class... Tail, std::enable_if_t< !std::is_constructible::value && std::is_constructible::value>* = nullptr> either(Head&& construct_right_head_arg, Tail&&... construct_right_tail_args) : _side(Side::right) { _construct_right( std::forward(construct_right_head_arg), std::forward(construct_right_tail_args)...); } either(const either& rhs) : _side(rhs._side) { if (_side == Side::left) { _construct_left( rhs._left); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { _construct_right( rhs._right); // NOLINT(cppcoreguidelines-pro-type-union-access) } } either(either&& rhs) noexcept : _side(rhs._side) { if (_side == Side::left) { _construct_left(std::move( rhs._left)); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { _construct_right(std::move( rhs._right)); // NOLINT(cppcoreguidelines-pro-type-union-access) } } ~either() { _destruct(); } either& operator=(const either& rhs) { _destruct(); _side = rhs._side; if (_side == Side::left) { _construct_left( rhs._left); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { _construct_right( rhs._right); // NOLINT(cppcoreguidelines-pro-type-union-access) } return *this; } either& operator=(either&& rhs) { _destruct(); _side = rhs._side; if (_side == Side::left) { _construct_left(std::move( rhs._left)); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { _construct_right(std::move( rhs._right)); // NOLINT(cppcoreguidelines-pro-type-union-access) } return *this; } bool is_left() const noexcept { return _side == Side::left; } bool is_right() const noexcept { return _side == Side::right; } const Left& left() const& { if (C10_UNLIKELY(!is_left())) { throw std::logic_error( "Tried to get left side of an either which is right."); } return _left; // NOLINT(cppcoreguidelines-pro-type-union-access) } Left& left() & { return const_cast( const_cast*>(this)->left()); } Left&& left() && { return std::move(left()); } const Right& right() const& { if (C10_UNLIKELY(!is_right())) { throw std::logic_error( "Tried to get right side of an either which is left."); } return _right; // NOLINT(cppcoreguidelines-pro-type-union-access) } Right& right() & { return const_cast( const_cast*>(this)->right()); } Right&& right() && { return std::move(right()); } template Result fold(LeftFoldFunc&& leftFoldFunc, RightFoldFunc&& rightFoldFunc) const { if (Side::left == _side) { return std::forward(leftFoldFunc)(_left); } else { return std::forward(rightFoldFunc)(_right); } } private: union { Left _left; Right _right; }; enum class Side : uint8_t { left, right } _side; explicit either(Side side) noexcept : _side(side) {} template void _construct_left(Args&&... args) { new (&_left) Left(std::forward( args)...); // NOLINT(cppcoreguidelines-pro-type-union-access) } template void _construct_right(Args&&... args) { new (&_right) Right(std::forward( args)...); // NOLINT(cppcoreguidelines-pro-type-union-access) } void _destruct() noexcept { if (_side == Side::left) { _left.~Left(); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { _right.~Right(); // NOLINT(cppcoreguidelines-pro-type-union-access) } } template friend either make_left(Args&&... args); template friend either make_right(Args&&... args); }; template inline bool operator==( const either& lhs, const either& rhs) { if (lhs.is_left() != rhs.is_left()) { return false; } if (lhs.is_left()) { return lhs.left() == rhs.left(); } else { return lhs.right() == rhs.right(); } } template inline bool operator!=( const either& lhs, const either& rhs) { return !operator==(lhs, rhs); } template inline std::ostream& operator<<( std::ostream& stream, const either& value) { if (value.is_left()) { stream << "Left(" << value.left() << ")"; } else { stream << "Right(" << value.right() << ")"; } return stream; } template inline either make_left(Args&&... args) { either result(either::Side::left); result._construct_left(std::forward(args)...); return result; } template inline either make_right(Args&&... args) { either result(either::Side::right); result._construct_right(std::forward(args)...); return result; } } // namespace c10