-// Copyright (C) 2022-2023 Joel Rosdahl and other contributors
+// Copyright (C) 2022-2024 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
insert(const uint8_t* pos, const uint8_t* data, const size_t size) noexcept;
void insert(const uint8_t* pos, const char* first, const char* last) noexcept;
void insert(const uint8_t* pos, const char* data, size_t size) noexcept;
+ void insert(const uint8_t* pos, nonstd::span<const uint8_t> data) noexcept;
private:
std::unique_ptr<uint8_t[]> m_data;
return insert(pos, data, data + size);
}
+inline void
+Bytes::insert(const uint8_t* pos, nonstd::span<const uint8_t> data) noexcept
+{
+ return insert(pos, &*data.begin(), &*data.end());
+}
+
} // namespace util
-// Copyright (C) 2021-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2024 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
CHECK(bytes2[1] == 'b');
CHECK(bytes2[2] == 'c');
}
+
+ SUBCASE("Insert span")
+ {
+ Bytes bytes2;
+ nonstd::span<const uint8_t> span(bytes1.begin(), bytes1.end());
+
+ bytes2.insert(bytes2.end(), span);
+ CHECK(bytes2.size() == 3);
+ CHECK(bytes2.capacity() == 3);
+ CHECK(bytes2[0] == 'a');
+ CHECK(bytes2[1] == 'b');
+ CHECK(bytes2[2] == 'c');
+ }
}
TEST_CASE("Conversion to span")