28 #include <boost/algorithm/string.hpp> 37 #if FOLLY_X64 || FOLLY_PPC64 41 "Object size is not what we expect for small_vector<int>");
44 "Object size is not what we expect for " 45 "small_vector<int32_t,2>");
48 "Object size is not what we expect for small_vector<int,10>");
52 "small_vector<int32_t,1,uint32_t> is wrong size");
57 "small_vector<int32_t,1,uint16_t> is wrong size");
60 "small_vector not aligned correctly");
65 "small_vector<int32_t,1,uint8_t> is wrong size");
68 "small_vector not aligned correctly");
72 "Sizeof unexpectedly large");
78 "std::unique_ptr<> is trivially copyable");
82 "small_vector not aligned correctly");
86 template <
typename Key,
typename Value,
size_t N>
91 std::allocator<std::pair<Key, Value>>,
95 template <
typename Key,
typename Value,
size_t N>
100 std::allocator<std::pair<Key, Value>>,
103 std::pair<Key, Value>,
105 folly::small_vector_policy::NoHeap>>;
107 template <
typename T,
size_t N>
115 template <
typename T,
size_t N>
123 struct NontrivialType {
125 explicit NontrivialType() :
a(0) {}
127 NontrivialType(
int a_) :
a(a_) {
131 NontrivialType(NontrivialType
const& ) {
135 NontrivialType& operator=(NontrivialType
const& o) {
144 "NontrivialType is trivially copyable");
146 int NontrivialType::ctored = 0;
148 struct TestException {};
150 int throwCounter = 1;
152 if (!--throwCounter) {
153 throw TestException();
157 const int kMagic = 0xdeadbeef;
161 Thrower() : magic(kMagic) {
166 Thrower(Thrower
const& other) : magic(other.magic) {
177 Thrower& operator=(Thrower
const& ) {
188 int Thrower::alive = 0;
192 struct NoncopyableCounter {
194 NoncopyableCounter() {
197 ~NoncopyableCounter() {
200 NoncopyableCounter(NoncopyableCounter&&)
noexcept {
203 NoncopyableCounter(NoncopyableCounter
const&) =
delete;
204 NoncopyableCounter& operator=(NoncopyableCounter
const&)
const =
delete;
205 NoncopyableCounter& operator=(NoncopyableCounter&&) {
209 int NoncopyableCounter::alive = 0;
213 "NoncopyableCounter is trivially copyable");
219 struct TestBasicGuarantee {
221 int const prepopulate;
223 explicit TestBasicGuarantee(
int prepopulate_) : prepopulate(prepopulate_) {
225 for (
int i = 0;
i < prepopulate; ++
i) {
230 ~TestBasicGuarantee() {
234 template <
class Operation>
235 void operator()(
int insertCount, Operation
const&
op) {
238 std::unique_ptr<folly::small_vector<Thrower, 3>> workingVec;
241 workingVec = std::make_unique<folly::small_vector<Thrower, 3>>(
vec);
243 EXPECT_EQ(Thrower::alive, prepopulate * 2);
257 EXPECT_EQ(workingVec->size(), prepopulate + insertCount);
258 EXPECT_EQ(Thrower::alive, prepopulate * 2 + insertCount);
266 for (
int prepop = 1; prepop < 30; ++prepop) {
267 (TestBasicGuarantee(prepop))(
287 std::vector<Thrower>
b;
298 v.insert(
v.begin() + 1, b.begin(), b.end());
302 std::vector<Thrower>
b;
303 for (
int i = 0;
i < 6; ++
i) {
307 v.insert(
v.begin() + 1, b.begin(), b.end());
324 for (
int j = 0; j < 1000; ++j) {
326 for (
int i = 0;
i < 10000; ++
i) {
336 for (
size_t i = 0;
i < someVec.
size(); ++
i) {
344 auto oldSize = someVec.
size();
349 v1.insert(v1.begin() + 1, v2.begin(), v2.end());
363 auto vec = somethingVec;
372 for (
auto i : junkVec) {
385 for (
auto i : moreJunk) {
390 for (
auto i : moreJunk) {
401 shrinker = {0, 1, 2, 3, 4, 5, 6, 7, 8};
404 swap(shrinker, other);
411 NontrivialType::ctored = 0;
423 NontrivialType::ctored = 0;
424 for (
int i = 0;
i < 120; ++
i) {
434 NontrivialType::ctored = 0;
452 folly::small_vector<int, 2> vec2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
471 std::generate_n(std::back_inserter(vec), 102, std::rand);
475 auto oldSize = vec.
size();
476 for (
size_t i = 0;
i < oldSize; ++
i) {
483 std::generate_n(std::back_inserter(vec), 102, std::rand);
486 std::generate_n(std::back_inserter(vec), 4096, std::rand);
504 std::vector<std::string> otherVec;
505 for (
auto&
s : vec) {
506 otherVec.push_back(
s);
509 if (otherVec.size() == vec.size()) {
510 EXPECT_TRUE(std::equal(otherVec.begin(), otherVec.end(), vec.begin()));
513 std::reverse(otherVec.begin(), otherVec.end());
514 auto oit = otherVec.begin();
515 auto rit = vec.crbegin();
516 for (; rit != vec.crend(); ++oit, ++rit) {
524 for (
int i = 0;
i < 10; ++
i) {
534 for (
int i = 0;
i < 10; ++
i) {
540 EXPECT_EQ(NoncopyableCounter::alive, 10);
542 vec3.
insert(vec3.
begin() + 3, NoncopyableCounter());
543 EXPECT_EQ(NoncopyableCounter::alive, 11);
545 EXPECT_EQ(NoncopyableCounter::alive, 11);
547 EXPECT_EQ(NoncopyableCounter::alive, 30);
548 vec4.erase(vec4.begin(), vec4.end());
573 folly::small_vector_policy::NoHeap>
577 static_assert(v.max_size() == 10,
"max_size is incorrect");
579 for (
int i = 0;
i < 10; ++
i) {
580 v.push_back(folly::to<std::string>(
i));
586 v.insert(v.begin(),
"ha");
587 }
catch (
const std::length_error&) {
603 notsosmall.
max_size() ==
sizeof(
char*),
"max_size is incorrect");
609 }
catch (
const std::length_error&) {
619 EXPECT_EQ(vec2.max_size(), (1 << 15) - 1);
625 double a,
b,
c, d, e;
627 SomeObj(
int val_) :
val(val_) {}
656 a.emplace(a.end(), 32);
659 a.emplace(a.begin(), 12);
662 a.erase(a.end() - 1);
715 const size_t hc_size = 100000;
716 for (
size_t i = 0;
i < hc_size; ++
i) {
717 auto v = (
unsigned char)
i;
723 for (
auto i = hc_size;
i > 0; --
i) {
724 auto v = (
unsigned char)(
i - 1);
732 for (
int i = 1;
i < 33; ++
i) {
734 for (
int j = 0; j <
i; ++j) {
746 for (
int i = 1;
i < 33; ++
i) {
748 for (
int j = 0; j <
i; ++j) {
761 for (
int i = 1;
i < 33; ++
i) {
763 for (
int j = 0; j <
i; ++j) {
775 for (
int i = 2;
i < 33; ++
i) {
777 for (
int j = 0; j <
i; ++j) {
790 static const int DEFAULT_VALUE = (int)0xdeadbeef;
796 rhs.value = DEFAULT_VALUE;
804 rhs.value = DEFAULT_VALUE;
814 for (
int i = 1;
i < 20; ++
i) {
823 for (
int i = 1;
i < 20; ++
i) {
833 for (
int i = 1;
i < 20; ++
i) {
842 for (
int i = 1;
i < 20; ++
i) {
852 for (
int i = 1;
i < 20; ++
i) {
861 for (
int i = 1;
i < 20; ++
i) {
869 std::vector<int*>
v{
new int(1),
new int(2)};
870 std::vector<std::unique_ptr<int>> uv(
v.begin(),
v.end());
872 std::vector<int*> w{
new int(1),
new int(2)};
877 std::vector<int> expected{125, 320, 512, 750, 333};
879 std::istringstream is1(values);
880 std::istringstream is2(values);
882 std::vector<int> stdV{std::istream_iterator<int>(is1),
883 std::istream_iterator<int>()};
885 for (
size_t i = 0;
i < expected.size();
i++) {
890 std::istream_iterator<int>()};
891 ASSERT_EQ(smallV.size(), expected.size());
892 for (
size_t i = 0;
i < expected.size();
i++) {
900 Test(
const Test&) =
delete;
901 Test(Test&&) =
default;
908 for (
const auto& element : test) {
916 for (
const auto& element : test) {
924 for (
auto element : test) {
931 std::vector<size_t> capacities;
932 capacities.push_back(test.
capacity());
933 for (
int i = 0;
i < 10000; ++
i) {
935 if (test.
capacity() != capacities.back()) {
936 capacities.push_back(test.
capacity());
944 std::vector<size_t> capacities;
945 capacities.push_back(test.
capacity());
946 for (
int i = 0;
i < 10000; ++
i) {
948 if (test.
capacity() != capacities.back()) {
949 capacities.push_back(test.
capacity());
957 std::vector<size_t> capacities;
958 capacities.push_back(test.
capacity());
959 for (
int i = 0;
i < 10000; ++
i) {
961 if (test.
capacity() != capacities.back()) {
962 capacities.push_back(test.
capacity());
978 explicit Counter(Counts& counts_) : counts(&counts_) {}
1052 small_sorted_vector_map<int32_t, int32_t, 2>
test;
1053 test.insert(std::make_pair(10, 10));
1055 test.insert(std::make_pair(10, 10));
1057 test.insert(std::make_pair(20, 10));
1059 test.insert(std::make_pair(30, 10));
1064 noheap_sorted_vector_map<int32_t, int32_t, 2>
test;
1065 test.insert(std::make_pair(10, 10));
1067 test.insert(std::make_pair(10, 10));
1069 test.insert(std::make_pair(20, 10));
1071 EXPECT_THROW(test.insert(std::make_pair(30, 10)), std::length_error);
1076 small_sorted_vector_set<int32_t, 2>
test;
1088 noheap_sorted_vector_set<int32_t, 2>
test;
1104 test =
static_cast<decltype(test)&&
>(
test);
1114 test =
static_cast<decltype(test)&
>(
test);
void reserve(size_type sz)
iterator emplace(const_iterator p, Args &&...args)
#define EXPECT_LE(val1, val2)
#define EXPECT_THROW(statement, expected_exception)
#define ASSERT_EQ(val1, val2)
void emplace_back(Args &&...args)
Map field(FieldType Class::*field)
#define EXPECT_EQ(val1, val2)
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
constexpr detail::Map< Move > move
internal::KeyMatcher< M > Key(M inner_matcher)
static constexpr size_type max_size()
requires E e noexcept(noexcept(s.error(std::move(e))))
ThreadCachedInt< int64_t > Counter
FOLLY_PUSH_WARNING RHS rhs
iterator insert(const_iterator constp, value_type &&t)
void assign(Arg first, Arg last)
bool Value(const T &value, M matcher)
void push_back(value_type &&t)
CheckedInt & operator=(CheckedInt &&rhs) noexcept
CheckedInt(CheckedInt &&rhs) noexcept
CheckedInt & operator=(const CheckedInt &rhs)
std::is_trivially_copyable< T > is_trivially_copyable
void resize(size_type sz)
CheckedInt(const CheckedInt &rhs)
#define EXPECT_TRUE(condition)
void swap(exception_wrapper &a, exception_wrapper &b) noexcept
bool operator==(const Unexpected< Error > &lhs, const Unexpected< Error > &rhs)
std::atomic< int > counter
CheckedInt(const CheckedInt &rhs, int)
iterator erase(const_iterator q)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
#define EXPECT_FALSE(condition)
#define EXPECT_LT(val1, val2)
TEST(SequencedExecutor, CPUThreadPoolExecutor)
std::vector< int > values(1'000)
constexpr detail::First first
Composed all(Predicate pred=Predicate())
size_type capacity() const
#define EXPECT_GT(val1, val2)