Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
cde9f44
add basic gtest framework
wusatosi Dec 11, 2024
5eb8151
add outline for spec test
wusatosi Dec 11, 2024
0d29b77
Update CMakeLists.txt
wusatosi Dec 11, 2024
d953f95
Added tests for [container.reqmts]
jbab Dec 16, 2024
d33b8e8
Added second spec test suite (experimental, suggestion), added tests …
jbab Dec 17, 2024
97345e6
update trivial type wording
wusatosi Dec 25, 2024
6b35bbc
format
wusatosi Dec 25, 2024
c854038
expand test structure
wusatosi Dec 25, 2024
73dee7b
add erase checks
wusatosi Jan 4, 2025
caa14ad
complete more erasure
wusatosi Jan 4, 2025
b8d30f8
complete modifiers/erasesingle modifier/popback
wusatosi Jan 4, 2025
f73c4fe
Add minimal for reserve shrink
wusatosi Jan 14, 2025
3b74798
Fix PopBack test
wusatosi Jan 14, 2025
e970fa2
Include Reserve and shrink
wusatosi Jan 14, 2025
b883947
lint
wusatosi Jan 14, 2025
e75d44b
Implement erase tests
wusatosi Jan 14, 2025
9ca550e
add pushback/ emplaceback tests
wusatosi Jan 14, 2025
2a8b99e
Fix emplace back
wusatosi Jan 15, 2025
70cad6c
fold spec.test2 into spec.test
wusatosi Jan 15, 2025
0d146a7
refactor triviality tests
wusatosi Jan 15, 2025
ef169f9
Fix destructor
wusatosi Jan 15, 2025
81903c2
Fix Triviality/ZeroSized
wusatosi Jan 15, 2025
ddb19ac
lint
wusatosi Jan 15, 2025
c1bdbac
fix triviality
wusatosi Jan 16, 2025
f238186
Fix Tests
wusatosi Jan 16, 2025
c16ccb5
lint
wusatosi Jan 16, 2025
5b955bc
inline ambiguous concepts
wusatosi Jan 16, 2025
fb2bf93
lint
wusatosi Jan 16, 2025
1c1eb86
fix werror
wusatosi Jan 16, 2025
ab82c73
remove false positive werror check
wusatosi Jan 16, 2025
cbfe0c4
add tests for insert
wusatosi Jan 17, 2025
0d37485
implement insert ranges series
wusatosi Jan 17, 2025
bb97f12
add data tests
wusatosi Jan 17, 2025
2bec84a
Add testcase for size and resize
wusatosi Jan 17, 2025
f7a3b74
minor addition for resize test
wusatosi Jan 17, 2025
955e9f2
fix test
wusatosi Jan 17, 2025
d135f4a
dump [sequence.reqmts]
wusatosi Jan 17, 2025
30cb4a0
remove #if 0 chuck
wusatosi Jan 17, 2025
634b185
Fix compile
wusatosi Jan 17, 2025
c300258
Added SizedDefault Test
wusatosi Jan 17, 2025
d446946
Split test file
wusatosi Jan 17, 2025
2c9c721
Format Fix
wusatosi Jan 18, 2025
e9d8635
Finish constructor test suite
wusatosi Jan 18, 2025
fea9b08
Finish [sequence.reqmts]
wusatosi Jan 19, 2025
451f0c5
use uz
wusatosi Jan 20, 2025
e0ff597
adopt suggestion
wusatosi Jan 20, 2025
5b23f5a
beman::bad_alloc => std::bad_alloc
wusatosi Jan 20, 2025
212c829
Revert "use uz"
wusatosi Jan 20, 2025
d1f1705
allow c++20
wusatosi Jan 20, 2025
fa0eacb
Improvements to tests
jbab Jan 23, 2025
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
12 changes: 2 additions & 10 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
c: gcc
- cpp: clang++
c: clang
cpp_version: [23]
cpp_version: [20, 23]
cmake_args:
- description: "Default"
args: ""
Expand All @@ -50,15 +50,7 @@ jobs:
compiler:
cpp: g++
c: gcc
cpp_version: 23
cmake_args:
description: "Werror"
args: "-DCMAKE_CXX_FLAGS='-Wall -Wextra -Wpedantic -Werror'"
- platform: ubuntu-24.04
compiler:
cpp: g++
c: gcc
cpp_version: 23
cpp_version: 20
cmake_args:
description: "Dynamic"
cmake_args: "-DBUILD_SHARED_LIBS=on"
Expand Down
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ option(
${PROJECT_IS_TOP_LEVEL}
)

include(FetchContent)
include(GNUInstallDirs)

add_library(beman.inplace_vector INTERFACE)
Expand Down Expand Up @@ -59,6 +60,22 @@ install(

if(BEMAN_INPLACE_VECTOR_BUILD_TESTS)
include(CTest)
enable_testing()

# Fetch GoogleTest
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG
f8d7d77c06936315286eb55f8de22cd23c188571 # release-1.14.0
EXCLUDE_FROM_ALL
)

