Template Class List#

Inheritance Relationships#

Base Type#

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 hold ObjectRef pointers), 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

using value_type = T#

The value type of the list.

using iterator = details::IterAdapter<ValueConverter, const Any*>#

The iterator type of the list.

using reverse_iterator = details::ReverseIterAdapter<ValueConverter, const Any*>#

The reverse iterator type of the list.

using ContainerType = ListObj#

specify container node

Public Functions

inline explicit List(UnsafeInit tag)#

Construct a List with UnsafeInit.

inline List()#

default constructor

inline List(List<T> &&other)#

Move constructor.

inline List(const List<T> &other)#

Copy 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

inline explicit List(ObjectPtr<Object> n)#

Constructor from pointer.

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 List(std::initializer_list<T> init)#

constructor from initializer list

inline List(const std::vector<T> &init)#

constructor from vector

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 iterator begin() const#
Returns:

begin iterator

inline iterator end() const#
Returns:

end iterator

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 T front() const#
Returns:

The first element of the list

inline T back() const#
Returns:

The last element of the list

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.

inline void Set(int64_t i, T value)#

set i-th element of the list.

Parameters:
  • i – The index

  • value – The value to be set.

inline ListObj *GetListObj() const#
Returns:

The underlying ListObj

template<typename IterType>
inline void Assign(IterType first, IterType last)#

reset the list to content from iterator.

Parameters:
  • first – begin of iterator

  • last – end of iterator

Template Parameters:

IterType – The type of iterator