From fb366b3c59941ea4c8e0a8d6e29ba0263f89bb02 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 20 Mar 2026 17:09:39 +0100 Subject: kstd/vector: allow input iterators for construction --- libs/kstd/include/kstd/vector | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'libs') diff --git a/libs/kstd/include/kstd/vector b/libs/kstd/include/kstd/vector index e4979e5..7042ff1 100644 --- a/libs/kstd/include/kstd/vector +++ b/libs/kstd/include/kstd/vector @@ -100,7 +100,7 @@ namespace kstd //! Construct a new vector and initialize it's content by copying all elements in the given range. //! - //! @tparam InputIterator An iterator type used to describe the source range. + //! @tparam ForwardIterator An iterator type used to describe the source range. //! @param first The start of the source range. //! @param last The end of the source range. template @@ -118,6 +118,27 @@ namespace kstd } } + //! Construct a new vector and initialize it's content by copying all elements in the given range. + //! + //! @tparam InputIterator An iterator type used to describe the source range. + //! @param first The start of the source range. + //! @param last The end of the source range. + template + constexpr vector(InputIterator first, InputIterator last, + allocator_type const & allocator = + allocator_type{}) noexcept(std::is_nothrow_copy_constructible_v) + : m_allocator{allocator} + , m_size{0} + , m_capacity{0} + , m_data{} + { + while (first != last) + { + emplace_back(*first); + ++first; + } + } + //! Construct a new vector and initialize it's content by copying all elements in the given range. //! //! @@ -747,6 +768,12 @@ namespace kstd vector(ForwardIterator, ForwardIterator, Allocator = Allocator()) -> vector::value_type, Allocator>; + //! Deduction guide for vector construction from an interator pair. + template::value_type>> + vector(InputIterator, InputIterator, Allocator = Allocator()) + -> vector::value_type, Allocator>; + //! Deduction guide for vector construction from a range. template>> vector(kstd::from_range_t, Range &&, Allocator = Allocator()) -> vector, Allocator>; -- cgit v1.2.3