Implement full support for non-pointer pointers in custom allocators for vector.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@185093 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant
2013-06-27 19:35:32 +00:00
parent 29f7432ff3
commit 2c39cbe020
98 changed files with 1721 additions and 91 deletions

View File

@@ -14,6 +14,7 @@
#include <vector>
#include <cassert>
#include "../../test_allocator.h"
#include "../../min_allocator.h"
int main()
{
@@ -31,4 +32,13 @@ int main()
assert(l2 == l);
assert(l2.get_allocator() == other_allocator<bool>(5));
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool> > l(3, 2, min_allocator<bool>());
std::vector<bool, min_allocator<bool> > l2(l, min_allocator<bool>());
l2 = l;
assert(l2 == l);
assert(l2.get_allocator() == min_allocator<bool>());
}
#endif
}

View File

@@ -14,15 +14,30 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
std::vector<int> d;
{
std::vector<bool> d;
d.assign({true, false, false, true});
assert(d.size() == 4);
assert(d[0] == true);
assert(d[1] == false);
assert(d[2] == false);
assert(d[3] == true);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> d;
d.assign({true, false, false, true});
assert(d.size() == 4);
assert(d[0] == true);
assert(d[1] == false);
assert(d[2] == false);
assert(d[3] == true);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@@ -14,6 +14,7 @@
#include <vector>
#include <cassert>
#include "../../test_allocator.h"
#include "../../min_allocator.h"
int main()
{
@@ -60,5 +61,21 @@ int main()
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool> > l(min_allocator<bool>{});
std::vector<bool, min_allocator<bool> > lo(min_allocator<bool>{});
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
std::vector<bool, min_allocator<bool> > l2(min_allocator<bool>{});
l2 = std::move(l);
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -15,6 +15,8 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
{
@@ -27,4 +29,16 @@ int main()
v.push_back(0);
assert(v.capacity() >= 101);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> v;
assert(v.capacity() == 0);
}
{
std::vector<bool, min_allocator<bool>> v(100);
assert(v.capacity() >= 100);
v.push_back(0);
assert(v.capacity() >= 101);
}
#endif
}

View File

@@ -16,6 +16,7 @@
#include <cassert>
#include "../../test_allocator.h"
#include "../../min_allocator.h"
template <class C>
void
@@ -43,4 +44,10 @@ int main()
test0<std::vector<bool> >();
test1<std::vector<bool, test_allocator<bool> > >(test_allocator<bool>(3));
}
#if __cplusplus >= 201103L
{
test0<std::vector<bool, min_allocator<bool>> >();
test1<std::vector<bool, min_allocator<bool> > >(min_allocator<bool>());
}
#endif
}

View File

@@ -16,6 +16,7 @@
#include <cassert>
#include "test_iterators.h"
#include "../../min_allocator.h"
template <class C, class Iterator>
void
@@ -37,4 +38,11 @@ int main()
test<std::vector<bool> >(bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an));
test<std::vector<bool> >(random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an));
test<std::vector<bool> >(a, an);
#if __cplusplus >= 201103L
test<std::vector<bool, min_allocator<bool>> >(input_iterator<const bool*>(a), input_iterator<const bool*>(an));
test<std::vector<bool, min_allocator<bool>> >(forward_iterator<const bool*>(a), forward_iterator<const bool*>(an));
test<std::vector<bool, min_allocator<bool>> >(bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an));
test<std::vector<bool, min_allocator<bool>> >(random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an));
test<std::vector<bool, min_allocator<bool>> >(a, an);
#endif
}

View File

