8000 Add some tests to verify that `select_on_container_copy_construction` is being used appropriately by gharveymn · Pull Request #20 · gharveymn/small_vector · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add some tests to verify that select_on_container_copy_construction is being used appropriately #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion source/test/test_allocators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ namespace gch
template <typename U>
constexpr GCH_IMPLICIT_CONVERSION
verifying_allocator (const verifying_allocator<U, PartialTraits>& other) noexcept
: base (other)
: base (other),
created_by_container_copy_construction (other.created_by_container_copy_construction)
{ }

GCH_NODISCARD
Expand Down Expand Up @@ -452,8 +453,48 @@ namespace gch
remove_object (p);
alloc_traits::destroy (*this, p);
}

verifying_allocator
select_on_container_copy_construction () const
{
verifying_allocator ret { *this };
ret.created_by_container_copy_construction = true;
return ret;
}

bool created_by_container_copy_construction = false;
};

template <typename A>
constexpr int
verify_created_by_container_copy_construction (const A&)
{
return 0;
}

template <typename T, typename Traits>
constexpr int
verify_created_by_container_copy_construction (const verifying_allocator<T, Traits>& a)
{
return assert (a.created_by_container_copy_construction
&& "select_on_container_copy_construction unexpectedly invoked"), 0;
}

template <typename A>
constexpr int
verify_not_created_by_container_copy_construction (const A&)
{
return 0;
}

template <typename T, typename Traits>
constexpr int
verify_not_created_by_container_copy_construction (const verifying_allocator<T, Traits>& a)
{
return assert (! a.created_by_container_copy_construction
&& "select_on_container_copy_construction unexpectedly not invoked"), 0;
}

template <typename T, typename Traits>
constexpr
bool
8000 Expand Down Expand Up @@ -489,6 +530,12 @@ namespace gch
using propagate_on_container_move_assignment = std::false_type;
using propagate_on_container_copy_assignment = std::false_type;
using propagate_on_container_swap = std::false_type;

non_propagating_verifying_allocator
select_on_container_copy_construction () const
{
return non_propagating_verifying_allocator { *this };
}
};

template <typename T, typename Traits>
Expand Down
4 changes: 4 additions & 0 deletions source/test/unit/member/assign/test-copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ struct tester

n.assign (m);
CHECK (n == m_cmp);
gch::test_types::verify_not_created_by_container_copy_construction (n.get_allocator ());
}
{
// vector_type<N> (ni) -> vector_type<M> (mi)
Expand All @@ -222,6 +223,7 @@ struct tester

m.assign (n);
CHECK (m == n_cmp);
gch::test_types::verify_not_created_by_container_copy_construction (m.get_allocator ());
}
{
// vector_type<M> (ni) -> vector_type<N> (mi)
Expand All @@ -233,6 +235,7 @@ struct tester

n.assign (m);
CHECK (n == n_cmp);
gch::test_types::verify_not_created_by_container_copy_construction (n.get_allocator ());
}
{
// vector_type<N> (mi) -> vector_type<M> (ni)
Expand All @@ -244,6 +247,7 @@ struct tester

m.assign (n);
CHECK (m == m_cmp);
gch::test_types::verify_not_created_by_container_copy_construction (m.get_allocator ());
}
}

Expand Down
4 changes: 4 additions & 0 deletions source/test/unit/member/assign/test-move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ struct tester

n.assign (std::move (m));
CHECK (n == m_cmp);
gch::test_types::verify_not_created_by_container_copy_construction (n.get_allocator ());
}
{
// vector_type<N> (ni) -> vector_type<M> (mi)
Expand All @@ -329,6 +330,7 @@ struct tester

m.assign (std::move (n));
CHECK (m == n_cmp);
gch::test_types::verify_not_created_by_container_copy_construction (m.get_allocator ());
}
{
// vector_type<M> (ni) -> vector_type<N> (mi)
Expand All @@ -340,6 +342,7 @@ struct tester

n.assign (std::move (m));
CHECK (n == n_cmp);
gch::test_types::verify_not_created_by_container_copy_construction (n.get_allocator ());
}
{
// vector_type<N> (mi) -> vector_type<M> (ni)
Expand All @@ -351,6 +354,7 @@ struct tester

m.assign (std::move (n));
CHECK (m == m_cmp);
gch::test_types::verify_not_created_by_container_copy_construction (m.get_allocator ());
}
}

Expand Down
2 changes: 2 additions & 0 deletions source/test/unit/member/constructor/test-copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@ struct tester

vector_type<N> v (m);
CHECK (v == m_cmp);
gch::test_types::verify_created_by_container_copy_construction (v.get_allocator ());
}
{
vector_type<M> m (mi.begin (), mi.end (), m_alloc);
mi (m);

vector_type<N> v (m, m_alloc);
CHECK (v == m_cmp);
gch::test_types::verify_not_created_by_container_copy_construction (v.get_allocator ());
}
}

Expand Down
2 changes: 2 additions & 0 deletions source/test/unit/member/constructor/test-move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@ struct tester

vector_type<N> v (std::move (m));
CHECK (v == m_cmp);
gch::test_types::verify_not_created_by_container_copy_construction (v.get_allocator ());
}
{
vector_type<M> m (mi.begin (), mi.end (), m_alloc);
mi (m);

vector_type<N> v (std::move (m), m_init_alloc);
CHECK (v == m_cmp);
gch::test_types::verify_not_created_by_container_copy_construction (v.get_allocator ());
}
}

Expand Down
3 changes: 3 additions & 0 deletions source/test/unit/member/constructor/test-range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ struct tester
{
vector_type<N> v (mi.begin (), mi.end (), m_alloc);
CHECK (mi.size () == v.size () && std::equal (mi.begin (), mi.end (), v.begin ()));
gch::test_types::verify_not_created_by_container_copy_construction (v.get_allocator ());
}
{
vector_type<N> v (input_it (&*mi.begin ()), input_it (&*mi.end ()));
Expand All @@ -138,6 +139,7 @@ struct tester
{
vector_type<N> v (input_it (&*mi.begin ()), input_it (&*mi.end ()), m_alloc);
CHECK (mi.size () == v.size () && std::equal (mi.begin (), mi.end (), v.begin ()));
gch::test_types::verify_not_created_by_container_copy_construction (v.get_allocator ());
}
{
vector_type<N> v (forward_it (&*mi.begin ()), forward_it (&*mi.end ()));
Expand All @@ -146,6 +148,7 @@ struct tester
{
vector_type<N> v (forward_it (&*mi.begin ()), forward_it (&*mi.end ()), m_alloc);
CHECK (mi.size () == v.size () && std::equal (mi.begin (), mi.end (), v.begin ()));
gch::test_types::verify_not_created_by_container_copy_construction (v.get_allocator ());
}
}

Expand Down
4 changes: 4 additions & 0 deletions source/test/unit/member/swap/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ struct tester
n.swap (m);
CHECK (n == m_cmp);
CHECK (m == n_cmp);
gch::test_types::verify_not_created_by_container_copy_construction (n.get_allocator ());
gch::test_types::verify_not_created_by_container_copy_construction (m.get_allocator ());
}
{
// vector_type<N> (ni) -> vector_type<N> (mi)
Expand All @@ -134,6 +136,8 @@ struct tester
m.swap (n);
CHECK (n == m_cmp);
CHECK (m == n_cmp);
gch::test_types::verify_not_created_by_container_copy_construction (n.get_allocator ());
gch::test_types::verify_not_created_by_container_copy_construction (m.get_allocator ());
}
}

Expand Down
Loading
0