Rename Trivial
The name of Trivial should be more clear and it should match any types.
Bug: None
Test: atest libbase_test
Change-Id: If227b1d162987af519d6cc156efe49469556964a
diff --git a/include/android-base/result.h b/include/android-base/result.h
index 2903cea..3c325f2 100644
--- a/include/android-base/result.h
+++ b/include/android-base/result.h
@@ -369,8 +369,9 @@
};
#ifdef __cpp_concepts
-template<class U>
-concept Trivial = std::is_same_v<U, U>;
+template <class U>
+// Define a concept which **any** type matches to
+concept Universal = std::is_same_v<U, U>;
#endif
} // namespace impl
@@ -410,11 +411,16 @@
return unexpected(std::move(this->error_));
}
#ifdef __cpp_concepts
- template <impl::Trivial U>
+ // The idea here is to match this template method to any type (not simply trivial types).
+ // The reason for including a constraint is to take advantage of the fact that a constrained
+ // method always has strictly lower precedence than a non-constrained method in template
+ // specialization rules (thus avoiding ambiguity). So we use a universally matching constraint to
+ // mark this function as less preferable (but still accepting of all types).
+ template <impl::Universal U>
#else
template <typename U>
#endif
- operator const Result<U, E, include_message>() const && {
+ operator const Result<U, E, include_message>() const&& {
return unexpected(std::move(this->error_));
}