[libcxx-commits] [PATCH] D113408: [libc++] Implement P0798R8 (Monadic operations for std::optional)
Arthur O'Dwyer via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Nov 14 08:04:07 PST 2021
Quuxplusone added inline comments.
================
Comment at: libcxx/test/std/utilities/optional/optional.monadic/or_else.pass.cpp:1
+//===----------------------------------------------------------------------===//
+//
----------------
philnik wrote:
> ldionne wrote:
> > Please add tests for SFINAE friendliness when the `Constraints:` are not met.
> Could you reference something where that is done? I have no idea what you are asking for.
Something like `libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_value_sfinae.pass.cpp`. Basically:
```
#include "MoveOnly.h"
struct NonMovable {
NonMovable() = default;
NonMovable(NonMovable&&) = delete;
};
// TODO: rewrite to use 'requires' when _LIBCPP_HAS_NO_CONCEPTS goes away
template<class O, class F>
auto has_or_else(int, O&& o, F&& f)
-> decltype(static_cast<O&&>(o).or_else(static_cast<F&&>(f)), true)
{ return true; }
template<class O, class F>
bool has_or_else(long, O&& o, F&& f)
{ return false; }
void test_sfinae() {
std::optional<int> o1;
std::optional<MoveOnly> o2;
std::optional<NonMovable> o3;
assert( has_or_else(0, o1, [&](){ return std::optional<int>(); }));
assert( has_or_else(0, std::move(o1), [&](){ return std::optional<int>(); }));
assert(!has_or_else(0, o2, [&](){ return std::optional<MoveOnly>(); }));
assert( has_or_else(0, std::move(o2), [&](){ return std::optional<MoveOnly>(); }));
assert(!has_or_else(0, o3, [&](){ return std::optional<NonMovable>(); }));
assert(!has_or_else(0, std::move(o3), [&](){ return std::optional<NonMovable>(); }));
assert(!has_or_else(0, o1, [&](int){ return std::optional<int>(); }));
assert(!has_or_else(0, o1, [&](int){}));
assert(!has_or_else(0, o1, 42));
}
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113408/new/
https://reviews.llvm.org/D113408
More information about the libcxx-commits
mailing list