Add a centralized dependent_false type
The main use case is to static_assert on it at the end of a if constexpr / else if constexpr chain. See P2593 for a discussion about why this is pretty much the only "allowed" way of doing so, short of running into IFNDR. I'm actually adding two versions: one for TTP and one for NTTP, as Qt code uses both. Apply it in QFlatMap. Change-Id: Iaff97e350784683d0c3994020b1352d5188931d6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
3a449bbb69
commit
21425c05e0
@ -45,6 +45,13 @@ noexcept(std::conjunction_v<std::is_nothrow_move_constructible<T>,
|
||||
return old;
|
||||
}
|
||||
|
||||
namespace QtPrivate {
|
||||
// helper to be used to trigger a "dependent static_assert(false)"
|
||||
// (for instance, in a final `else` branch of a `if constexpr`.)
|
||||
template <typename T> struct type_dependent_false : std::false_type {};
|
||||
template <auto T> struct value_dependent_false : std::false_type {};
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QTTYPETRAITS_H
|
||||
|
@ -848,7 +848,6 @@ public:
|
||||
size_type remove_if(Predicate pred)
|
||||
{
|
||||
const auto indirect_call_to_pred = [pred = std::move(pred)](iterator it) {
|
||||
[[maybe_unused]] auto dependent_false = [](auto &&...) { return false; };
|
||||
using Pair = decltype(*it);
|
||||
using K = decltype(it.key());
|
||||
using V = decltype(it.value());
|
||||
@ -860,7 +859,7 @@ public:
|
||||
} else if constexpr (std::is_invocable_v<P, K> && !std::is_invocable_v<P, Pair>) {
|
||||
return pred(it.key());
|
||||
} else {
|
||||
static_assert(dependent_false(pred),
|
||||
static_assert(QtPrivate::type_dependent_false<Predicate>(),
|
||||
"Don't know how to call the predicate.\n"
|
||||
"Options:\n"
|
||||
"- pred(*it)\n"
|
||||
|
Loading…
Reference in New Issue
Block a user