@@ -17,6 +17,7 @@
#include <cassert>
#include "test_iterators.h"
#include "../../min_allocator.h"
template <class C, class Iterator>
void
@@ -33,10 +34,22 @@ int main()
{
bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
bool* an = a + sizeof(a)/sizeof(a[0]);
{
std::allocator<bool> alloc;
test<std::vector<bool> >(input_iterator<const bool*>(a), input_iterator<const bool*>(an), alloc);
test<std::vector<bool> >(forward_iterator<const bool*>(a), forward_iterator<const bool*>(an), alloc);
test<std::vector<bool> >(bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an), alloc);
test<std::vector<bool> >(random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an), alloc);
test<std::vector<bool> >(a, an, alloc);
}
#if __cplusplus >= 201103L
{
min_allocator<bool> alloc;
test<std::vector<bool, min_allocator<bool>> >(input_iterator<const bool*>(a), input_iterator<const bool*>(an), alloc);
test<std::vector<bool, min_allocator<bool>> >(forward_iterator<const bool*>(a), forward_iterator<const bool*>(an), alloc);
test<std::vector<bool, min_allocator<bool>> >(bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an), alloc);
test<std::vector<bool, min_allocator<bool>> >(random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an), alloc);
test<std::vector<bool, min_allocator<bool>> >(a, an, alloc);
}
#endif
}

View File

@@ -15,6 +15,8 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
template <class C>
void
test(typename C::size_type n)
@@ -30,4 +32,7 @@ test(typename C::size_type n)
int main()
{
test<std::vector<bool> >(50);
#if __cplusplus >= 201103L
test<std::vector<bool, min_allocator<bool>> >(50);
#endif
}

View File

@@ -15,6 +15,8 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
template <class C>
void
test(typename C::size_type n, const typename C::value_type& x)
@@ -29,4 +31,7 @@ test(typename C::size_type n, const typename C::value_type& x)
int main()
{
test<std::vector<bool> >(50, 3);
#if __cplusplus >= 201103L
test<std::vector<bool, min_allocator<bool>> >(50, 3);
#endif
}

View File

@@ -15,6 +15,8 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
template <class C>
void
test(typename C::size_type n, const typename C::value_type& x,
@@ -31,4 +33,7 @@ test(typename C::size_type n, const typename C::value_type& x,
int main()
{
test<std::vector<bool> >(50, 3, std::allocator<bool>());
#if __cplusplus >= 201103L
test<std::vector<bool, min_allocator<bool>> >(50, 3, min_allocator<bool>());
#endif
}

View File

@@ -15,6 +15,7 @@
#include <vector>
#include <cassert>
#include "../../test_allocator.h"
#include "../../min_allocator.h"
template <class C>
void
@@ -48,4 +49,17 @@ int main()
assert(v2.get_allocator() == other_allocator<bool>(-2));
}
#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
#if __cplusplus >= 201103L
{
bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
bool* an = a + sizeof(a)/sizeof(a[0]);
test(std::vector<bool, min_allocator<bool>>(a, an));
}
{
std::vector<bool, min_allocator<bool> > v(3, 2, min_allocator<bool>());
std::vector<bool, min_allocator<bool> > v2 = v;
assert(v2 == v);
assert(v2.get_allocator() == v.get_allocator());
}
#endif
}

View File

@@ -14,6 +14,7 @@
#include <vector>
#include <cassert>
#include "../../test_allocator.h"
#include "../../min_allocator.h"
template <class C>
void
@@ -45,4 +46,17 @@ int main()
assert(l2 == l);
assert(l2.get_allocator() == other_allocator<bool>(3));
}
#if __cplusplus >= 201103L
{
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
int* an = a + sizeof(a)/sizeof(a[0]);
test(std::vector<bool, min_allocator<bool>>(a, an), min_allocator<bool>());
}
{
std::vector<bool, min_allocator<bool> > l(3, 2, min_allocator<bool>());
std::vector<bool, min_allocator<bool> > l2(l, min_allocator<bool>());
assert(l2 == l);
assert(l2.get_allocator() == min_allocator<bool>());
}
#endif
}

View File

