! * \brief Constructs a container and move from another * \param cap The capacity of the container * \param from Source of the move * \return Ref-counted ArrayObj requested */
| 73 | * \return Ref-counted ArrayObj requested |
| 74 | */ |
| 75 | static ObjectPtr<ArrayObj> MoveFrom(int64_t cap, ArrayObj* from) { |
| 76 | int64_t size = from->TVMFFISeqCell::size; |
| 77 | if (size > cap) { |
| 78 | TVM_FFI_THROW(RuntimeError) << "Not enough capacity"; |
| 79 | } |
| 80 | ObjectPtr<ArrayObj> p = ArrayObj::Empty(cap); |
| 81 | Any* write = p->MutableBegin(); |
| 82 | Any* read = from->MutableBegin(); |
| 83 | // To ensure exception safety, size is only incremented after the initialization succeeds |
| 84 | for (int64_t& i = p->TVMFFISeqCell::size = 0; i < size; ++i) { |
| 85 | new (write++) Any(std::move(*read++)); |
| 86 | } |
| 87 | from->TVMFFISeqCell::size = 0; |
| 88 | return p; |
| 89 | } |
| 90 | |
| 91 | /*! |
| 92 | * \brief Constructs a container with n elements. Each element is a copy of val |
nothing calls this directly
no test coverage detected