29 Blob() noexcept : meta_(), pointer_(
nullptr), has_ownership_(
false) {}
48 return meta_.Match<
T>();
74 "wrong type for the Blob instance. Blob contains ",
76 " while caller expects ",
77 TypeMeta::TypeName<T>());
81 return *
static_cast<const T*
>(pointer_);
103 "GetMutable can't be called with non-default-constructible types. "
104 "Try using specialized methods");
106 return static_cast<T*
>(pointer_);
110 return Reset<T>(
new T());
117 return static_cast<T*
>(pointer_);
134 meta_ = TypeMeta::Make<T>();
135 pointer_ =
static_cast<void*
>(
allocated);
136 has_ownership_ =
true;
153 return static_cast<T*
>(ShareExternal(
162 has_ownership_ =
false;
173 has_ownership_ =
false;
188 if (has_ownership_ && pointer_ !=
nullptr) {
189 (*meta_.deleteFn())(pointer_);
#define TORCH_INTERNAL_ASSERT(cond,...)
Reimplementation of std::string_view for C++11.
intrusive_ptr<T> is an alternative to shared_ptr<T> that has better performance because it does the r...
Blob is a general container that hosts a typed pointer.
Blob & operator=(Blob &&other) noexcept
const void * GetRaw() const noexcept
void * ShareExternal(void *allocated, const TypeMeta meta)
T * Reset(T *allocated)
Sets the underlying object to the allocated one.
Blob(Blob &&other) noexcept
const TypeMeta meta() const noexcept
Returns the meta info of the blob.
std::remove_const< T >::type * ShareExternal(typename std::remove_const< T >::type *allocated)
Sets the underlying object to the allocated one, but does not take over the ownership of the passed i...
c10::string_view TypeName() const noexcept
Returns a printable typename of the blob.
bool IsType() const noexcept
Checks if the content stored in the blob is of type T.
void swap(Blob &rhs)
Swaps the underlying storage of two blobs.
const T & Get() const
Gets the const reference of the stored object.
Blob() noexcept
Initializes an empty Blob.
void Reset()
Resets the Blob to an empty one.
T * GetMutable()
Gets a mutable pointer to the stored object.
C10_DISABLE_COPY_AND_ASSIGN(Blob)
constexpr remove_reference_t< T > && move(T &&t) noexcept
Copyright (c) 2016-present, Facebook, Inc.
std::ostream & operator<<(std::ostream &out, const Blob &v)
void swap(Blob &lhs, Blob &rhs)
void swap(c10::SmallVectorImpl< T > &LHS, c10::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.