From d82541fcea40efadaef63fef5f4a76c3fea5defe Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 27 Jan 2024 11:32:16 +0000 Subject: Support constructing a glContainer from a collection of the same type --- lib/glContainer.h | 6 ++++++ test/test-glContainer.cpp | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/glContainer.h b/lib/glContainer.h index ce88916..2ccc1c2 100644 --- a/lib/glContainer.h +++ b/lib/glContainer.h @@ -38,6 +38,12 @@ public: clear(); } + template typename C> explicit glContainer(const C & src) + { + reserve(src.size()); + std::copy(src.begin(), src.end(), std::back_inserter(*this)); + } + DEFAULT_MOVE_NO_COPY(glContainer); [[nodiscard]] iterator diff --git a/test/test-glContainer.cpp b/test/test-glContainer.cpp index 0597470..ccf3b90 100644 --- a/test/test-glContainer.cpp +++ b/test/test-glContainer.cpp @@ -305,6 +305,15 @@ BOOST_AUTO_TEST_CASE(iter_compare) BOOST_AUTO_TEST_SUITE_END(); +BOOST_AUTO_TEST_CASE(create_copy_source, *boost::unit_test::timeout(1)) +{ + const std::vector src {4, 6, 2, 4, 6, 0}; + glContainer dst {src}; + static_assert(std::is_same_v); + dst.unmap(); + BOOST_CHECK_EQUAL_COLLECTIONS(src.begin(), src.end(), dst.begin(), dst.end()); +} + struct C { int x; float y; -- cgit v1.2.3