Skip to content

Commit

Permalink
check extended services have been exported
Browse files Browse the repository at this point in the history
  • Loading branch information
lukevalenty authored and elbeno committed Jul 21, 2023
1 parent 0691e86 commit e9616d2
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 13 deletions.
1 change: 1 addition & 0 deletions cmake/quality.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
find_program(CLANG_TIDY_PROGRAM "clang-tidy")
if(CLANG_TIDY_PROGRAM)
message(STATUS "clang-tidy found: ${CLANG_TIDY_PROGRAM}")
add_custom_target(clang-tidy)
include(${CMAKE_CURRENT_LIST_DIR}/clang-tidy.cmake)
else()
Expand Down
5 changes: 5 additions & 0 deletions include/cib/detail/components.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ struct components : public detail::config_item {
[[nodiscard]] constexpr auto extends_tuple(Args const &...args) const {
return cib::tuple_cat(Components::config.extends_tuple(args...)...);
}

template <typename... Args>
[[nodiscard]] constexpr auto exports_tuple(Args const &...args) const {
return cib::tuple_cat(Components::config.exports_tuple(args...)...);
}
};
} // namespace cib::detail
9 changes: 9 additions & 0 deletions include/cib/detail/conditional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,14 @@ struct conditional : config_item {
return cib::tuple<>{};
}
}

template <typename... Args>
[[nodiscard]] constexpr auto exports_tuple(Args const &...) const {
if constexpr (Pred{}(Args{}...)) {
return body.exports_tuple(Args{}...);
} else {
return cib::tuple<>{};
}
}
};
} // namespace cib::detail
10 changes: 10 additions & 0 deletions include/cib/detail/config_details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,15 @@ struct config : public detail::config_item {
});
});
}

template <typename... Args>
[[nodiscard]] constexpr auto exports_tuple(Args const &...args) const {
return ConfigArgs::value.apply([&](auto const &...config_args) {
return configs_tuple.apply([&](auto const &...configs_pack) {
return cib::tuple_cat(
configs_pack.exports_tuple(args..., config_args...)...);
});
});
}
};
} // namespace cib::detail
7 changes: 6 additions & 1 deletion include/cib/detail/config_item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ namespace cib::detail {
struct config_item {
template <typename... Args>
[[nodiscard]] constexpr auto extends_tuple(Args const &...) const {
return cib::tuple<>{};
return cib::make_tuple();
}

template <typename... InitArgs>
[[nodiscard]] constexpr auto exports_tuple(InitArgs const &...) const {
return cib::make_tuple();
}
};
} // namespace cib::detail
5 changes: 5 additions & 0 deletions include/cib/detail/exports.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ template <typename... Services> struct exports : public detail::config_item {
[[nodiscard]] constexpr auto extends_tuple(InitArgs const &...) const {
return cib::make_tuple(extend<Services>{}...);
}

template <typename... InitArgs>
[[nodiscard]] constexpr auto exports_tuple(InitArgs const &...) const {
return cib::make_tuple(Services{}...);
}
};
} // namespace cib::detail
8 changes: 7 additions & 1 deletion include/cib/detail/nexus_details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cib/detail/meta.hpp>
#include <cib/set.hpp>
#include <cib/tuple.hpp>
#include <cib/tuple_algorithms.hpp>

