From a2928b52ff4cd747e110082a40ee01e2f970b3e2 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Mon, 8 Jul 2019 16:49:28 -0700 Subject: [PATCH] Don't implement our own remove_cvref_t. clang-tidy flagged the anonymous namespace in the header as a warning, but in any case, it'll be cleaner to implement this in terms of the existing type traits. Test: build Change-Id: I189986d2a855c028e28dd9d62ab9da012feddc9b --- base/include/android-base/expected.h | 69 +++++++++++----------------- 1 file changed, 27 insertions(+), 42 deletions(-) diff --git a/base/include/android-base/expected.h b/base/include/android-base/expected.h index 957a8a000..6153b7766 100644 --- a/base/include/android-base/expected.h +++ b/base/include/android-base/expected.h @@ -81,15 +81,6 @@ inline constexpr unexpect_t unexpect{}; #define _NODISCARD_ #endif -namespace { -template< class T > -struct remove_cvref { - typedef std::remove_cv_t> type; -}; -template< class T > -using remove_cvref_t = typename remove_cvref::type; -} // namespace - // Class expected template class _NODISCARD_ expected { @@ -182,25 +173,23 @@ class _NODISCARD_ expected { else var_ = unexpected(std::move(rhs.error())); } - template && - !std::is_same_v, std::in_place_t> && - !std::is_same_v, remove_cvref_t> && - !std::is_same_v, remove_cvref_t> && - std::is_convertible_v /* non-explicit */ - )> - constexpr expected(U&& v) - : var_(std::in_place_index<0>, std::forward(v)) {} + template && + !std::is_same_v>, std::in_place_t> && + !std::is_same_v, std::remove_cv_t>> && + !std::is_same_v, std::remove_cv_t>> && + std::is_convertible_v /* non-explicit */ + )> + constexpr expected(U&& v) : var_(std::in_place_index<0>, std::forward(v)) {} - template && - !std::is_same_v, std::in_place_t> && - !std::is_same_v, remove_cvref_t> && - !std::is_same_v, remove_cvref_t> && - !std::is_convertible_v /* explicit */ - )> - constexpr explicit expected(U&& v) - : var_(std::in_place_index<0>, T(std::forward(v))) {} + template && + !std::is_same_v>, std::in_place_t> && + !std::is_same_v, std::remove_cv_t>> && + !std::is_same_v, std::remove_cv_t>> && + !std::is_convertible_v /* explicit */ + )> + constexpr explicit expected(U&& v) : var_(std::in_place_index<0>, T(std::forward(v))) {} template && @@ -269,14 +258,12 @@ class _NODISCARD_ expected { // Note for SFNAIE above applies to here as well expected& operator=(expected&& rhs) = default; - template && - !std::is_same_v, remove_cvref_t> && - !std::conjunction_v, std::is_same>> && - std::is_constructible_v && - std::is_assignable_v && - std::is_nothrow_move_constructible_v - )> + template && + !std::is_same_v, std::remove_cv_t>> && + !std::conjunction_v, std::is_same>> && + std::is_constructible_v && std::is_assignable_v && + std::is_nothrow_move_constructible_v)> expected& operator=(U&& rhs) { var_ = T(std::forward(rhs)); return *this; @@ -648,13 +635,11 @@ class unexpected { constexpr unexpected(const unexpected&) = default; constexpr unexpected(unexpected&&) = default; - template && - !std::is_same_v, std::in_place_t> && - !std::is_same_v, unexpected> - )> - constexpr unexpected(Err&& e) - : val_(std::forward(e)) {} + template && + !std::is_same_v>, std::in_place_t> && + !std::is_same_v>, unexpected>)> + constexpr unexpected(Err&& e) : val_(std::forward(e)) {} template&, Args...>