Skip to content
Open
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
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.5)

project(ring-view)

enable_testing()

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) # Ensures no compiler-specific extensions are used
set(CMAKE_CXX_FLAGS_DEBUG_INIT "-Wall -Wextra -pedantic -Werror")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "-Wall -Wextra -pedantic -Werror")

set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

# Catch2
find_package(Catch2 CONFIG REQUIRED)

add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(examples)
41 changes: 41 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 3,
"configurePresets": [
{
"name": "debug",
"displayName": "Linux Debug",
"description": "debug build for Linux",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": {
"CMAKE_CXX_STANDARD": "23",
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
},
{
"name": "release",
"displayName": "Linux Release",
"description": "release build for Linux",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": {
"CMAKE_CXX_STANDARD": "23",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
}
],
"buildPresets": [
{
"name": "debug",
"configurePreset": "debug"
},
{
"name": "release",
"configurePreset": "release"
}
]
}
4 changes: 4 additions & 0 deletions cmake-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

cmake --preset=release -DCMAKE_CXX_COMPILER=g++-14
cmake --build --preset=release -j$(nproc)
3 changes: 3 additions & 0 deletions cmake-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

ctest --test-dir out/build/release --output-on-failure $*
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_executable(
ring_view_test_executable
ring_view.test.cc
)

target_link_libraries(
ring_view_test_executable
PRIVATE
ring_view
)
8 changes: 6 additions & 2 deletions ring_view.test.cc → examples/ring_view.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ int main()
std::queue<T, RVT> q(rv);
q.push(nullptr);
q.push(nullptr);
q.front();
q.back();
{
const auto _ = std::move(q.front());
}
{
const auto _ = std::move(q.back());
}
q.pop();
}
23 changes: 0 additions & 23 deletions fixed_ring.test.cc

This file was deleted.

13 changes: 13 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_library(
ring_view
INTERFACE
ring_span.h
heap_span.h
fixed_ring.h
)

target_include_directories(
ring_view
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
)
16 changes: 11 additions & 5 deletions fixed_ring.h → src/fixed_ring.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#ifndef FIXED_RING_H
#define FIXED_RING_H

#include "ring_view.h"
#include "ring_span.h"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that ring_view was supposed to be ring_span here?

#include <array>
#include <cstddef>

Expand All @@ -11,6 +12,9 @@ template<class T, std::size_t Capacity, class Container = std::array<T, Capacity
class fixed_ring
{
public:
template<typename U>
using ring_span = std::experimental::ring_span<U>;

using container_type = Container;
using value_type = typename Container::value_type;
using size_type = typename Container::size_type;
Expand Down Expand Up @@ -57,15 +61,15 @@ class fixed_ring
{
ctr_ = rhs.ctr_;
auto first_idx = (&*rhs.rv_.begin() - rhs.ctr_.begin());
rv_ = ring_view<T>(ctr_.begin(), ctr_.end(), ctr_.begin() + first_idx, rhs.rv_.size());
rv_ = ring_span<T>(ctr_.begin(), ctr_.end(), ctr_.begin() + first_idx, rhs.rv_.size());
return *this;
}

fixed_ring& operator=(fixed_ring&& rhs) noexcept(std::is_nothrow_copy_assignable<Container>::value)
{
auto first_idx = (&*rhs.rv_.begin() - rhs.ctr_.begin());
ctr_ = std::move(rhs.ctr_);
rv_ = ring_view<T>(ctr_.begin(), ctr_.end(), ctr_.begin() + first_idx, rhs.rv_.size());
rv_ = ring_span<T>(ctr_.begin(), ctr_.end(), ctr_.begin() + first_idx, rhs.rv_.size());
return *this;
}

Expand Down Expand Up @@ -111,5 +115,7 @@ class fixed_ring
{}

Container ctr_;
ring_view<T> rv_;
ring_span<T> rv_;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you've discovered that I didn't write any tests for "fixed_ring.h", huh? :)

The syntax error on line 112 is that noexcept(Container(std::forward<Args>(args)...)) should be noexcept(noexcept(Container(std::forward<Args>(args)...))) — yes, "noexcept noexcept" is correct, and what's there now is a dumb typo.

