aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-03-20 17:09:39 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-03-20 17:09:39 +0100
commitfb366b3c59941ea4c8e0a8d6e29ba0263f89bb02 (patch)
tree5679aafbb853c2f59218bb0136806677c90ed2ce /libs
parentb430f23711071872ff054a1e1b30f8a028584fe4 (diff)
downloadteachos-fb366b3c59941ea4c8e0a8d6e29ba0263f89bb02.tar.xz
teachos-fb366b3c59941ea4c8e0a8d6e29ba0263f89bb02.zip
kstd/vector: allow input iterators for construction
Diffstat (limited to 'libs')
-rw-r--r--libs/kstd/include/kstd/vector29
1 files changed, 28 insertions, 1 deletions
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<std::forward_iterator ForwardIterator>
@@ -120,6 +120,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<std::input_iterator InputIterator>
+ constexpr vector(InputIterator first, InputIterator last,
+ allocator_type const & allocator =
+ allocator_type{}) noexcept(std::is_nothrow_copy_constructible_v<allocator_type>)
+ : 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.
+ //!
//!
template<typename Range>
requires(std::ranges::input_range<Range> && std::ranges::sized_range<Range> &&
@@ -747,6 +768,12 @@ namespace kstd
vector(ForwardIterator, ForwardIterator, Allocator = Allocator())
-> vector<typename std::iterator_traits<ForwardIterator>::value_type, Allocator>;
+ //! Deduction guide for vector construction from an interator pair.
+ template<std::input_iterator InputIterator,
+ typename Allocator = kstd::allocator<typename std::iterator_traits<InputIterator>::value_type>>
+ vector(InputIterator, InputIterator, Allocator = Allocator())
+ -> vector<typename std::iterator_traits<InputIterator>::value_type, Allocator>;
+
//! Deduction guide for vector construction from a range.
template<std::ranges::input_range Range, typename Allocator = kstd::allocator<std::ranges::range_value_t<Range>>>
vector(kstd::from_range_t, Range &&, Allocator = Allocator()) -> vector<std::ranges::range_value_t<Range>, Allocator>;