@@ -15,9 +15,12 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
bool a1[] = {1, 0, 1};
{
std::vector<bool> l1(a1, a1+3);
std::vector<bool>::const_iterator i = l1.begin();
++i;
@@ -36,4 +39,27 @@ int main()
assert(j == l1.end());
assert(l1.size() == 0);
assert(distance(l1.begin(), l1.end()) == 0);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> l1(a1, a1+3);
std::vector<bool, min_allocator<bool>>::const_iterator i = l1.begin();
++i;
std::vector<bool, min_allocator<bool>>::iterator j = l1.erase(i);
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
assert(*j == true);
assert(*l1.begin() == 1);
assert(*next(l1.begin()) == true);
j = l1.erase(j);
assert(j == l1.end());
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
assert(*l1.begin() == true);
j = l1.erase(l1.begin());
assert(j == l1.end());
assert(l1.size() == 0);
assert(distance(l1.begin(), l1.end()) == 0);
}
#endif
}

View File

@@ -15,6 +15,8 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
bool a1[] = {1, 0, 1};
@@ -48,4 +50,36 @@ int main()
assert(distance(l1.cbegin(), l1.cend()) == 0);
assert(i == l1.begin());
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> l1(a1, a1+3);
std::vector<bool, min_allocator<bool>>::iterator i = l1.erase(l1.cbegin(), l1.cbegin());
assert(l1.size() == 3);
assert(distance(l1.cbegin(), l1.cend()) == 3);
assert(i == l1.begin());
}
{
std::vector<bool, min_allocator<bool>> l1(a1, a1+3);
std::vector<bool, min_allocator<bool>>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin()));
assert(l1.size() == 2);
assert(distance(l1.cbegin(), l1.cend()) == 2);
assert(i == l1.begin());
assert((l1 == std::vector<bool, min_allocator<bool>>(a1+1, a1+3)));
}
{
std::vector<bool, min_allocator<bool>> l1(a1, a1+3);
std::vector<bool, min_allocator<bool>>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2));
assert(l1.size() == 1);
assert(distance(l1.cbegin(), l1.cend()) == 1);
assert(i == l1.begin());
assert((l1 == std::vector<bool, min_allocator<bool>>(a1+2, a1+3)));
}
{
std::vector<bool, min_allocator<bool>> l1(a1, a1+3);
std::vector<bool, min_allocator<bool>>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3));
assert(l1.size() == 0);
assert(distance(l1.cbegin(), l1.cend()) == 0);
assert(i == l1.begin());
}
#endif
}

View File

