From c2420d150eda964cf57da884201be419486caea2 Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Sat, 5 Sep 2026 14:44:58 +0200 Subject: [PATCH 1/5] C++20 updates --- CMakeLists.txt | 2 +- include/dict.hpp | 69 ++++++++++++++++-------------------------------- meson.build | 4 +-- 3 files changed, 26 insertions(+), 49 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74ae6d3..572a454 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ option(BUILD_TEST "Build test" OFF) ############################## # Set additional compiler option ############################## -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) ############################## diff --git a/include/dict.hpp b/include/dict.hpp index aa95e6b..faf4125 100644 --- a/include/dict.hpp +++ b/include/dict.hpp @@ -1,9 +1,7 @@ #ifndef DICT_H #define DICT_H -#include -#include -#include +#include #include #include #include @@ -11,21 +9,14 @@ #include #include #include -#include #include #include #include namespace cppdict { -namespace -{ - template - constexpr bool is_any_of() - { - return std::disjunction_v...>; - } -} // namespace +template +concept any_of = (std::same_as || ...); namespace // Visitor details { @@ -35,31 +26,19 @@ namespace // Visitor details struct all_nodes_t { }; - template - struct is_visit_policy : std::false_type - { - }; - template<> - struct is_visit_policy : std::true_type - { - }; - template<> - struct is_visit_policy : std::true_type - { - }; + template + concept visit_policy = std::same_as or std::same_as; + template inline constexpr bool is_values_only_v = std::is_same_v; - template + template struct Visitor : Ts... { - Visitor(const Ts&... args) - : Ts(args)... - { - } - using Ts::operator()...; }; + template + Visitor(Ts...) -> Visitor; template auto make_visitor(Ts... lambdas) @@ -105,13 +84,8 @@ struct Dict using data_t = std::variant; template - struct is_value - : std::conditional and !std::is_same_v, - std::true_type, std::false_type>::type - { - }; - template - static constexpr bool is_value_v = is_value::value; + static constexpr bool is_value_v + = !std::is_same_v and !std::is_same_v; data_t data = empty_leaf_t{}; @@ -191,7 +165,8 @@ struct Dict bool isValue() const noexcept { return !isNode() and !isEmpty(); } - template()>> + template + requires any_of Dict& operator=(const T& value) { data = value; @@ -228,13 +203,15 @@ struct Dict throw std::runtime_error("cppdict: not a map or not default"); } - template()>> + template + requires any_of operator T&() const { return to(); } - template()>> + template + requires any_of operator T&() { return to(); @@ -287,8 +264,8 @@ struct Dict } - template::value, int> = 0> + template + requires visit_policy void visit(visit_policy_t, Ts... lambdas) const { visit_impl(*this, std::forward(lambdas)...); @@ -377,16 +354,16 @@ std::optional> get(std::vector const& keys, size_t i } -template class Dict, typename... Types, - typename Check = std::enable_if_t()>> +template class Dict, typename... Types> + requires any_of void add(std::vector const& keys, T&& value, Dict& dict) { auto&& node = get(keys, 0ul, dict); node = std::forward(value); } -template class Dict, typename... Types, - typename Check = std::enable_if_t()>> +template class Dict, typename... Types> + requires any_of void add(std::string const& path, T&& value, Dict& dict) { add(detail::split_string(path), std::forward(value), dict); diff --git a/meson.build b/meson.build index fe5c948..c9a507b 100644 --- a/meson.build +++ b/meson.build @@ -1,8 +1,8 @@ project( 'cppdict', 'cpp', - version : '0.0.1', - default_options : ['warning_level=3', 'cpp_std=c++17'], + version : '1.0.2', + default_options : ['warning_level=3', 'cpp_std=c++20'], license : 'GPL3' ) From 1a41db18574b9e014ba59b9f348c3690f6250fee Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Sat, 5 Sep 2026 17:45:30 +0200 Subject: [PATCH 2/5] try ubuntu latest without jeandet container --- .github/workflows/ccpp.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 6f2644e..2c60b24 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -10,7 +10,7 @@ jobs: gcc: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Configure with CMake run: cmake -DBUILD_TEST:bool=ON -S . -B build_cmake - name: Build (CMake) @@ -21,7 +21,7 @@ jobs: clang: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Configure with CMake run: cmake -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DBUILD_TEST:bool=ON -S . -B build_cmake - name: Build (CMake) @@ -31,9 +31,8 @@ jobs: coverage: runs-on: ubuntu-latest - container: jeandet/simple_cxx_fedora steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: update Meson run: python3 -m pip install meson -U - name: Configure with Meson From 5eb48a917a79b9bcdb47fc620f036a74d2e77c9b Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Sat, 5 Sep 2026 17:49:48 +0200 Subject: [PATCH 3/5] ++ --- .github/workflows/ccpp.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 2c60b24..9e8303b 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -33,6 +33,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: configure ubuntu + run: sudo apt-get update && sudo apt-get install -y gcovr lcov - name: update Meson run: python3 -m pip install meson -U - name: Configure with Meson From 4c8c3c7fbcb5ce88b94d8e6880cb449de20654af Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Sat, 5 Sep 2026 18:01:29 +0200 Subject: [PATCH 4/5] ++ --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 9e8303b..9cc0a46 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -38,7 +38,7 @@ jobs: - name: update Meson run: python3 -m pip install meson -U - name: Configure with Meson - run: meson -Db_coverage=true . build + run: CXX=clang++ meson -Db_coverage=true . build - name: Build (meson) run: ninja -C build - name: Run tests (meson) From 88fe880f2afcf67e007aad9e85555366c514d13c Mon Sep 17 00:00:00 2001 From: PhilipDeegan Date: Thu, 22 Oct 2026 11:21:23 +0200 Subject: [PATCH 5/5] review / retry coverage without lcov --- .github/workflows/ccpp.yml | 11 +++++------ include/dict.hpp | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 9cc0a46..9b207c9 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -34,26 +34,25 @@ jobs: steps: - uses: actions/checkout@v4 - name: configure ubuntu - run: sudo apt-get update && sudo apt-get install -y gcovr lcov + run: sudo apt-get update && sudo apt-get install -y lcov - name: update Meson run: python3 -m pip install meson -U - name: Configure with Meson - run: CXX=clang++ meson -Db_coverage=true . build + run: CXX=g++ meson setup -Db_coverage=true . build - name: Build (meson) run: ninja -C build - name: Run tests (meson) run: ninja test -C build - name: Generate Coverage repport run: | - lcov --capture --directory . --output-file coverage.info - lcov --remove coverage.info '/usr/*' --output-file coverage.info - lcov --remove coverage.info '*/catch.hpp' --output-file coverage.info + lcov --capture --directory . --output-file coverage.info --ignore-errors mismatch,unused + lcov --remove coverage.info '/usr/*' '*/subprojects/*' '*/test/*' --output-file coverage.info --ignore-errors unused lcov --list coverage.info - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} - file: ./coverage.info + files: ./coverage.info flags: unittests name: codecov-cdfpp yml: ./codecov.yml diff --git a/include/dict.hpp b/include/dict.hpp index faf4125..5004987 100644 --- a/include/dict.hpp +++ b/include/dict.hpp @@ -15,8 +15,11 @@ namespace cppdict { -template -concept any_of = (std::same_as || ...); +namespace detail +{ + template + concept any_of = (std::same_as || ...); +} // namespace detail namespace // Visitor details { @@ -37,13 +40,11 @@ namespace // Visitor details { using Ts::operator()...; }; - template - Visitor(Ts...) -> Visitor; template auto make_visitor(Ts... lambdas) { - return Visitor(lambdas...); + return Visitor{lambdas...}; } template @@ -166,7 +167,7 @@ struct Dict bool isValue() const noexcept { return !isNode() and !isEmpty(); } template - requires any_of + requires detail::any_of Dict& operator=(const T& value) { data = value; @@ -204,14 +205,14 @@ struct Dict } template - requires any_of + requires detail::any_of operator T&() const { return to(); } template - requires any_of + requires detail::any_of operator T&() { return to(); @@ -355,7 +356,7 @@ std::optional> get(std::vector const& keys, size_t i template class Dict, typename... Types> - requires any_of + requires detail::any_of void add(std::vector const& keys, T&& value, Dict& dict) { auto&& node = get(keys, 0ul, dict); @@ -363,7 +364,7 @@ void add(std::vector const& keys, T&& value, Dict& dict) } template class Dict, typename... Types> - requires any_of + requires detail::any_of void add(std::string const& path, T&& value, Dict& dict) { add(detail::split_string(path), std::forward(value), dict);