Skip to content

Commit 0edf7fd

Browse files
authoredApr 7, 2025··
Merge pull request #52 from psiha/feature/resize_with_fill_value
Added overloads for enlarge-resize methods which accept a default-fil…
2 parents 288355a + e2fa24d commit 0edf7fd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎include/psi/vm/containers/vector_impl.hpp

+17
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,23 @@ class [[ nodiscard, clang::trivial_abi ]] vector_impl
916916
}
917917
return data;
918918
}
919+
template <typename U>
920+
value_type * grow_to( this Impl & self, size_type const target_size, U && default_value )
921+
requires std::constructible_from<T, U>
922+
{
923+
auto const current_size{ self.size() };
924+
BOOST_ASSUME( target_size >= current_size );
925+
auto const data{ self.grow_to( target_size, no_init ) };
926+
auto const uninitialized_space_begin{ &data[ current_size ] };
927+
auto const uninitialized_space_size { target_size - current_size };
928+
try {
929+
std::uninitialized_fill_n( uninitialized_space_begin, uninitialized_space_size, std::forward<U>( default_value ) );
930+
} catch(...) {
931+
self.storage_shrink_size_to( current_size );
932+
throw;
933+
}
934+
}
935+
919936
value_type * grow_by( this Impl & self, size_type const delta, auto const init_policy )
920937
{
921938
return self.grow_to( self.size() + delta, init_policy );

0 commit comments

Comments
 (0)
Please sign in to comment.