Template Class List#
Defined in File list.h
Inheritance Relationships#
Base Type#
public tvm::ffi::ObjectRef(Class ObjectRef)
Class Documentation#
-
template<typename T, typename = typename std::enable_if_t<details::storage_enabled_v<T>>>
class List : public tvm::ffi::ObjectRef# List, container representing a mutable contiguous sequence of ObjectRefs.
Unlike Array, List is mutable and does not implement copy-on-write. Mutations happen directly on the underlying shared ListObj.
Note
Thread safety: List is not thread-safe. Concurrent reads and writes from multiple threads require external synchronization.
Warning
Because List elements are stored as
Any(which may holdObjectRefpointers), it is possible to create reference cycles (e.g. a List that contains itself). Such cycles will not be collected by the reference- counting mechanism alone; avoid them in long-lived data structures.- Template Parameters:
T – The content Value type, must be compatible with tvm::ffi::Any
Public Types
Public Functions
-
inline explicit List(UnsafeInit tag)#
Construct a List with UnsafeInit.
-
inline List()#
default constructor
-
template<typename U, typename = std::enable_if_t<details::type_contains_v<T, U>>>
inline List(List<U> &&other)# Constructor from another list.
- Template Parameters:
U – The value type of the other list
-
template<typename U, typename = std::enable_if_t<details::type_contains_v<T, U>>>
inline List(const List<U> &other)# Constructor from another list.
- Template Parameters:
U – The value type of the other list
-
template<typename IterType>
inline List(IterType first, IterType last)# Constructor from iterator.
- Parameters:
first – begin of iterator
last – end of iterator
- Template Parameters:
IterType – The type of iterator
-
inline explicit List(const size_t n, const T &val)#
Constructs a container with n elements. Each element is a copy of val.
- Parameters:
n – The size of the container
val – The init value
-
inline reverse_iterator rbegin() const#
- Returns:
rbegin iterator
-
inline reverse_iterator rend() const#
- Returns:
rend iterator
-
inline size_t size() const#
- Returns:
The size of the list
-
inline size_t capacity() const#
- Returns:
The capacity of the list
-
inline bool empty() const#
- Returns:
Whether list is empty
-
inline void push_back(const T &item)#
push a new item to the back of the list
- Parameters:
item – The item to be pushed.
-
template<typename ...Args>
inline void emplace_back(Args&&... args)# Emplace a new element at the back of the list.
- Parameters:
args – The arguments to construct the new element
-
inline void insert(iterator position, const T &val)#
Insert an element into the given position.
- Parameters:
position – An iterator pointing to the insertion point
val – The element to insert
-
template<typename IterType>
inline void insert(iterator position, IterType first, IterType last)# Insert a range of elements into the given position.
- Parameters:
position – An iterator pointing to the insertion point
first – The begin iterator of the range
last – The end iterator of the range
-
inline void pop_back()#
Remove the last item of the list.
-
inline void erase(iterator position)#
Erase an element on the given position.
- Parameters:
position – An iterator pointing to the element to be erased
-
inline void erase(iterator first, iterator last)#
Erase a given range of elements.
- Parameters:
first – The begin iterator of the range
last – The end iterator of the range
-
inline void resize(int64_t n)#
Resize the list.
- Parameters:
n – The new size.
-
inline void reserve(int64_t n)#
Make sure the list has the capacity of at least n.
- Parameters:
n – lower bound of the capacity
-
inline void clear()#
Release reference to all the elements.