MCPcopy Create free account
hub / github.com/pybind/pybind11 / Sequence

Class Sequence

tests/test_sequences_and_iterators.cpp:172–267  ·  view source on GitHub ↗

test_sequence

Source from the content-addressed store, hash-verified

170
171 // test_sequence
172 class Sequence {
173 public:
174 explicit Sequence(size_t size) : m_size(size) {
175 print_created(this, "of size", m_size);
176 // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
177 m_data = new float[size];
178 memset(m_data, 0, sizeof(float) * size);
179 }
180 explicit Sequence(const std::vector<float> &value) : m_size(value.size()) {
181 print_created(this, "of size", m_size, "from std::vector");
182 // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
183 m_data = new float[m_size];
184 memcpy(m_data, &value[0], sizeof(float) * m_size);
185 }
186 Sequence(const Sequence &s) : m_size(s.m_size) {
187 print_copy_created(this);
188 // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
189 m_data = new float[m_size];
190 memcpy(m_data, s.m_data, sizeof(float) * m_size);
191 }
192 Sequence(Sequence &&s) noexcept : m_size(s.m_size), m_data(s.m_data) {
193 print_move_created(this);
194 s.m_size = 0;
195 s.m_data = nullptr;
196 }
197
198 ~Sequence() {
199 print_destroyed(this);
200 delete[] m_data;
201 }
202
203 Sequence &operator=(const Sequence &s) {
204 if (&s != this) {
205 delete[] m_data;
206 m_size = s.m_size;
207 m_data = new float[m_size];
208 memcpy(m_data, s.m_data, sizeof(float) * m_size);
209 }
210 print_copy_assigned(this);
211 return *this;
212 }
213
214 Sequence &operator=(Sequence &&s) noexcept {
215 if (&s != this) {
216 delete[] m_data;
217 m_size = s.m_size;
218 m_data = s.m_data;
219 s.m_size = 0;
220 s.m_data = nullptr;
221 }
222 print_move_assigned(this);
223 return *this;
224 }
225
226 bool operator==(const Sequence &s) const {
227 if (m_size != s.size()) {
228 return false;
229 }

Callers

nothing calls this directly

Calls 2

print_copy_assignedFunction · 0.85
print_move_assignedFunction · 0.85

Tested by

no test coverage detected