Skip to content

Commit

Permalink
Fixed GCC build
Browse files Browse the repository at this point in the history
  • Loading branch information
gracicot committed Sep 2, 2024
1 parent 3a0db44 commit 98b9b6b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion include/kangaru/detail/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace kangaru {

template<typename T, typename... Args>
concept brace_constructible = requires(Args&&... args) {
::new T{KANGARU5_FWD(args)...};
T{KANGARU5_FWD(args)...};
};

template<typename T, typename... Args>
Expand Down
13 changes: 9 additions & 4 deletions include/kangaru/detail/source_reference_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ namespace kangaru {
std::remove_reference_t<Source>* source;
};

template<typename Source> requires source<std::remove_cvref_t<Source>>
source_forwarding_reference_wrapper(Source&&) -> source_forwarding_reference_wrapper<Source&&>;

template<typename T>
concept reference_wrapper = source<T> and requires(T ref) {
{ ref.unwrap() } -> reference;
};

template<typename T> requires reference_wrapper<std::remove_cvref_t<T>>
inline constexpr auto maybe_unwrap(T&& ref) noexcept -> decltype(auto) {
template<typename T>
concept forwarded_reference_wrapper = reference_wrapper<std::remove_reference_t<T>>;

inline constexpr auto maybe_unwrap(forwarded_reference_wrapper auto&& ref) noexcept -> decltype(auto) {
return KANGARU5_FWD(ref).unwrap();
}

Expand All @@ -67,12 +72,12 @@ namespace kangaru {
template<typename MaybeWrapper>
using maybe_wrapped_t = std::remove_reference_t<decltype(kangaru::maybe_unwrap(std::declval<MaybeWrapper>()))>;

template<typename Source> requires source<std::remove_const_t<Source>>
template<typename Source> requires (source<std::remove_cvref_t<Source>> and not reference_wrapper<std::remove_cvref_t<Source>>)
inline constexpr auto ref(Source& source) -> source_reference_wrapper<Source> {
return source_reference_wrapper<Source>{source};
}

template<typename Source> requires source<std::remove_cvref_t<Source>>
template<typename Source> requires (source<std::remove_cvref_t<Source>> and not reference_wrapper<std::remove_cvref_t<Source>>)
inline constexpr auto fwd_ref(Source&& source) -> source_forwarding_reference_wrapper<Source&&> {
return source_forwarding_reference_wrapper<Source&&>{KANGARU5_FWD(source)};
}
Expand Down
24 changes: 12 additions & 12 deletions tests/src/5-runtime-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,24 @@ TEST_CASE("Runtime source will cache sources results", "[deducer]") {
}

SECTION("Support the service idiom and cache and construction, with recursive construction on top") {
auto source = kangaru::with_recursion{
auto source = kangaru::make_source_with_recursion(
kangaru::make_source_with_exhaustive_construction(
kangaru::with_recursion{
kangaru::with_source_from_tag{
kangaru::with_cache{
kangaru::with_heap_storage{
kangaru::make_source_with_recursion(
kangaru::make_source_with_source_from_tag(
kangaru::make_source_with_cache(
kangaru::make_source_with_heap_storage(
kangaru::make_source_with_exhaustive_construction(
increment_source{.n = 3} // just a source of int
)
}
}
}
}
)
)
)
)
)
};
);

CHECK(kangaru::provide(kangaru::provide_tag_v<service_a&>, source).a == 3);

service_a& ra = kangaru::provide(kangaru::provide_tag_v<service_a&>, source);
service_b& rb = kangaru::provide(kangaru::provide_tag_v<service_b&>, source);
CHECK(std::addressof(ra) == std::addressof(rb.a));
Expand Down

0 comments on commit 98b9b6b

Please sign in to comment.