LockedPtr::and_then introduced - #458
Conversation
|
The created documentation from the pull request is available at: docu-html |
There was a problem hiding this comment.
Pull request overview
Adds LockedPtr::and_then for optional-based monadic chaining.
Changes:
- Adds optional detection support.
- Implements four value-category overloads.
- Adds tests for success, empty, and null cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
score/concurrency/type_traits.h |
Adds optional type detection. |
score/concurrency/locked_ptr.h |
Implements and_then. |
score/concurrency/locked_ptr_test.cpp |
Tests the new overloads. |
Suppressed comments (6)
score/concurrency/locked_ptr.h:227
Retpreserves cv/reference qualifiers, so this overload rejects callables returningconst optional<T>oroptional<T>&, unlikescore::cpp::optional::and_then. Decay the invocation result so all supported optional return forms produce an optional value.
typename Ret = std::invoke_result_t<Func, const LockedPtr&>,
score/concurrency/locked_ptr.h:248
Retpreserves cv/reference qualifiers, so this overload rejects callables returningconst optional<T>oroptional<T>&, unlikescore::cpp::optional::and_then. Decay the invocation result so all supported optional return forms produce an optional value.
typename Ret = std::invoke_result_t<Func, LockedPtr>,
score/concurrency/locked_ptr.h:269
Retpreserves cv/reference qualifiers, so this overload rejects callables returningconst optional<T>oroptional<T>&, unlikescore::cpp::optional::and_then. Decay the invocation result so all supported optional return forms produce an optional value.
typename Ret = std::invoke_result_t<Func, const LockedPtr&>,
score/concurrency/locked_ptr_test.cpp:53
- This namespace-scope lambda object is a mutable global. Repository style requires fixed namespace-scope values to be
const/constexprandk-prefixed (docs/cpp-style-guide.md:29); use a constant or named helper function and update its call sites.
auto value_if_positive = [](LPtr2IntW& lp) -> score::cpp::optional<int> {
score/concurrency/locked_ptr_test.cpp:61
- This namespace-scope lambda object is a mutable global. Repository style requires fixed namespace-scope values to be
const/constexprandk-prefixed (docs/cpp-style-guide.md:29); use a constant or named helper function and update its call sites.
auto cvalue_if_positive = [](const LPtr2IntW& lp) -> score::cpp::optional<int> {
score/concurrency/locked_ptr_test.cpp:69
- This namespace-scope lambda object is a mutable global. Repository style requires fixed namespace-scope values to be
const/constexprandk-prefixed (docs/cpp-style-guide.md:29); use a constant or named helper function and update its call sites.
auto opt_move_get = [](LPtr2IntW lp) -> score::cpp::optional<IntWrapper*> {
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
5a7302d to
1586ba2
Compare
|
Documentation preview for this pull request is available at: |
e62e468 to
c615da8
Compare
|
@4og All comments resolved. Trigger Copilot recheck? Thanks! |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
score/concurrency/locked_ptr.h:278
- The
const&&overload discards the receiver's rvalue category by constraining and invoking the callable withconst LockedPtr&. A callable that specifically acceptsconst LockedPtr&&is therefore rejected, and an overloaded callable unexpectedly takes its lvalue branch; forwardstd::move(*this)as the other ref-qualified monadic overloads do.
template <typename Func,
typename = std::enable_if_t<std::is_invocable_v<Func, const LockedPtr&>>,
typename Ret = std::invoke_result_t<Func, const LockedPtr&>,
typename = std::enable_if_t<score::cpp::is_optional_v<Ret>>>
[[nodiscard]] auto and_then(Func&& f) const&& -> Ret
score/concurrency/locked_ptr.h:208
- The new method name violates the repository rule that functions and methods use
PascalCase(docs/cpp-style-guide.md:27). Rename the overload set toAndThenand update its tests and example call sites consistently.
[[nodiscard]] auto and_then(Func&& f) & -> Ret
| #ifndef SCORE_LIB_CONCURRENCY_TYPE_TRAITS_H | ||
| #define SCORE_LIB_CONCURRENCY_TYPE_TRAITS_H | ||
|
|
||
| #include <score/optional.hpp> |
|
besides the copilot comments rest looks good me, |
Monadic interfaces help write functional code by supporting
transform,and_thenandor_else. This PR is to supportand_then.This makes the following possible.