Skip to content

Commit

Permalink
Fixed incorrect dynarray constructor sometimes chosen
Browse files Browse the repository at this point in the history
  • Loading branch information
OleErikPeistorpet committed Jun 6, 2024
1 parent 0bd4b90 commit 7a366ce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dynarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ class dynarray
auto result = dynarray(boost::range::istream_range<int>(someStream));
@endcode */
template< typename InputRange,
typename /*EnableIfRange*/ = iterator_t<InputRange> >
typename /*EnableIfRange*/ = iterator_t<InputRange>,
enable_if< !_detail::isSameSansCVRef<InputRange, dynarray> > = 0
>
explicit dynarray(InputRange && r, Alloc a = Alloc{}) : _m(a) { append(r); }

dynarray(std::initializer_list<T> il, Alloc a = Alloc{}) : _m(a) { append(il); }
Expand Down
15 changes: 15 additions & 0 deletions unit_test/dynarray_construct_assignop_swap_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,21 @@ TEST_F(dynarrayConstructTest, constructMoveOnlyIterator)
#endif


TEST_F(dynarrayConstructTest, copyConstruct)
{
using Al = StatefulAllocator<TrivialRelocat>;
auto x = dynarray< TrivialRelocat, Al >({TrivialRelocat{0.5}}, Al(-5));
EXPECT_EQ(1, g_allocCount.nAllocations);

auto y = dynarray(x);
EXPECT_EQ(-5, y.get_allocator().id);
EXPECT_EQ(2, g_allocCount.nAllocations);

auto z = dynarray(y, Al(7));
EXPECT_EQ(0.5, *z.front());
EXPECT_EQ(3, g_allocCount.nAllocations);
}

template<typename Alloc>
void testMoveConstruct(Alloc a0, Alloc a1)
{
Expand Down
7 changes: 7 additions & 0 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ namespace _detail
OEL_ALWAYS_INLINE constexpr const Empty_type_MSVC_unique_name & second() const { return *this; }
OEL_ALWAYS_INLINE constexpr Empty_type_MSVC_unique_name & second() { return *this; }
};



template< typename T, typename U,
typename SansCVRef = std::remove_cv_t< std::remove_reference_t<T> >
>
inline constexpr auto isSameSansCVRef = std::is_same_v<SansCVRef, U>;
}

} // namespace oel

0 comments on commit 7a366ce

Please sign in to comment.