Skip to content
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
2 changes: 0 additions & 2 deletions tests/0026.container/.test_prop.toml

This file was deleted.

2 changes: 2 additions & 0 deletions tests/0026.container/0001.vector/append_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ using namespace fast_io::mnp;

int main()
{
#if 0
auto head = fast_io::vector<int>{1, 2, 3, 4};
auto const tail = std::list{-5, -6, -7};
head.append_range(tail);
assert(std::ranges::equal(head, fast_io::vector<int>{1, 2, 3, 4, -5, -6, -7}));
#endif
}
4 changes: 3 additions & 1 deletion tests/0026.container/0001.vector/assign.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ int main()
characters.assign(5, 'a');
print_vector();

#if 0
std::string const extra(6, 'b');
characters.assign(extra.begin(), extra.end());
print_vector();

characters.assign({'C', '+', '+', '1', '1'});
print_vector();
}
#endif
}
2 changes: 2 additions & 0 deletions tests/0026.container/0001.vector/assign_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

int main()
{
#if 0
auto const source = std::list{2, 7, 1};
auto destination = fast_io::vector{3, 1, 4};
destination.assign_range(source);
assert(std::ranges::equal(source, destination));
#endif
}
4 changes: 2 additions & 2 deletions tests/0026.container/0001.vector/capacity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ int main()
v.push_back(sz);
if (cap != v.capacity())
{
println(left(v.size(), 7), left(v.capacity(), 11), left(v.capacity() / static_cast<float>(cap), 10));
println(left(v.size(), 7), left(v.capacity(), 11), left(float(v.capacity()) / static_cast<float>(cap), 10));
cap = v.capacity();
}
}

println("\nFinal size: ", v.size(), ", capacity: ", v.capacity());
}
}
8 changes: 5 additions & 3 deletions tests/0026.container/0001.vector/emplace_back.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <cassert>
#include <string>
#include <string>
#include <fast_io.h>
#include <fast_io_dsal/vector.h>
using namespace fast_io::io;
Expand Down Expand Up @@ -31,7 +30,10 @@ int main()
fast_io::vector<President> elections;
print("emplace_back:\n");
auto &ref = elections.emplace_back("Nelson Mandela", "South Africa", 1994);
assert(ref.year == 1994 && "uses a reference to the created object (C++17)");
if (ref.year != 1994)
{
::fast_io::fast_terminate();
}

fast_io::vector<President> reElections;
print("\npush_back:\n");
Expand Down
3 changes: 2 additions & 1 deletion tests/0026.container/0001.vector/insert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int main()
auto it = c1.begin();
it = c1.insert(it, 200);
print_info(2, c1);

#if 0
c1.insert(it, 2, 300);
print_info(3, c1);

Expand All @@ -34,4 +34,5 @@ int main()

c1.insert(c1.end(), {601, 602, 603});
print_info(6, c1);
#endif
}
2 changes: 2 additions & 0 deletions tests/0026.container/0001.vector/insert_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ using namespace fast_io::mnp;

int main()
{
#if 0
auto container = fast_io::vector{1, 2, 3, 4};
auto pos = std::next(container.begin(), 2);
assert(*pos == 3);
auto const rg = std::list{-1, -2, -3};

container.insert_range(pos, rg);
assert(std::ranges::equal(container, fast_io::vector{1, 2, -1, -2, -3, 3, 4}));
#endif
}
4 changes: 3 additions & 1 deletion tests/0026.container/0001.vector/max_size.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include <fast_io.h>
#include <fast_io_i18n.h>
// #include <fast_io_i18n.h>
#include <fast_io_dsal/vector.h>
using namespace fast_io::io;
using namespace fast_io::mnp;

int main()
{
#if 0
fast_io::vector<char> q;
fast_io::native_l10n l10n{"en_US.UTF-8"};
println(imbue(l10n, fast_io::c_stdout()), "Maximum size of a std::vector is ", q.max_size());
#endif
}
5 changes: 4 additions & 1 deletion tests/0026.container/0001.vector/operator_assign.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ using namespace fast_io::mnp;
int main()
{
fast_io::vector<int> x{1, 2, 3}, y, z;
auto const w = {4, 5, 6, 7};

print("Initially:\n");
print("x = {", rgvw(x, ", "), "}\ny = {", rgvw(y, ", "), "}\nz = {", rgvw(z, ", "), "}\n");
Expand All @@ -21,7 +20,11 @@ int main()
z = std::move(x);
print("x = {", rgvw(x, ", "), "}\nz = {", rgvw(z, ", "), "}\n");

#if 0
auto const w = {4, 5, 6, 7};

print("Assignment of initializer_list w to z:\n");
z = w;
print("w = {", rgvw(w, ", "), "}\nz = {", rgvw(z, ", "), "}\n");
#endif
}
26 changes: 20 additions & 6 deletions tests/0026.container/0001.vector/recursive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ struct Node2
{
fast_io::vector<Base> subast;

Node2();
Node2(fast_io::vector<Base> sub);
~Node2();
constexpr Node2();
constexpr Node2(fast_io::vector<Base> sub);
constexpr ~Node2();

template <typename>
constexpr int a_method(int) const noexcept;
};

