diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 6f2644e..9b207c9 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,28 +31,28 @@ jobs: coverage: runs-on: ubuntu-latest - container: jeandet/simple_cxx_fedora steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - name: configure ubuntu + 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: 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/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..5004987 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,17 @@ #include #include #include -#include #include #include #include namespace cppdict { -namespace +namespace detail { template - constexpr bool is_any_of() - { - return std::disjunction_v...>; - } -} // namespace + concept any_of = (std::same_as || ...); +} // namespace detail namespace // Visitor details { @@ -35,36 +29,22 @@ 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 auto make_visitor(Ts... lambdas) { - return Visitor(lambdas...); + return Visitor{lambdas...}; } template @@ -105,13 +85,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 +166,8 @@ struct Dict bool isValue() const noexcept { return !isNode() and !isEmpty(); } - template()>> + template + requires detail::any_of Dict& operator=(const T& value) { data = value; @@ -228,13 +204,15 @@ struct Dict throw std::runtime_error("cppdict: not a map or not default"); } - template()>> + template + requires detail::any_of operator T&() const { return to(); } - template()>> + template + requires detail::any_of operator T&() { return to(); @@ -287,8 +265,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 +355,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 detail::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 detail::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' )