-
Notifications
You must be signed in to change notification settings - Fork 8
WIP: error: use of parameter from containing function #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) |
| 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" | ||
| } | ||
| ] | ||
| } |
| 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) |
| 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 $* |
| 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 | ||
| ) |
This file was deleted.
| 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} | ||
| ) |
| 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" | ||
| #include <array> | ||
| #include <cstddef> | ||
|
|
||
|
|
@@ -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; | ||
|
|
@@ -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; | ||
| } | ||
|
|
||
|
|
@@ -111,5 +115,7 @@ class fixed_ring | |
| {} | ||
|
|
||
| Container ctr_; | ||
| ring_view<T> rv_; | ||
| ring_span<T> rv_; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Pull requests for these simple typos/thinkos are welcome. 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| add_executable( | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| 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); | ||
| } |
| 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); | ||
| } |
This file was deleted.
| 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" | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "dependencies": [ | ||
| "catch2" | ||
| ] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that
ring_viewwas supposed to bering_spanhere?