struct Base
Expand All @@ -30,10 +33,16 @@ struct Base
{}
};

Node2::Node2() = default;
Node2::Node2(fast_io::vector<Base> sub) : subast(std::move(sub))
constexpr Node2::Node2() = default;
constexpr Node2::Node2(fast_io::vector<Base> sub) : subast(std::move(sub))
{}
Node2::~Node2() = default;
constexpr Node2::~Node2() = default;

template <typename>
constexpr int Node2::a_method(int) const noexcept
{
return 42;
}

using Ast = fast_io::vector<Base>;

Expand All @@ -58,6 +67,11 @@ int main()
}
else if constexpr (std::is_same_v<T, Node2>)
{
int const v{n.template a_method<int>(0)};
if (v != 42)
{
::fast_io::fast_terminate();
}
}
else if constexpr (std::is_same_v<T, Node3>)
{
Expand Down
42 changes: 28 additions & 14 deletions tests/0026.container/0001.vector/reserve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,60 @@ using namespace fast_io::mnp;
// minimal allocator with debug output
struct NAlloc
{
static void *allocate(std::size_t n)
static void *allocate(std::size_t n) noexcept
{
void *p = ::operator new(n);
println("allocating ", n, " bytes @ ", pointervw(p));
return p;
}
static void deallocate_n(void *p, std::size_t n)
static void deallocate_n(void *p, std::size_t) noexcept
{
print("deallocating ", n, " bytes @ ", pointervw(p), "\n\n");
::operator delete(p);
}
constexpr bool operator==(NAlloc const &) const noexcept = default;
static void deallocate(void *p) noexcept
{
::operator delete(p);
}
constexpr bool operator==(::NAlloc const &) const noexcept = default;
};

using NAllocAdapter = fast_io::generic_allocator_adapter<NAlloc>;

int main()
{
constexpr int max_elements = 32;

print("using reserve: \n");
// using reserve
{
fast_io::vector<int, NAlloc> v1;
fast_io::vector<int, ::NAllocAdapter> v1;
v1.reserve(max_elements); // reserves at least max_elements * sizeof(int) bytes

for (int n = 0; n < max_elements; ++n)
{
v1.push_back(n);
}
for (int n = 0; n < max_elements; ++n)
{
int v{v1[n]};
if (v != n) {
::fast_io::fast_terminate();
}
}
}

print("not using reserve: \n");
// not using reserve
{
fast_io::vector<int, NAlloc> v1;
fast_io::vector<int, ::NAllocAdapter> v1;

for (int n = 0; n < max_elements; ++n)
{
if (v1.size() == v1.capacity())
{
println("size() == capacity() == ", v1.size());
}
v1.push_back(n);
}
for (int n = 0; n < max_elements; ++n)
{
int v{v1[n]};
if (v != n) {
::fast_io::fast_terminate();
}
}
}
}
}
4 changes: 2 additions & 2 deletions tests/0026.container/0001.vector/resize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void print_info(auto rem, fast_io::vector<int> const &c)

int main()
{
fast_io::vector<int> c = {1, 2, 3};
fast_io::vector<int> c{1, 2, 3};
print_info("The vector holds: ", c);

c.resize(5);
Expand All @@ -21,4 +21,4 @@ int main()

c.resize(6, 4);
print_info("After resize up to 6 (initializer = 4): ", c);
}
}
7 changes: 4 additions & 3 deletions tests/0026.container/0001.vector/vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ int main()
// C++11 initializer list syntax:
fast_io::vector<std::string> words1{"the", "frogurt", "is", "also", "cursed"};
print("1: {", rgvw(words1, ", "), "}\n");

#if 0
// words2 == words1
fast_io::vector<std::string> words2(::std::from_range, words1);
print("2: {", rgvw(words2, ", "), "}\n");

#endif
// words3 == words1
fast_io::vector<std::string> words3(words1);
print("3: {", rgvw(words3, ", "), "}\n");

// words4 is {"Mo", "Mo", "Mo", "Mo", "Mo"}
fast_io::vector<std::string> words4(5, "Mo");
print("4: {", rgvw(words4, ", "), "}\n");

#if 0
auto const rg = {"cat", "cow", "crow"};
fast_io::vector<std::string> words5(::std::from_range, rg); // overload (11)
print("5: {", rgvw(words5, ", "), "}\n");
#endif
}
Loading