libcxx initial import
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103490 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <vector>
|
||||
|
||||
// size_type capacity() const;
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::vector<int> v;
|
||||
assert(v.capacity() == 0);
|
||||
}
|
||||
{
|
||||
std::vector<int> v(100);
|
||||
assert(v.capacity() == 100);
|
||||
v.push_back(0);
|
||||
assert(v.capacity() > 101);
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <vector>
|
||||
|
||||
// void reserve(size_type n);
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include "../../../stack_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::vector<int> v;
|
||||
v.reserve(10);
|
||||
assert(v.capacity() >= 10);
|
||||
}
|
||||
{
|
||||
std::vector<int> 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);
|
||||
}
|
||||
{
|
||||
std::vector<int, stack_allocator<int, 250> > 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);
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <vector>
|
||||
|
||||
// void resize(size_type sz);
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include "../../../stack_allocator.h"
|
||||
#include "../../../MoveOnly.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _LIBCPP_MOVE
|
||||
{
|
||||
std::vector<MoveOnly> v(100);
|
||||
v.resize(50);
|
||||
assert(v.size() == 50);
|
||||
assert(v.capacity() == 100);
|
||||
v.resize(200);
|
||||
assert(v.size() == 200);
|
||||
assert(v.capacity() >= 200);
|
||||
}
|
||||
{
|
||||
std::vector<MoveOnly, stack_allocator<MoveOnly, 300> > v(100);
|
||||
v.resize(50);
|
||||
assert(v.size() == 50);
|
||||
assert(v.capacity() == 100);
|
||||
v.resize(200);
|
||||
assert(v.size() == 200);
|
||||
assert(v.capacity() >= 200);
|
||||
}
|
||||
#else
|
||||
{
|
||||
std::vector<int> v(100);
|
||||
v.resize(50);
|
||||
assert(v.size() == 50);
|
||||
assert(v.capacity() == 100);
|
||||
v.resize(200);
|
||||
assert(v.size() == 200);
|
||||
assert(v.capacity() >= 200);
|
||||
}
|
||||
{
|
||||
std::vector<int, stack_allocator<int, 300> > 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
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <vector>
|
||||
|
||||
// void resize(size_type sz, const value_type& x);
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include "../../../stack_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::vector<int> v(100);
|
||||
v.resize(50, 1);
|
||||
assert(v.size() == 50);
|
||||
assert(v.capacity() == 100);
|
||||
assert(v == std::vector<int>(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);
|
||||
}
|
||||
{
|
||||
std::vector<int, stack_allocator<int, 300> > v(100);
|
||||
v.resize(50, 1);
|
||||
assert(v.size() == 50);
|
||||
assert(v.capacity() == 100);
|
||||
v.resize(200, 1);
|
||||
assert(v.size() == 200);
|
||||
assert(v.capacity() >= 200);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <vector>
|
||||
|
||||
// void shrink_to_fit();
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include "../../../stack_allocator.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::vector<int> v(100);
|
||||
v.push_back(1);
|
||||
v.shrink_to_fit();
|
||||
assert(v.capacity() == 101);
|
||||
assert(v.size() == 101);
|
||||
}
|
||||
{
|
||||
std::vector<int, stack_allocator<int, 401> > v(100);
|
||||
v.push_back(1);
|
||||
v.shrink_to_fit();
|
||||
assert(v.capacity() == 101);
|
||||
assert(v.size() == 101);
|
||||
}
|
||||
{
|
||||
std::vector<int, stack_allocator<int, 400> > v(100);
|
||||
v.push_back(1);
|
||||
v.shrink_to_fit();
|
||||
assert(v.capacity() == 200);
|
||||
assert(v.size() == 101);
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <vector>
|
||||
|
||||
// void swap(vector& x);
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::vector<int> v1(100);
|
||||
std::vector<int> v2(200);
|
||||
v1.swap(v2);
|
||||
assert(v1.size() == 200);
|
||||
assert(v1.capacity() == 200);
|
||||
assert(v2.size() == 100);
|
||||
assert(v2.capacity() == 100);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user