Skip to content
Merged
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
18 changes: 9 additions & 9 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

##############################
Expand Down
68 changes: 23 additions & 45 deletions include/dict.hpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
#ifndef DICT_H
#define DICT_H

#include <algorithm>
#include <array>
#include <functional>
#include <concepts>
#include <iostream>
#include <map>
#include <memory>
#include <optional>
#include <sstream>
#include <string>
#include <type_traits>
#include <typeinfo>
#include <utility>
#include <variant>
#include <vector>

namespace cppdict
{
namespace
namespace detail
{
template<typename T1, typename... T2>
constexpr bool is_any_of()
{
return std::disjunction_v<std::is_same<T1, T2>...>;
}
} // namespace
concept any_of = (std::same_as<T1, T2> || ...);
} // namespace detail

namespace // Visitor details
{
Expand All @@ -35,36 +29,22 @@ namespace // Visitor details
struct all_nodes_t
{
};
template<class _Tp>
struct is_visit_policy : std::false_type
{
};
template<>
struct is_visit_policy<all_nodes_t> : std::true_type
{
};
template<>
struct is_visit_policy<values_only_t> : std::true_type
{
};
template<typename T>
concept visit_policy = std::same_as<T, values_only_t> or std::same_as<T, all_nodes_t>;

template<typename T>
inline constexpr bool is_values_only_v = std::is_same_v<T, values_only_t>;
template<typename... Ts>

template<typename... Ts>
struct Visitor : Ts...
{
Visitor(const Ts&... args)
: Ts(args)...
{
}

using Ts::operator()...;
};

template<typename... Ts>
auto make_visitor(Ts... lambdas)
{
return Visitor<Ts...>(lambdas...);
return Visitor<Ts...>{lambdas...};
}

template<typename visit_policy_t, typename NodeT, typename... Ts>
Expand Down Expand Up @@ -105,13 +85,8 @@ struct Dict
using data_t = std::variant<empty_leaf_t, node_t, Types...>;

template<typename T>
struct is_value
: std::conditional<!std::is_same_v<T, empty_leaf_t> and !std::is_same_v<T, node_t>,
std::true_type, std::false_type>::type
{
};
template<typename T>
static constexpr bool is_value_v = is_value<T>::value;
static constexpr bool is_value_v
= !std::is_same_v<T, empty_leaf_t> and !std::is_same_v<T, node_t>;


data_t data = empty_leaf_t{};
Expand Down Expand Up @@ -191,7 +166,8 @@ struct Dict

bool isValue() const noexcept { return !isNode() and !isEmpty(); }

template<typename T, typename U = std::enable_if_t<is_any_of<T, Types...>()>>
template<typename T>
requires detail::any_of<T, Types...>
Dict& operator=(const T& value)
{
data = value;
Expand Down Expand Up @@ -228,13 +204,15 @@ struct Dict
throw std::runtime_error("cppdict: not a map or not default");
}

template<typename T, typename U = std::enable_if_t<is_any_of<T, Types...>()>>
template<typename T>
requires detail::any_of<T, Types...>
operator T&() const
{
return to<T>();
}

template<typename T, typename U = std::enable_if_t<is_any_of<T, Types...>()>>
template<typename T>
requires detail::any_of<T, Types...>
operator T&()
{
return to<T>();
Expand Down Expand Up @@ -287,8 +265,8 @@ struct Dict
}


template<class visit_policy_t, typename... Ts,
std::enable_if_t<is_visit_policy<visit_policy_t>::value, int> = 0>
template<typename visit_policy_t, typename... Ts>
requires visit_policy<visit_policy_t>
void visit(visit_policy_t, Ts... lambdas) const
{
visit_impl<visit_policy_t>(*this, std::forward<Ts>(lambdas)...);
Expand Down Expand Up @@ -377,16 +355,16 @@ std::optional<Dict<Types...>> get(std::vector<std::string> const& keys, size_t i
}


template<typename T, template<typename... Types> class Dict, typename... Types,
typename Check = std::enable_if_t<is_any_of<T, Types...>()>>
template<typename T, template<typename... Types> class Dict, typename... Types>
requires detail::any_of<T, Types...>
void add(std::vector<std::string> const& keys, T&& value, Dict<Types...>& dict)
{
auto&& node = get(keys, 0ul, dict);
node = std::forward<T>(value);
}

template<typename T, template<typename... Types> class Dict, typename... Types,
typename Check = std::enable_if_t<is_any_of<T, Types...>()>>
template<typename T, template<typename... Types> class Dict, typename... Types>
requires detail::any_of<T, Types...>
void add(std::string const& path, T&& value, Dict<Types...>& dict)
{
add(detail::split_string(path), std::forward<T>(value), dict);
Expand Down
4 changes: 2 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
@@ -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'
)

Expand Down
Loading