/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/ExclusivelyOwned.h (4759B)
#pragma once #include namespace c10 { // See example implementations in TensorBody.h and intrusive_ptr.h. // Synopsis: // // repr_type -- type to use to store an owned T in ExclusivelyOwned. // // pointer_type -- pointer-esque type to return from // ExclusivelyOwned's get() and operator*() methods. // // const_pointer_type -- similar to pointer_type, used for the const methods. // // static repr_type nullRepr() -- return a null instance of repr_type. // // template // static repr_type createInPlace(Args&&... args) -- used by the in-place // ExclusivelyOwned constructor. // // static repr_type moveToRepr(T&& x) -- move the given x into an // instance of repr_type. used by the ExclusivelyOwned(T&&) // constructor. // // static void destroyOwned(repr_type x) -- free memory for a // known-exclusively-owned instance of x. Replaces calling repr_type's // destructor. Being able to implement this more efficiently than // repr_type's destructor is the main reason to use ExclusivelyOwned // for a type. // // static T take(repr_type&) -- move out of the given repr_type into an owned T. // // static pointer_type getImpl(const repr_type&) -- return a pointer // to the given repr_type. May take repr_type by value if that is more // efficient. template struct ExclusivelyOwnedTraits; /// ExclusivelyOwned is a smart-pointer-like wrapper around an /// exclusively-owned instance of some type T that normally has /// mandatory reference counting (currently Tensor or /// c10::intrusive_ptr). If you have an isolated piece of code that /// knows that it has sole ownership of an object of one of these /// types (i.e., because you created it directly or using a factory /// function) and that object will not escape from that isolated piece /// of code, then moving the object into an ExclusivelyOwned will /// avoid an atomic reference count decrement at destruction time. /// /// If you directly create the Tensor/intrusive_ptr in the first /// place, you can use the in_place constructor of ExclusivelyOwned to /// additionally avoid doing any stores to initialize the refcount & /// weakcount. (Do note, however, that in this case you should /// probably just use std::unique_ptr instead of intrusive_ptr if applicable.) template class ExclusivelyOwned { using EOT = ExclusivelyOwnedTraits; union { char dummy_; typename ExclusivelyOwnedTraits::repr_type repr_; }; public: ExclusivelyOwned() : repr_(EOT::nullRepr()) {} explicit ExclusivelyOwned(T&& t) : repr_(EOT::moveToRepr(std::move(t))) {} template explicit ExclusivelyOwned(in_place_t, Args&&... args) : repr_(EOT::createInPlace(std::forward(args)...)) {} ExclusivelyOwned(const ExclusivelyOwned&) = delete; ExclusivelyOwned(ExclusivelyOwned&& rhs) noexcept : repr_(std::move(rhs.repr_)) { rhs.repr_ = EOT::nullRepr(); } ExclusivelyOwned& operator=(const ExclusivelyOwned&) = delete; ExclusivelyOwned& operator=(ExclusivelyOwned&& rhs) noexcept { EOT::destroyOwned(repr_); repr_ = std::move(rhs.repr_); rhs.repr_ = EOT::nullRepr(); return *this; } ExclusivelyOwned& operator=(T&& rhs) noexcept { EOT::destroyOwned(repr_); repr_ = EOT::moveToRepr(std::move(rhs)); return *this; } ~ExclusivelyOwned() { EOT::destroyOwned(repr_); // Don't bother to call the destructor of repr_, since we already // did specialized destruction for the exclusively-owned case in // destroyOwned! } // We don't provide this because it would require us to be able to // differentiate an owned-but-empty T from a lack of T. This is // particularly problematic for Tensor, which wants to use an // undefined Tensor as its null state. explicit operator bool() const noexcept = delete; operator T() && { return take(); } // NOTE: the equivalent operation on MaybeOwned is a moving // operator*. For ExclusivelyOwned, take() and operator*() may well // have different return types (e.g., for intrusive_ptr, take() // returns c10::intrusive_ptr whereas operator* returns T&), so // they are different functions. T take() && { return EOT::take(repr_); } typename EOT::const_pointer_type operator->() const { return get(); } typename EOT::const_pointer_type get() const { return EOT::getImpl(repr_); } typename EOT::pointer_type operator->() { return get(); } typename EOT::pointer_type get() { return EOT::getImpl(repr_); } std::remove_pointer_t& operator*() const { return *get(); } std::remove_pointer_t& operator*() { return *get(); } }; } // namespace c10