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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ endif()

add_versioned_package("gh:boostorg/mp11#boost-1.83.0")
add_versioned_package("gh:intel/cpp-baremetal-concurrency#7c5b26c")
add_versioned_package("gh:intel/cpp-std-extensions#5530b5d")
add_versioned_package("gh:intel/cpp-std-extensions#57c87c2")
add_versioned_package("gh:intel/cpp-baremetal-senders-and-receivers#73d95bc")
add_versioned_package("gh:intel/safe-arithmetic#9ea549a")

Expand Down
28 changes: 24 additions & 4 deletions include/groov/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <stdx/bit.hpp>
#include <stdx/ct_string.hpp>
#include <stdx/static_assert.hpp>
#include <stdx/tuple.hpp>
#include <stdx/type_traits.hpp>

#include <boost/mp11/algorithm.hpp>
Expand Down Expand Up @@ -190,13 +192,31 @@ template <typename L> struct any_resolves_q {
template <pathlike P> using fn = boost::mp11::mp_any_of_q<L, resolves_q<P>>;
};

// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define GROOV_STATIC_ASSERT(cond, fmt, ...) \
STATIC_ASSERT( \
cond, \
" (/o.o)/ _|_|_ . o O (HEY, LOOK HERE!!!) ~~ GROOV ERROR: " fmt \
__VA_OPT__(, ) __VA_ARGS__)

template <typename... Paths>
constexpr static auto path_names(boost::mp11::mp_list<Paths...>) {
using namespace stdx::literals;
return stdx::tuple{Paths::to_string()...}.join(
""_cts, [](auto lhs, auto rhs) { return lhs + ", "_cts + rhs; });
}

template <typename G, typename L> constexpr auto check_valid_config() -> void {
static_assert(boost::mp11::mp_is_set<L>::value,
"Duplicate path passed to group");
static_assert(
boost::mp11::mp_all_of_q<L,
any_resolves_q<typename G::children_t>>::value,
"Unresolvable path passed to group");

using bad_paths =
boost::mp11::mp_remove_if_q<L, any_resolves_q<typename G::children_t>>;

GROOV_STATIC_ASSERT(boost::mp11::mp_empty<bad_paths>::value,
"Unresolvable path(s) [{}] passed to group [{}]",
path_names(bad_paths{}), CX_VALUE(G::name));

stdx::template_for_each<L>([]<typename P>() {
using rest = boost::mp11::mp_remove<L, P>;
static_assert(boost::mp11::mp_none_of_q<rest, resolves_q<P>>::value,
Expand Down
7 changes: 7 additions & 0 deletions include/groov/path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <stdx/compiler.hpp>
#include <stdx/ct_string.hpp>
#include <stdx/tuple.hpp>
#include <stdx/type_traits.hpp>

#include <boost/mp11/algorithm.hpp>
Expand Down Expand Up @@ -50,6 +51,12 @@ template <stdx::ct_string... Parts> struct path {

constexpr static auto empty = std::bool_constant<sizeof...(Parts) == 0>{};

constexpr static auto to_string() {
using namespace stdx::literals;
return stdx::tuple{Parts...}.join(
""_cts, [](auto lhs, auto rhs) { return lhs + "."_cts + rhs; });
}

private:
friend constexpr auto operator==(path, path) -> bool = default;

Expand Down
2 changes: 1 addition & 1 deletion test/fail/group_unresolvable_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <cstdint>

// EXPECT: Unresolvable path passed to group
// EXPECT: Unresolvable path\(s\) \[reg0.field1\] passed to group \[group\]

namespace {
struct bus {
Expand Down
9 changes: 9 additions & 0 deletions test/path.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <groov/path.hpp>

#include <stdx/ct_string.hpp>

#include <catch2/catch_test_macros.hpp>

#include <type_traits>
Expand Down Expand Up @@ -95,3 +97,10 @@ TEST_CASE("path is pathlike", "[path]") {
static_assert(groov::pathlike<decltype("reg"_r / "field"_f)>);
static_assert(not groov::valued_pathlike<decltype("reg"_r / "field"_f)>);
}

TEST_CASE("convert to string", "[path]") {
using namespace stdx::literals;
using namespace groov::literals;
static_assert(("reg"_r / "field"_f).to_string() == "reg.field"_cts);
static_assert(groov::path<>::to_string() == ""_cts);
}