@@ -14,14 +14,28 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
std::vector<int> d = {true, false, false, true};
{
std::vector<bool> d = {true, false, false, true};
assert(d.size() == 4);
assert(d[0] == true);
assert(d[1] == false);
assert(d[2] == false);
assert(d[3] == true);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> d = {true, false, false, true};
assert(d.size() == 4);
assert(d[0] == true);
assert(d[1] == false);
assert(d[2] == false);
assert(d[3] == true);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@@ -15,16 +15,30 @@
#include <cassert>
#include "../../test_allocator.h"
#include "../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
std::vector<int, test_allocator<int>> d({true, false, false, true}, test_allocator<int>(3));
assert(d.get_allocator() == test_allocator<int>(3));
{
std::vector<bool, test_allocator<bool>> d({true, false, false, true}, test_allocator<bool>(3));
assert(d.get_allocator() == test_allocator<bool>(3));
assert(d.size() == 4);
assert(d[0] == true);
assert(d[1] == false);
assert(d[2] == false);
assert(d[3] == true);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> d({true, false, false, true}, min_allocator<bool>());
assert(d.get_allocator() == min_allocator<bool>());
assert(d.size() == 4);
assert(d[0] == true);
assert(d[1] == false);
assert(d[2] == false);
assert(d[3] == true);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@@ -14,9 +14,12 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
std::vector<bool> d(10, true);
std::vector<bool>::iterator i = d.insert(d.cbegin() + 2, {false, true, true, false});
assert(d.size() == 14);
@@ -35,5 +38,28 @@ int main()
assert(d[11] == true);
assert(d[12] == true);
assert(d[13] == true);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> d(10, true);
std::vector<bool, min_allocator<bool>>::iterator i = d.insert(d.cbegin() + 2, {false, true, true, false});
assert(d.size() == 14);
assert(i == d.begin() + 2);
assert(d[0] == true);
assert(d[1] == true);
assert(d[2] == false);
assert(d[3] == true);
assert(d[4] == true);
assert(d[5] == false);
assert(d[6] == true);
assert(d[7] == true);
assert(d[8] == true);
assert(d[9] == true);
assert(d[10] == true);
assert(d[11] == true);
assert(d[12] == true);
assert(d[13] == true);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@@ -16,6 +16,7 @@
#include <vector>
#include <cassert>
#include "test_iterators.h"
#include "../../min_allocator.h"
int main()
{
@@ -51,4 +52,38 @@ int main()
for (; j < 105; ++j)
assert(v[j] == 0);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> v(100);
bool a[] = {1, 0, 0, 1, 1};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::vector<bool, min_allocator<bool>>::iterator i = v.insert(v.cbegin() + 10, input_iterator<const bool*>(a),
input_iterator<const bool*>(a+N));
assert(v.size() == 100 + N);
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (int k = 0; k < N; ++j, ++k)
assert(v[j] == a[k]);
for (; j < 105; ++j)
assert(v[j] == 0);
}
{
std::vector<bool, min_allocator<bool>> v(100);
bool a[] = {1, 0, 0, 1, 1};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::vector<bool, min_allocator<bool>>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const bool*>(a),
forward_iterator<const bool*>(a+N));
assert(v.size() == 100 + N);
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (int k = 0; k < N; ++j, ++k)
assert(v[j] == a[k]);
for (; j < 105; ++j)
assert(v[j] == 0);
}
#endif
}

View File

@@ -15,6 +15,8 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
{
@@ -30,4 +32,19 @@ int main()
for (++j; j < 105; ++j)
assert(v[j] == 0);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> v(100);
std::vector<bool, min_allocator<bool>>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
assert(v.size() == 105);
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
for (; j < 15; ++j)
assert(v[j] == 1);
for (++j; j < 105; ++j)
assert(v[j] == 0);
}
#endif
}

View File

@@ -15,6 +15,8 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
{
@@ -29,4 +31,18 @@ int main()
for (++j; j < 101; ++j)
assert(v[j] == 0);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> v(100);
std::vector<bool, min_allocator<bool>>::iterator i = v.insert(v.cbegin() + 10, 1);
assert(v.size() == 101);
assert(i == v.begin() + 10);
int j;
for (j = 0; j < 10; ++j)
assert(v[j] == 0);
assert(v[j] == 1);
for (++j; j < 101; ++j)
assert(v[j] == 0);
}
#endif
}

View File

@@ -20,6 +20,8 @@
#include <cassert>
#include <iterator>
#include "../../min_allocator.h"
int main()
{
{
@@ -56,4 +58,40 @@ int main()
C::iterator i;
C::const_iterator j;
}
#if __cplusplus >= 201103L
{
typedef bool T;
typedef std::vector<T, min_allocator<T>> C;
C c;
C::iterator i = c.begin();
C::iterator j = c.end();
assert(std::distance(i, j) == 0);
assert(i == j);
}
{
typedef bool T;
typedef std::vector<T, min_allocator<T>> C;
const C c;
C::const_iterator i = c.begin();
C::const_iterator j = c.end();
assert(std::distance(i, j) == 0);
assert(i == j);
}
{
typedef bool T;
typedef std::vector<T, min_allocator<T>> C;
C c;
C::const_iterator i = c.cbegin();
C::const_iterator j = c.cend();
assert(std::distance(i, j) == 0);
assert(i == j);
assert(i == c.end());
}
{
typedef bool T;
typedef std::vector<T, min_allocator<T>> C;
C::iterator i;
C::const_iterator j;
}
#endif
}

