Skip to content

Commit

Permalink
Using no adl macro in all remaining places
Browse files Browse the repository at this point in the history
  • Loading branch information
gracicot committed Nov 11, 2024
1 parent 782e289 commit d6fba2e
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 110 deletions.
40 changes: 20 additions & 20 deletions include/kangaru/detail/cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace kangaru {
struct with_cache {
using source_type = Source;
using cache_type = Cache;

private:
using unwrapped_cache_type = maybe_wrapped_t<cache_type>;

Expand All @@ -54,76 +54,76 @@ namespace kangaru {
source_type source;

constexpr auto insert(auto&& value) requires requires(unwrapped_cache_type c) { c.insert(KANGARU5_FWD(value)); } {
return kangaru::maybe_unwrap(cache).insert(KANGARU5_FWD(value));
return KANGARU5_NO_ADL(maybe_unwrap)(cache).insert(KANGARU5_FWD(value));
}

template<typename It>
constexpr auto insert(It begin, It end) requires requires(unwrapped_cache_type c) { c.insert(begin, end); } {
return kangaru::maybe_unwrap(cache).insert(begin, end);
return KANGARU5_NO_ADL(maybe_unwrap)(cache).insert(begin, end);
}

[[nodiscard]]
constexpr auto find(auto const& key) requires requires(unwrapped_cache_type c) { c.find(key); } {
return kangaru::maybe_unwrap(cache).find(key);
return KANGARU5_NO_ADL(maybe_unwrap)(cache).find(key);
}

[[nodiscard]]
constexpr auto find(auto const& key) const requires requires(unwrapped_cache_type const c) { c.find(key); } {
return kangaru::maybe_unwrap(cache).find(key);
return KANGARU5_NO_ADL(maybe_unwrap)(cache).find(key);
}

[[nodiscard]]
constexpr auto contains(auto const& key) const requires requires(unwrapped_cache_type c) { c.contains(key); } {
return kangaru::maybe_unwrap(cache).contains(key);
return KANGARU5_NO_ADL(maybe_unwrap)(cache).contains(key);
}

[[nodiscard]]
constexpr auto begin() -> typename unwrapped_cache_type::iterator {
return kangaru::maybe_unwrap(cache).begin();
return KANGARU5_NO_ADL(maybe_unwrap)(cache).begin();
}

[[nodiscard]]
constexpr auto end() -> typename unwrapped_cache_type::iterator {
return kangaru::maybe_unwrap(cache).end();
return KANGARU5_NO_ADL(maybe_unwrap)(cache).end();
}

[[nodiscard]]
constexpr auto begin() const {
return kangaru::maybe_unwrap(cache).begin();
return KANGARU5_NO_ADL(maybe_unwrap)(cache).begin();
}

[[nodiscard]]
constexpr auto end() const {
return kangaru::maybe_unwrap(cache).end();
return KANGARU5_NO_ADL(maybe_unwrap)(cache).end();
}

[[nodiscard]]
constexpr auto cbegin() const -> typename unwrapped_cache_type::const_iterator {
return kangaru::maybe_unwrap(cache).cbegin();
return KANGARU5_NO_ADL(maybe_unwrap)(cache).cbegin();
}

[[nodiscard]]
constexpr auto cend() const -> typename unwrapped_cache_type::const_iterator {
return kangaru::maybe_unwrap(cache).cend();
return KANGARU5_NO_ADL(maybe_unwrap)(cache).cend();
}

[[nodiscard]]
constexpr auto empty() const -> bool {
return kangaru::maybe_unwrap(cache).empty();
return KANGARU5_NO_ADL(maybe_unwrap)(cache).empty();
}

constexpr auto clear() -> void {
return kangaru::maybe_unwrap(cache).clear();
return KANGARU5_NO_ADL(maybe_unwrap)(cache).clear();
}

[[nodiscard]]
constexpr auto size() const {
return kangaru::maybe_unwrap(cache).size();
return KANGARU5_NO_ADL(maybe_unwrap)(cache).size();
}

[[nodiscard]]
constexpr auto erase(auto const& key) requires requires(unwrapped_cache_type c) { c.erase(key); } {
return kangaru::maybe_unwrap(cache).erase(key);
return KANGARU5_NO_ADL(maybe_unwrap)(cache).erase(key);
}

constexpr auto swap(with_cache& other) noexcept -> void {
Expand All @@ -146,11 +146,11 @@ namespace kangaru {
requires source_of<detail::utility::forward_like_t<Self, source_type>, T>
friend constexpr auto provide(Self&& source) -> T {
constexpr auto id = detail::ctti::type_id_for<T>();
auto const it = kangaru::maybe_unwrap(source.cache).find(id);
auto const it = KANGARU5_NO_ADL(maybe_unwrap)(source.cache).find(id);

if (it == kangaru::maybe_unwrap(source.cache).end()) {
auto object = provide<T>(KANGARU5_FWD(source).source);
auto const [it, _] = kangaru::maybe_unwrap(source.cache).insert(std::pair{id, std::move(object)});
if (it == KANGARU5_NO_ADL(maybe_unwrap)(source.cache).end()) {
auto object = kangaru::provide<T>(KANGARU5_FWD(source).source);
auto const [it, _] = KANGARU5_NO_ADL(maybe_unwrap)(source.cache).insert(std::pair{id, std::move(object)});
return cast<T>(it->second);
} else {
return cast<T>(it->second);
Expand Down
1 change: 0 additions & 1 deletion include/kangaru/detail/cache_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ namespace kangaru {
template<typename T>
concept forwarded_cache_map = cache_map<std::remove_cvref_t<T>>;


static_assert(cache_map<std::unordered_map<std::size_t, void*>>);

template<cache_map Map>
Expand Down
74 changes: 37 additions & 37 deletions include/kangaru/detail/deducer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,29 +163,29 @@ namespace kangaru {
template<deducible_prvalue<Source> T>
constexpr operator T() {
if constexpr (source_of<Source, T>) {
return provide<T>(static_cast<Source&&>(*source));
return kangaru::provide<T>(static_cast<Source&&>(*source));
} else if constexpr (source_of<Source, T&&>) {
return provide<T&&>(static_cast<Source&&>(*source));
return kangaru::provide<T&&>(static_cast<Source&&>(*source));
} else if constexpr (source_of<Source, T const&&>) {
return provide<T const&&>(static_cast<Source&&>(*source));
return kangaru::provide<T const&&>(static_cast<Source&&>(*source));
} else if constexpr (source_of<Source, T const&>) {
return provide<T const&>(static_cast<Source&&>(*source));
return kangaru::provide<T const&>(static_cast<Source&&>(*source));
} else if constexpr (source_of<Source, T&>) {
return provide<T&>(static_cast<Source&&>(*source));
return kangaru::provide<T&>(static_cast<Source&&>(*source));
} else {
static_assert(not std::same_as<T, T>, "exhaustive");
}
}

template<deducible_lvalue<Source> T>
constexpr operator T&() const {
return provide<T&>(static_cast<Source&&>(*source));
return kangaru::provide<T&>(static_cast<Source&&>(*source));
}

template<deducible_lvalue_const<Source> T>
constexpr operator T const&() const {
if constexpr (source_of<Source, T const&>) {
return provide<T const&>(static_cast<Source&&>(*source));
return kangaru::provide<T const&>(static_cast<Source&&>(*source));
} else if constexpr (source_of<Source, T&>) {
return std::as_const(provide<T&>(static_cast<Source&&>(*source)));
} else if constexpr (source_of<Source, T const&&>) {
Expand All @@ -199,15 +199,15 @@ namespace kangaru {

template<deducible_rvalue<Source> T>
constexpr operator T&&() const {
return provide<T&&>(static_cast<Source&&>(*source));
return kangaru::provide<T&&>(static_cast<Source&&>(*source));
}

template<deducible_rvalue_const<Source> T>
constexpr operator T const&&() const {
if constexpr (source_of<Source, T const&&>) {
return provide<T const&&>(static_cast<Source&&>(*source));
return kangaru::provide<T const&&>(static_cast<Source&&>(*source));
} else if constexpr (source_of<Source, T&&>) {
return provide<T&&>(static_cast<Source&&>(*source));
return kangaru::provide<T&&>(static_cast<Source&&>(*source));
} else {
static_assert(not std::same_as<T, T>, "exhaustive");
}
Expand All @@ -230,27 +230,27 @@ namespace kangaru {

template<deducible_strict_prvalue<Source> T>
constexpr operator T() {
return provide<T>(static_cast<Source&&>(*source));
return kangaru::provide<T>(static_cast<Source&&>(*source));
}

template<deducible_strict_lvalue<Source> T>
constexpr operator T&() const {
return provide<T&>(static_cast<Source&&>(*source));
return kangaru::provide<T&>(static_cast<Source&&>(*source));
}

template<deducible_strict_lvalue_const<Source> T>
constexpr operator T const&() const {
return provide<T const&>(static_cast<Source&&>(*source));
return kangaru::provide<T const&>(static_cast<Source&&>(*source));
}

template<deducible_strict_rvalue<Source> T>
constexpr operator T&&() const {
return provide<T&&>(static_cast<Source&&>(*source));
return kangaru::provide<T&&>(static_cast<Source&&>(*source));
}

template<deducible_strict_rvalue_const<Source> T>
constexpr operator T const&&() const {
return provide<T const&&>(static_cast<Source&&>(*source));
return kangaru::provide<T const&&>(static_cast<Source&&>(*source));
}

private:
Expand Down Expand Up @@ -552,31 +552,31 @@ namespace kangaru {
}

template<typename T, typename F, std::size_t nth, std::size_t max>
inline KANGARU5_CONSTEVAL auto callable_with_nth_parameter_being() -> bool {
return callable_with_nth_parameter_being_expand<T, F>(std::make_index_sequence<nth>{}, std::make_index_sequence<max - nth - 1>{});
}
inline constexpr auto callable_with_nth_parameter_being = bool{
callable_with_nth_parameter_being_expand<T, F>(std::make_index_sequence<nth>{}, std::make_index_sequence<max - nth - 1>{})
};

template<typename F, std::size_t nth, std::size_t max>
inline KANGARU5_CONSTEVAL auto is_nth_parameter_prvalue() -> bool {
return (
not callable_with_nth_parameter_being<ambiguous_prvalue_deducer, F, nth, max>()
and callable_with_nth_parameter_being<ambiguous_overloaded_reference_deducer, F, nth, max>()
);
}
inline constexpr auto is_nth_parameter_prvalue = bool{
not callable_with_nth_parameter_being<ambiguous_prvalue_deducer, F, nth, max>
and callable_with_nth_parameter_being<ambiguous_overloaded_reference_deducer, F, nth, max>
};

template<typename T, typename F, std::size_t nth, std::size_t max>
inline KANGARU5_CONSTEVAL auto reference_kind_for_nth_parameter() -> reference_kind {
if constexpr (is_nth_parameter_prvalue<F, nth, max>()) {
if constexpr (is_nth_parameter_prvalue<F, nth, max>) {
return reference_kind::none;
} else {
// Welcome to insanity

// Only one kind of parameter will accept a lvalue const reference, and it's a lvalue const reference.
// If the function is callable with a lvalue const reference, then it means there's an overload that accepts it.
constexpr auto callable_with_lvalue_const_ref = callable_with_nth_parameter_being<
filtered_value_category_deducer<T, reference_kind::lvalue_const_reference>,
F,
nth,
max
>();
>;

// Now we have something harder to match. Sending a rvalue constant reference would indeed match a rvalue
// constant reference parameter, but would also match a lvalue constant reference. This means that if we
Expand All @@ -596,25 +596,25 @@ namespace kangaru {
F,
nth,
max
>()
>
: (
callable_with_nth_parameter_being<
filtered_value_category_deducer<T, reference_kind::rvalue_const_reference>,
F,
nth,
max
>() or (
> or (
callable_with_nth_parameter_being<
filtered_value_category_deducer<T, reference_kind::rvalue_reference>,
F,
nth,
max
>() and not callable_with_nth_parameter_being<
> and not callable_with_nth_parameter_being<
filtered_value_category_deducer<T, reference_kind::rvalue_reference_and_rvalue_const_reference>,
F,
nth,
max
>()
>
)
);

Expand All @@ -628,13 +628,13 @@ namespace kangaru {
F,
nth,
max
>()
>
: callable_with_nth_parameter_being<
filtered_value_category_deducer<T, reference_kind::lvalue_reference>,
F,
nth,
max
>();
>;

// Here we finally check for value references. They can match rvalue references, rvalue cosnt references, and
// lvalue const references. We need to check for those two if we matched them before in order to do the check
Expand All @@ -645,20 +645,20 @@ namespace kangaru {
F,
nth,
max
>()
>
: callable_with_lvalue_const_ref
? not callable_with_nth_parameter_being<
filtered_value_category_deducer<T, reference_kind::lvalue_const_reference_and_rvalue_reference>,
F,
nth,
max
>()
>
: callable_with_nth_parameter_being<
filtered_value_category_deducer<T, reference_kind::rvalue_reference>,
F,
nth,
max
>();
>;

// We build the bitmask enum to express what overloads of different reference kind exists
return (
Expand All @@ -678,8 +678,8 @@ namespace kangaru {

template<typename F, typename Deducer, std::size_t nth, std::size_t arity>
using prvalue_filtered_deducer_for = detail::type_traits::conditional_t<
not is_nth_parameter_prvalue<F, nth, arity>()
and callable_with_nth_parameter_being<exclude_prvalue_deducer<Deducer>, F, nth, arity>(),
not is_nth_parameter_prvalue<F, nth, arity>
and callable_with_nth_parameter_being<exclude_prvalue_deducer<Deducer>, F, nth, arity>,
exclude_prvalue_deducer<Deducer>,
exclude_references_deducer<Deducer>
>;
Expand Down
6 changes: 3 additions & 3 deletions include/kangaru/detail/heap_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ namespace kangaru {

template<std::copy_constructible F>
constexpr auto emplace_from(F function) -> std::invoke_result_t<F>* {
return kangaru::maybe_unwrap(storage).emplace_from(function);
return KANGARU5_NO_ADL(maybe_unwrap)(storage).emplace_from(function);
}

private:
template<pointer T> requires source_of<source_type, std::remove_pointer_t<T>>
friend constexpr auto provide(forwarded<with_heap_storage> auto&& source) -> T {
return kangaru::maybe_unwrap(source.storage).emplace_from(
return KANGARU5_NO_ADL(maybe_unwrap)(source.storage).emplace_from(
[&source] {
return provide<std::remove_pointer_t<T>>(KANGARU5_FWD(source).source);
return kangaru::provide<std::remove_pointer_t<T>>(KANGARU5_FWD(source).source);
}
);
}
Expand Down
4 changes: 2 additions & 2 deletions include/kangaru/detail/polymorphic_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace kangaru {
template<source Source>
static constexpr auto provide_function_for() -> std::invocable<void*> auto {
return [](void* s) KANGARU5_CONSTEXPR_VOIDSTAR -> T {
return provide<T>(*static_cast<Source*>(s));
return kangaru::provide<T>(*static_cast<Source*>(s));
};
}

Expand Down Expand Up @@ -94,7 +94,7 @@ namespace kangaru {
std::construct_at(
static_cast<function_container<T>*>(static_cast<void*>(function_container_type_erased)),
[](void* source) -> T {
return provide<T>(*static_cast<S*>(source));
return kangaru::provide<T>(*static_cast<S*>(source));
}
);
}
Expand Down
Loading

0 comments on commit d6fba2e

Please sign in to comment.