Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor concepts fixes #492

Merged
merged 1 commit into from
Dec 17, 2023
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
10 changes: 8 additions & 2 deletions src/rpp/rpp/observables/details/disposable_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,25 @@

namespace details
{
template<typename T>
concept has_expected_disposable_strategy = requires { typename T::expected_disposable_strategy; };

template<typename T>
auto* deduce_disposable_strategy()
{
if constexpr (requires { typename T::expected_disposable_strategy; })
if constexpr (has_expected_disposable_strategy<T>)

Check warning on line 83 in src/rpp/rpp/observables/details/disposable_strategy.hpp

View check run for this annotation

Codecov / codecov/patch

src/rpp/rpp/observables/details/disposable_strategy.hpp#L83

Added line #L83 was not covered by tests
return static_cast<typename T::expected_disposable_strategy*>(nullptr);
else
return static_cast<default_disposable_strategy_selector*>(nullptr);
}

template<typename T, typename Prev>
concept has_updated_disposable_strategy = requires { typename T::template updated_disposable_strategy<Prev>; };

template<typename T, typename Prev>
auto* deduce_updated_disposable_strategy()
{
if constexpr (requires { typename T::template updated_disposable_strategy<Prev>; })
if constexpr(has_updated_disposable_strategy<T, Prev>)

Check warning on line 95 in src/rpp/rpp/observables/details/disposable_strategy.hpp

View check run for this annotation

Codecov / codecov/patch

src/rpp/rpp/observables/details/disposable_strategy.hpp#L95

Added line #L95 was not covered by tests
return static_cast<typename T::template updated_disposable_strategy<Prev>*>(nullptr);
else
return static_cast<default_disposable_strategy_selector*>(nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/rpp/rpp/observables/observable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class observable
requires (!constraint::observer<ObserverStrategy>)
void subscribe(ObserverStrategy&& observer_strategy) const
{
if constexpr (details::observers::has_disposable_strategy_v<ObserverStrategy>)
if constexpr (details::observers::has_disposable_strategy<ObserverStrategy>)
subscribe(rpp::observer<Type, std::decay_t<ObserverStrategy>>{std::forward<ObserverStrategy>(observer_strategy)});
else
subscribe(rpp::observer<Type, details::with_disposable_strategy<std::decay_t<ObserverStrategy>, typename expected_disposable_strategy::disposable_strategy>>{std::forward<ObserverStrategy>(observer_strategy)});
Expand Down
4 changes: 2 additions & 2 deletions src/rpp/rpp/observers/details/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@
}

template<typename T>
static constexpr bool has_disposable_strategy_v = requires { typename T::preferred_disposable_strategy; };
concept has_disposable_strategy = requires { typename T::preferred_disposable_strategy; };

namespace details
{
template<typename T>
auto* deduce_disposable_strategy()
{
if constexpr (has_disposable_strategy_v<T>)
if constexpr (has_disposable_strategy<T>)

Check warning on line 73 in src/rpp/rpp/observers/details/fwd.hpp

View check run for this annotation

Codecov / codecov/patch

src/rpp/rpp/observers/details/fwd.hpp#L73

Added line #L73 was not covered by tests
return static_cast<typename T::preferred_disposable_strategy*>(nullptr);
else
return static_cast<dynamic_local_disposable_strategy<0, atomic_bool>*>(nullptr);
Expand Down
2 changes: 2 additions & 0 deletions src/rpp/rpp/observers/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ namespace rpp::details
{
struct fake_strategy
{
using preferred_disposable_strategy = rpp::details::observers::none_disposable_strategy;

static void on_next(const auto&) noexcept {}

static void on_error(const std::exception_ptr&) noexcept {}
Expand Down
2 changes: 2 additions & 0 deletions src/rpp/rpp/operators/scan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ struct scan_t : public operators::details::operator_observable_strategy<scan_obs
template<rpp::constraint::decayed_type Seed, rpp::constraint::observer TObserver, rpp::constraint::decayed_type Fn>
struct scan_no_seed_observer_strategy
{
using preferred_disposable_strategy = rpp::details::observers::none_disposable_strategy;

RPP_NO_UNIQUE_ADDRESS TObserver observer;
RPP_NO_UNIQUE_ADDRESS Fn fn;
mutable std::optional<Seed> seed{};
Expand Down
Loading