#include <type_traits>
#include <utility>
Expand All @@ -22,8 +23,13 @@ template <typename Config>
constexpr static auto initialized_builders = transform<extract_service_tag>(
[](auto extensions) {
using namespace cib::tuple_literals;
constexpr auto initial_builder = extensions[0_idx].builder;

using exports_tuple = decltype(Config::config.exports_tuple());
using service = get_service_from_tuple<decltype(extensions)>;
static_assert(contains_type<exports_tuple, service>);

constexpr auto initial_builder = extensions[0_idx].builder;

auto built_service = extensions.fold_right(
initial_builder, [](auto extension, auto outer_builder) {
return extension.args_tuple.apply(
Expand Down
10 changes: 4 additions & 6 deletions include/cib/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ struct element<Index, T, Ts...> : T {
};

template <typename Op, typename Value> struct fold_helper {
Op &op;
Op op;
Value value;

private:
Expand All @@ -191,7 +191,7 @@ template <typename Op, typename Value>
fold_helper(Op, Value) -> fold_helper<Op, std::remove_cvref_t<Value>>;

template <typename Op, typename Value> struct join_helper {
Op &op;
Op op;
Value value;
};
template <typename Op, typename Value>
Expand All @@ -202,11 +202,9 @@ join_helper(Op, Value) -> join_helper<Op, std::remove_cvref_t<Value>>;
template <typename Op, typename T, typename U>
[[nodiscard]] constexpr auto operator+(join_helper<Op, T> &&lhs,
join_helper<Op, U> &&rhs) {
using R = decltype(lhs.op(std::forward<join_helper<Op, T>>(lhs).value,
std::forward<join_helper<Op, U>>(rhs).value));
using R = decltype(lhs.op(std::move(lhs).value, std::move(rhs).value));
return join_helper<Op, std::remove_cvref_t<R>>{
lhs.op, lhs.op(std::forward<join_helper<Op, T>>(lhs).value,
std::forward<join_helper<Op, U>>(rhs).value)};
lhs.op, lhs.op(std::move(lhs).value, std::move(rhs).value)};
}

template <template <typename> typename...> struct index_function_list;
Expand Down
1 change: 0 additions & 1 deletion include/cib/tuple_algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,4 @@ constexpr auto contains_type =
return (... or std::is_same_v<T, cib::tuple_element_t<Is, Tuple>>);
}
(std::make_index_sequence<cib::tuple_size_v<Tuple>>{});

} // namespace cib
2 changes: 1 addition & 1 deletion include/msg/detail/func_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace msg::detail {

template <typename T>
using remove_cvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
typename std::remove_cv_t<typename std::remove_reference_t<T>>;

template <typename CallableT> struct func_args {
using msg_type = typename func_args<
Expand Down
4 changes: 2 additions & 2 deletions include/sc/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ template <typename CharT, CharT... chars, typename ArgsTupleT>
}

template <typename EnumTypeT, EnumTypeT ValueT,
std::enable_if_t<std::is_enum<EnumTypeT>::value, bool> = true>
std::enable_if_t<std::is_enum_v<EnumTypeT>, bool> = true>
[[nodiscard]] constexpr auto
format_field([[maybe_unused]] std::string_view field,
std::integral_constant<EnumTypeT, ValueT>, char *out) -> char * {
Expand All @@ -111,7 +111,7 @@ format_field([[maybe_unused]] std::string_view field, type_name<T>, char *out)
}

template <typename IntegralTypeT, IntegralTypeT ValueT,
std::enable_if_t<!std::is_enum<IntegralTypeT>::value, bool> = true>
std::enable_if_t<!std::is_enum_v<IntegralTypeT>, bool> = true>
[[nodiscard]] constexpr auto
format_field(std::string_view field,
std::integral_constant<IntegralTypeT, ValueT> const &, char *out)
Expand Down
2 changes: 1 addition & 1 deletion include/sc/to_string_constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ template <std::integral T, T Value, T Base = T{10}, bool Uppercase = false>
}

template <typename EnumTypeT, EnumTypeT ValueT,
std::enable_if_t<std::is_enum<EnumTypeT>::value, bool> = true>
std::enable_if_t<std::is_enum_v<EnumTypeT>, bool> = true>
[[nodiscard]] constexpr auto
to_string_constant(std::integral_constant<EnumTypeT, ValueT> const &) {
return detail::create<detail::EnumToString<EnumTypeT, ValueT>>();
Expand Down

0 comments on commit e9616d2

Please sign in to comment.