Pull requests for these simple typos/thinkos are welcome.
Pull requests for better testing are admirable, if perhaps not a good use of your time.
Pull requests for CMake support are highly unlikely to be accepted.

Have you looked at https://github.com/nonstd-lite/ring-span-lite ? I'd recommend his over mine, unless you've found something less-good about his.

};

#endif
5 changes: 4 additions & 1 deletion heap_span.h → src/heap_span.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef HEAP_SPAN_H
#define HEAP_SPAN_H

#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -187,3 +188,5 @@ class heap_span
};

} } // namespace std::experimental

#endif
5 changes: 4 additions & 1 deletion ring_span.h → src/ring_span.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef RING_SPAN_H
#define RING_SPAN_H

// Reference implementation of P0059R1 + errata.

Expand Down Expand Up @@ -271,3 +272,5 @@ class ring_iterator
} // namespace detail

} } // namespace std::experimental

#endif
68 changes: 68 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
add_executable(
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all of these will compile/run and work (yet). I have not yet fixed up each of the test files.

compiles_at_all
compiles_at_all.cc
)

target_link_libraries(
compiles_at_all
PRIVATE
Catch2::Catch2
Catch2::Catch2WithMain
ring_view
)

add_executable(
fixed_ring_test
fixed_ring.test.cc
)

target_link_libraries(
fixed_ring_test
PRIVATE
Catch2::Catch2
Catch2::Catch2WithMain
ring_view
)

add_executable(
is_default_constructible
is_default_constructible.cc
)

target_link_libraries(
is_default_constructible
PRIVATE
Catch2::Catch2
Catch2::Catch2WithMain
ring_view
)

add_executable(
moveonly_type
moveonly_type.cc
)

target_link_libraries(
moveonly_type
PRIVATE
Catch2::Catch2
Catch2::Catch2WithMain
ring_view
)

add_executable(
p0059r1
p0059r1.cc
)

target_link_libraries(
p0059r1
PRIVATE
Catch2::Catch2
Catch2::Catch2WithMain
ring_view
)


include(Catch)
catch_discover_tests(compiles_at_all)
7 changes: 4 additions & 3 deletions test/compiles_at_all.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <catch2/catch_test_macros.hpp>

#include "ring_span.h"

int main()
{
}
TEST_CASE("compiles-at-all") {
REQUIRE(1 == 1);
}
45 changes: 45 additions & 0 deletions test/fixed_ring.test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <catch2/catch_test_macros.hpp>

#include "fixed_ring.h"
#include <cstdio>

TEST_CASE("fixed-ring_test") {

fixed_ring<int, 4> fr;
REQUIRE(fr.size() == 0);

fr.push(1);
REQUIRE(fr.size() == 1);
REQUIRE(fr.front() == 1);
REQUIRE(fr.back() == 1);

fr.push(2);
REQUIRE(fr.size() == 2);
REQUIRE(fr.front() == 1);
REQUIRE(fr.back() == 2);

fr.push(3);
REQUIRE(fr.size() == 3);
REQUIRE(fr.front() == 1);
REQUIRE(fr.back() == 3);

fr.push(4);
REQUIRE(fr.size() == 4);
REQUIRE(fr.front() == 1);
REQUIRE(fr.back() == 4);

fr.push(5);
REQUIRE(fr.size() == 4);
REQUIRE(fr.front() == 2);
REQUIRE(fr.back() == 5);

fr.push(6);
REQUIRE(fr.size() == 4);
REQUIRE(fr.front() == 3);
REQUIRE(fr.back() == 6);

fr.pop();
REQUIRE(fr.size() == 3);
REQUIRE(fr.front() == 4);
REQUIRE(fr.back() == 6);
}
5 changes: 0 additions & 5 deletions test/run-all-tests.sh

This file was deleted.

14 changes: 14 additions & 0 deletions vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"default-registry": {
"kind": "git",
"baseline": "b1b19307e2d2ec1eefbdb7ea069de7d4bcd31f01",
"repository": "https://github.com/microsoft/vcpkg"
},
"registries": [
{
"kind": "artifact",
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
"name": "microsoft"
}
]
}
5 changes: 5 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": [
"catch2"
]
}