View File

@@ -14,6 +14,7 @@
#include <vector>
#include <cassert>
#include "../../test_allocator.h"
#include "../../min_allocator.h"
int main()
{
@@ -44,5 +45,20 @@ int main()
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool> > l(min_allocator<bool>{});
std::vector<bool, min_allocator<bool> > lo(min_allocator<bool>{});
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
std::vector<bool, min_allocator<bool> > l2 = std::move(l);
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -14,6 +14,7 @@
#include <vector>
#include <cassert>
#include "../../test_allocator.h"
#include "../../min_allocator.h"
int main()
{
@@ -57,5 +58,20 @@ int main()
assert(!l.empty());
assert(l2.get_allocator() == other_allocator<bool>(4));
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool> > l(min_allocator<bool>{});
std::vector<bool, min_allocator<bool> > lo(min_allocator<bool>{});
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
std::vector<bool, min_allocator<bool> > l2(std::move(l), min_allocator<bool>());
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == min_allocator<bool>());
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -14,9 +14,12 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
std::vector<bool> d;
d = {true, false, false, true};
assert(d.size() == 4);
@@ -24,5 +27,17 @@ int main()
assert(d[1] == false);
assert(d[2] == false);
assert(d[3] == true);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> d;
d = {true, false, false, true};
assert(d.size() == 4);
assert(d[0] == true);
assert(d[1] == false);
assert(d[2] == false);
assert(d[3] == true);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@@ -15,12 +15,14 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
{
bool a[] = {0, 1, 1, 0, 1, 0, 0};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::vector<int> c;
std::vector<bool> c;
for (unsigned i = 0; i < N; ++i)
{
c.push_back(a[i]);
@@ -29,4 +31,18 @@ int main()
assert(c[j] == a[j]);
}
}
#if __cplusplus >= 201103L
{
bool a[] = {0, 1, 1, 0, 1, 0, 0};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::vector<bool, min_allocator<bool>> c;
for (unsigned i = 0; i < N; ++i)
{
c.push_back(a[i]);
assert(c.size() == i+1);
for (int j = 0; j < c.size(); ++j)
assert(c[j] == a[j]);
}
}
#endif
}

View File

@@ -15,6 +15,8 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
{
@@ -32,4 +34,21 @@ int main()
assert(v.size() == 100);
assert(v.capacity() >= 150);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> v;
v.reserve(10);
assert(v.capacity() >= 10);
}
{
std::vector<bool, min_allocator<bool>> v(100);
assert(v.capacity() >= 100);
v.reserve(50);
assert(v.size() == 100);
assert(v.capacity() >= 100);
v.reserve(150);
assert(v.size() == 100);
assert(v.capacity() >= 150);
}
#endif
}

View File

@@ -15,6 +15,8 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
{
@@ -26,4 +28,15 @@ int main()
assert(v.size() == 200);
assert(v.capacity() >= 200);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> v(100);
v.resize(50);
assert(v.size() == 50);
assert(v.capacity() >= 100);
v.resize(200);
assert(v.size() == 200);
assert(v.capacity() >= 200);
}
#endif
}

View File

@@ -15,6 +15,8 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
{
@@ -31,4 +33,20 @@ int main()
for (unsigned i = 50; i < 200; ++i)
assert(v[i] == 1);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> v(100);
v.resize(50, 1);
assert(v.size() == 50);
assert(v.capacity() >= 100);
assert((v == std::vector<bool, min_allocator<bool>>(50)));
v.resize(200, 1);
assert(v.size() == 200);
assert(v.capacity() >= 200);
for (unsigned i = 0; i < 50; ++i)
assert(v[i] == 0);
for (unsigned i = 50; i < 200; ++i)
assert(v[i] == 1);
}
#endif
}