block()
set(INSTALL_GTEST OFF) # Disable GoogleTest installation
FetchContent_MakeAvailable(googletest)
endblock()

add_subdirectory(tests/beman/inplace_vector)
endif()

Expand Down
59 changes: 49 additions & 10 deletions include/beman/inplace_vector/inplace_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ template <class = void>
[[noreturn]]
static constexpr void __assert_failure(char const *__file, int __line,
char const *__msg) {
if consteval {
if (std::is_constant_evaluated()) {
throw __msg; // TODO: std lib implementer, do better here
} else {
fprintf(stderr, "%s(%d): %s\n", __file, __line, __msg);
Expand Down Expand Up @@ -459,7 +459,11 @@ template <class __T, size_t __N> struct __non_trivial {
constexpr __non_trivial &operator=(__non_trivial const &) noexcept = default;
constexpr __non_trivial(__non_trivial &&) noexcept = default;
constexpr __non_trivial &operator=(__non_trivial &&) noexcept = default;
constexpr ~__non_trivial() = default;

constexpr ~__non_trivial()
requires(is_trivially_destructible_v<__T>)
= default;
constexpr ~__non_trivial() { destroy(__data(), __data() + __size()); }
};

// Selects the vector storage.
Expand Down Expand Up @@ -500,7 +504,7 @@ struct inplace_vector : private __iv_detail::__storage::_t<__T, __N> {
using const_reverse_iterator = ::std::reverse_iterator<const_iterator>;

// [containers.sequences.inplace_vector.cons], construct/copy/destroy
constexpr inplace_vector() noexcept { __unsafe_set_size(0); }
constexpr inplace_vector() noexcept = default;
// constexpr explicit inplace_vector(size_type __n);
// constexpr inplace_vector(size_type __n, const __T& __value);
// template <class __InputIterator> // BUGBUG: why not model input_iterator?
Expand Down Expand Up @@ -694,11 +698,12 @@ struct inplace_vector : private __iv_detail::__storage::_t<__T, __N> {
}

template <class... __Args>
constexpr void emplace_back(__Args &&...__args)
constexpr __T &emplace_back(__Args &&...__args)
requires(constructible_from<__T, __Args...>)
{
if (!try_emplace_back(::std::forward<__Args>(__args)...)) [[unlikely]]
throw bad_alloc();
return back();
}
constexpr __T &push_back(const __T &__x)
requires(constructible_from<__T, const __T &>)
Expand Down Expand Up @@ -769,7 +774,8 @@ struct inplace_vector : private __iv_detail::__storage::_t<__T, __N> {
movable<__T>)
{
__assert_iterator_in_range(__position);
__assert_valid_iterator_pair(__first, __last);
// __assert_valid_iterator_pair(__first, __last); // does not work with
// arbitrary InputIterators
if constexpr (random_access_iterator<__InputIterator>) {
if (size() + static_cast<size_type>(distance(__first, __last)) >
capacity()) [[unlikely]]
Expand Down Expand Up @@ -934,27 +940,60 @@ struct inplace_vector : private __iv_detail::__storage::_t<__T, __N> {
}

constexpr inplace_vector(const inplace_vector &__x)
requires(copyable<__T>)
requires(__N == 0 || is_trivially_copy_constructible_v<__T>)
= default;

constexpr inplace_vector(const inplace_vector &__x)
requires(__N != 0 && !is_trivially_copy_constructible_v<__T> &&
copyable<__T>)
{
for (auto &&__e : __x)
emplace_back(__e);
}

constexpr inplace_vector(inplace_vector &&__x)
requires(movable<__T>)
requires(__N == 0 || is_trivially_move_constructible_v<__T>)
= default;

constexpr inplace_vector(inplace_vector &&__x)
requires(__N != 0 && !is_trivially_move_constructible_v<__T> &&
movable<__T>)
{
for (auto &&__e : __x)
emplace_back(::std::move(__e));
}

constexpr inplace_vector &operator=(const inplace_vector &__x)
requires(copyable<__T>)
requires(__N == 0 || (std::is_trivially_destructible_v<__T> &&
std::is_trivially_copy_constructible_v<__T> &&
std::is_trivially_copy_assignable_v<__T>))
= default;

constexpr inplace_vector &operator=(const inplace_vector &__x)
requires(__N != 0 &&
!(std::is_trivially_destructible_v<__T> &&
std::is_trivially_copy_constructible_v<__T> &&
std::is_trivially_copy_assignable_v<__T>) &&
copyable<__T>)
{
clear();
for (auto &&__e : __x)
emplace_back(__e);
return *this;
}

constexpr inplace_vector &operator=(inplace_vector &&__x)
requires(movable<__T>)
requires(__N == 0 || (std::is_trivially_destructible_v<__T> &&
std::is_trivially_move_constructible_v<__T> &&
std::is_trivially_move_assignable_v<__T>))
= default;

constexpr inplace_vector &operator=(inplace_vector &&__x)
requires(__N != 0 &&
!(std::is_trivially_destructible_v<__T> &&
std::is_trivially_move_constructible_v<__T> &&
std::is_trivially_move_assignable_v<__T>) &&
movable<__T>)
{
clear();
for (auto &&__e : __x)
Expand Down Expand Up @@ -985,7 +1024,7 @@ struct inplace_vector : private __iv_detail::__storage::_t<__T, __N> {
requires(constructible_from<__T, ranges::range_reference_t<__R>> &&
movable<__T>)
{
assign(begin(__rg), end(__rg));
assign(std::begin(__rg), std::end(__rg));
}
constexpr void assign(size_type __n, const __T &__u)
requires(constructible_from<__T, const __T &> && movable<__T>)
Expand Down
20 changes: 20 additions & 0 deletions tests/beman/inplace_vector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,23 @@ add_test(
NAME beman.inplace_vector.ref-test
COMMAND beman.inplace_vector.ref-test
)

# GoogleTest based tests
include(GoogleTest)

function(add_gtest NAME)
add_executable(beman.inplace_vector.tests.${NAME})
target_sources(beman.inplace_vector.tests.${NAME} PRIVATE ${NAME}.test.cpp)
target_link_libraries(
beman.inplace_vector.tests.${NAME}
PRIVATE beman.inplace_vector GTest::gtest GTest::gtest_main
)
gtest_add_tests(beman.inplace_vector.tests.${NAME} "" AUTO)
endfunction()

# Tests for official specs
add_gtest(container_requirements)
add_gtest(triviality)
add_gtest(constructors)
add_gtest(size_n_data)
add_gtest(erasure)
109 changes: 109 additions & 0 deletions tests/beman/inplace_vector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Inplace Vector Testing Suite

This folder contains tests for `inplace_vector` implementation.

The aim for the test cases are to keep the implementation in-check with its standing in the latest C++ draft.

You can checkout `inplace_vector`'s current state in C++ draft [here](https://eel.is/c++draft/inplace.vector).

## C++ Draft paragraph to test file

`inplace_vector`'s chapter number in the latest C++ draft is **23.3.14**.

### Overview (23.3.14.1)

[Overview](https://eel.is/c++draft/inplace.vector#overview) has 6 clauses.

#### 6.1 Overview

> An inplace_vector is a contiguous container. Its capacity is fixed and its
elements are stored within the inplace_vector object itself.

This is not testable.

#### 6.2 Container Requirements

> An inplace_vector meets all of the requirements of a container ([container.reqmts]),
> of a reversible container ([container.rev.reqmts]), of a contiguous container,
> and of a sequence container, including most of the optional sequence
container requirements ([sequence.reqmts]). The exceptions are the push_front,
> prepend_range, pop_front, and emplace_front member functions,
> which are not provided.
> Descriptions are provided here only for operations on inplace_vector that
> are not described in one of these tables or for operations where there is
> additional semantic information.

See [container_requirements.test.cpp](container_requirements.test.cpp).

#### 6.3 Constexpr Iterator

> For any N, `inplace_vector<T, N>​::​iterator` and
> `inplace_vector<T, N>​::​const_iterator` meet the constexpr iterator
> requirements.

Not tested for now.

#### 6.4 Constexpr member functions

> For any $N>0$, if T is not trivially copyable or
> `is_trivially_default_constructible_v<T>` is false,
> then no `inplace_vector<T, N>` member functions are usable in
> constant expressions.

Not tested for now.

#### 6.5 Bad alloc requirement

> Any member function of `inplace_vector<T, N>` that would cause the size to
> exceed N throws an exception of type bad_alloc.

These are tested with individual functions.

#### 6.6 Triviality

Let IV denote a specialization of `inplace_vector<T, N>`.
> If N is zero, then IV is trivially copyable and empty,
> and std​::​is_trivially_default_constructible_v<IV> is true.
> (Sub-clauses omitted)

See [triviality.test.cpp](triviality.test.cpp)

### Constructors (23.3.14.2)

See [constructors.test.cpp](constructors.test.cpp)

### Size and capacity (23.3.14.3)

See [size_n_data.test.cpp](size_n_data.test.cpp)

### Data (23.3.14.4)

See [size_n_data.test.cpp](size_n_data.test.cpp)

### Modifiers (23.3.14.5)

See [modifiers.test.cpp](modifiers.test.cpp)

### Erasure (23.3.14.6)

See [erasure.test.cpp](erasure.test.cpp)

## Other tests

- [ref_impl.test.cpp](ref_impl.test.cpp):
Is the test suite imported from reference implementation in
[P0843R14](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p0843r14.html).
Originally included [here on godbolt](https://godbolt.org/z/5P78aG5xE).
- [inplace_vector.test.cpp](inplace_vector.test.cpp):
A minimal test suite by @Hels15 for their implementation.

## Known Issues/ Missed Tests

- Constexpr related functionalities.
- Emplacement minimal copy/ construction.
- Exception safety on mutation.

## Special Thanks

Special thanks to Jan Babst (@jbab) for his contribution at setting up the
Google Test infrastructure.
Loading
Loading