View File

@@ -15,6 +15,8 @@
#include <vector>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
{
@@ -24,4 +26,13 @@ int main()
assert(v.capacity() >= 101);
assert(v.size() >= 101);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> v(100);
v.push_back(1);
v.shrink_to_fit();
assert(v.capacity() >= 101);
assert(v.size() >= 101);
}
#endif
}

View File

@@ -15,6 +15,7 @@
#include <vector>
#include <cassert>
#include "../../test_allocator.h"
#include "../../min_allocator.h"
int main()
{
@@ -61,4 +62,37 @@ int main()
assert(v[0] == false);
assert(v[1] == true);
}
#if __cplusplus >= 201103L
{
std::vector<bool, min_allocator<bool>> v1(100);
std::vector<bool, min_allocator<bool>> v2(200);
v1.swap(v2);
assert(v1.size() == 200);
assert(v1.capacity() >= 200);
assert(v2.size() == 100);
assert(v2.capacity() >= 100);
}
{
typedef min_allocator<bool> A;
std::vector<bool, A> v1(100, true, A());
std::vector<bool, A> v2(200, false, A());
swap(v1, v2);
assert(v1.size() == 200);
assert(v1.capacity() >= 200);
assert(v2.size() == 100);
assert(v2.capacity() >= 100);
assert(v1.get_allocator() == A());
assert(v2.get_allocator() == A());
}
{
std::vector<bool, min_allocator<bool>> v(2);
std::vector<bool, min_allocator<bool>>::reference r1 = v[0];
std::vector<bool, min_allocator<bool>>::reference r2 = v[1];
r1 = true;
using std::swap;
swap(r1, r2);
assert(v[0] == false);
assert(v[1] == true);
}
#endif
}

View File

@@ -33,6 +33,7 @@
#include "../../test_allocator.h"
#include "../../Copyable.h"
#include "../../min_allocator.h"
template <class Allocator>
void
@@ -43,8 +44,8 @@ test()
static_assert((std::is_same<typename C::value_type, bool>::value), "");
static_assert((std::is_same<typename C::value_type, typename Allocator::value_type>::value), "");
static_assert((std::is_same<typename C::allocator_type, Allocator>::value), "");
static_assert((std::is_same<typename C::size_type, typename Allocator::size_type>::value), "");
static_assert((std::is_same<typename C::difference_type, typename Allocator::difference_type>::value), "");
static_assert((std::is_same<typename C::size_type, typename std::allocator_traits<Allocator>::size_type>::value), "");
static_assert((std::is_same<typename C::difference_type, typename std::allocator_traits<Allocator>::difference_type>::value), "");
static_assert((std::is_same<
typename std::iterator_traits<typename C::iterator>::iterator_category,
std::random_access_iterator_tag>::value), "");
@@ -65,4 +66,7 @@ int main()
test<std::allocator<bool> >();
static_assert((std::is_same<std::vector<bool>::allocator_type,
std::allocator<bool> >::value), "");
#if __cplusplus >= 201103L
test<min_allocator<bool> >();
#endif
}

View File

@@ -22,8 +22,11 @@
#include <cassert>
#include <type_traits>
#include "../../min_allocator.h"
int main()
{
{
typedef std::vector<bool> T;
typedef std::hash<T> H;
static_assert((std::is_base_of<std::unary_function<T, std::size_t>,
@@ -32,4 +35,17 @@ int main()
T vb(std::begin(ba), std::end(ba));
H h;
assert(h(vb) != 0);
}
#if __cplusplus >= 201103L
{
typedef std::vector<bool, min_allocator<bool>> T;
typedef std::hash<T> H;
static_assert((std::is_base_of<std::unary_function<T, std::size_t>,
H>::value), "");
bool ba[] = {true, false, true, true, false};
T vb(std::begin(ba), std::end(ba));
H h;
assert(h(vb) != 0);
}
#endif
}