From 2a315442b2744301c351988a3ebe6516b782ffbc Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Thu, 2 Jan 2025 18:52:07 +0100 Subject: [PATCH] Use `std::remove_cvref_t`. --- NEWS | 1 + include/pqxx/internal/conversions.hxx | 8 ++++---- include/pqxx/internal/stream_query.hxx | 2 +- include/pqxx/params.hxx | 2 +- include/pqxx/row.hxx | 2 +- include/pqxx/separated_list.hxx | 2 +- include/pqxx/strconv.hxx | 6 +++--- include/pqxx/stream_from.hxx | 2 +- include/pqxx/types.hxx | 13 +++++++------ include/pqxx/util.hxx | 10 +++++----- include/pqxx/zview.hxx | 4 ++-- src/params.cxx | 2 +- 12 files changed, 28 insertions(+), 26 deletions(-) diff --git a/NEWS b/NEWS index 4d6ebb86c..d49c76426 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ - Assume compiler supports concepts. - Assume compiler supports integral conversions in `charconv`. - Assume compiler supports spans, ranges, and `cmp_less` etc. + - Assume compiler supports `std::remove_cvref_t`. - Assume compiler supports `[[likely]]` & `[[unlikely]]`. - Assume compiler supports `ssize()`. - Assume compiler supports ISO-646 without needing `` header. diff --git a/include/pqxx/internal/conversions.hxx b/include/pqxx/internal/conversions.hxx index f9bf91f99..ee6826811 100644 --- a/include/pqxx/internal/conversions.hxx +++ b/include/pqxx/internal/conversions.hxx @@ -334,7 +334,7 @@ template struct nullness> return value.valueless_by_exception() or std::visit( [](auto const &i) noexcept { - return nullness>::is_null(i); + return nullness>::is_null(i); }, value); } @@ -357,7 +357,7 @@ template struct string_traits> { return std::visit( [begin, end](auto const &i) { - return string_traits>::into_buf(begin, end, i); + return string_traits>::into_buf(begin, end, i); }, value); } @@ -365,7 +365,7 @@ template struct string_traits> { return std::visit( [begin, end](auto const &i) { - return string_traits>::to_buf(begin, end, i); + return string_traits>::to_buf(begin, end, i); }, value); } @@ -1031,7 +1031,7 @@ namespace pqxx::internal template struct array_string_traits { private: - using elt_type = strip_t>; + using elt_type = std::remove_cvref_t>; using elt_traits = string_traits; static constexpr zview s_null{"NULL"}; diff --git a/include/pqxx/internal/stream_query.hxx b/include/pqxx/internal/stream_query.hxx index 5a11b6589..642dcefac 100644 --- a/include/pqxx/internal/stream_query.hxx +++ b/include/pqxx/internal/stream_query.hxx @@ -268,7 +268,7 @@ private: template TARGET parse_field(zview line, std::size_t &offset, char *&write) { - using field_type = strip_t; + using field_type = std::remove_cvref_t; using nullity = nullness; assert(offset <= std::size(line)); diff --git a/include/pqxx/params.hxx b/include/pqxx/params.hxx index 271bd6cde..c3d58d649 100644 --- a/include/pqxx/params.hxx +++ b/include/pqxx/params.hxx @@ -118,7 +118,7 @@ public: template void append(TYPE const &value) & { // TODO: Pool storage for multiple string conversions in one buffer? - if constexpr (nullness>::always_null) + if constexpr (nullness>::always_null) { ignore_unused(value); m_params.emplace_back(); diff --git a/include/pqxx/row.hxx b/include/pqxx/row.hxx index 46488e125..c1388e206 100644 --- a/include/pqxx/row.hxx +++ b/include/pqxx/row.hxx @@ -550,7 +550,7 @@ const_row_iterator::operator-(const_row_iterator const &i) const noexcept template inline void row::extract_value(Tuple &t) const { - using field_type = strip_t(t))>; + using field_type = std::remove_cvref_t(t))>; field const f{m_result, m_index, index}; std::get(t) = from_string(f); } diff --git a/include/pqxx/separated_list.hxx b/include/pqxx/separated_list.hxx index 5e0f07025..e3187def2 100644 --- a/include/pqxx/separated_list.hxx +++ b/include/pqxx/separated_list.hxx @@ -53,7 +53,7 @@ separated_list(std::string_view sep, ITER begin, ITER end, ACCESS access) return to_string(access(begin)); // From here on, we've got at least 2 elements -- meaning that we need sep. - using elt_type = strip_t; + using elt_type = std::remove_cvref_t; using traits = string_traits; std::size_t budget{0}; diff --git a/include/pqxx/strconv.hxx b/include/pqxx/strconv.hxx index adf342581..e3053d703 100644 --- a/include/pqxx/strconv.hxx +++ b/include/pqxx/strconv.hxx @@ -510,7 +510,7 @@ inline void into_string(TYPE const &value, std::string &out); template [[nodiscard]] inline constexpr bool is_null(TYPE const &value) noexcept { - return nullness>::is_null(value); + return nullness>::is_null(value); } @@ -521,7 +521,7 @@ template template [[nodiscard]] inline std::size_t size_buffer(TYPE const &...value) noexcept { - return (string_traits>::size_buffer(value) + ...); + return (string_traits>::size_buffer(value) + ...); } @@ -602,7 +602,7 @@ inline zview generic_to_buf(char *begin, char *end, TYPE const &value) */ template concept binary = std::ranges::contiguous_range and - std::is_same_v>, std::byte>; + std::is_same_v>, std::byte>; #endif //@} } // namespace pqxx diff --git a/include/pqxx/stream_from.hxx b/include/pqxx/stream_from.hxx index 665f422df..335a6e0f5 100644 --- a/include/pqxx/stream_from.hxx +++ b/include/pqxx/stream_from.hxx @@ -343,7 +343,7 @@ template inline stream_from &stream_from::operator>>(Tuple &t) template inline void stream_from::extract_value(Tuple &t) const { - using field_type = strip_t(t))>; + using field_type = std::remove_cvref_t(t))>; using nullity = nullness; assert(index < std::size(m_fields)); if constexpr (nullity::always_null) diff --git a/include/pqxx/types.hxx b/include/pqxx/types.hxx index e4056a07b..7111f2691 100644 --- a/include/pqxx/types.hxx +++ b/include/pqxx/types.hxx @@ -17,6 +17,7 @@ #include #include #include +#include namespace pqxx @@ -70,10 +71,10 @@ enum class format : int /// Remove any constness, volatile, and reference-ness from a type. -/** @deprecated In C++20 we'll replace this with std::remove_cvref. +/** @deprecated Use `std::remove_cvref` instead. */ template -using strip_t = std::remove_cv_t>; +using strip_t = std::remove_cvref_t; #if defined(PQXX_HAVE_CONCEPTS) @@ -82,14 +83,14 @@ using strip_t = std::remove_cv_t>; * which we may or may not end up using for this. */ template -using value_type = strip_t()))>; +using value_type = std::remove_cvref_t()))>; #else // PQXX_HAVE_CONCEPTS /// The type of a container's elements. /** At the time of writing there's a similar thing in `std::experimental`, * which we may or may not end up using for this. */ template -using value_type = strip_t()))>; +using value_type = std::remove_cvref_t()))>; #endif // PQXX_HAVE_CONCEPTS @@ -97,12 +98,12 @@ using value_type = strip_t()))>; /// Concept: Any type that we can read as a string of `char`. template concept char_string = std::ranges::contiguous_range and - std::same_as>, char>; + std::same_as>, char>; /// Concept: Anything we can iterate to get things we can read as strings. template concept char_strings = - std::ranges::range and char_string>>; + std::ranges::range and char_string>>; /// Concept: Anything we might want to treat as binary data. template diff --git a/include/pqxx/util.hxx b/include/pqxx/util.hxx index f61af0ca0..811643ee4 100644 --- a/include/pqxx/util.hxx +++ b/include/pqxx/util.hxx @@ -347,7 +347,7 @@ bytes_view binary_cast(TYPE const &data) // C++20: Use std::as_bytes. return { reinterpret_cast( - const_cast const *>( + const_cast const *>( std::data(data))), std::size(data)}; } @@ -539,15 +539,15 @@ template using args_t = decltype(args_f(std::declval())); -/// Helper: Apply `strip_t` to each of a tuple type's component types. +/// Apply `std::remove_cvref_t` to each of a tuple type's component types. /** This function has no definition. It is not meant to be called, only to be * used to deduce the right types. */ template -std::tuple...> strip_types(std::tuple const &); +std::tuple...> strip_types(std::tuple const &); -/// Take a tuple type and apply @ref strip_t to its component types. +/// Take a tuple type and apply std::remove_cvref_t to its component types. template using strip_types_t = decltype(strip_types(std::declval())); @@ -591,7 +591,7 @@ error_string(int err_num, std::array &buffer) # else auto const err_result{strerror_r(err_num, std::data(buffer), BYTES)}; # endif - if constexpr (std::is_same_v, char *>) + if constexpr (std::is_same_v, char *>) { // GNU version of strerror_r; returns the error string, which may or may // not reside within buffer. diff --git a/include/pqxx/zview.hxx b/include/pqxx/zview.hxx index 383184ad0..8c536782f 100644 --- a/include/pqxx/zview.hxx +++ b/include/pqxx/zview.hxx @@ -131,8 +131,8 @@ namespace pqxx::internal * support each of these individually. */ template -concept ZString = std::is_convertible_v, char const *> or - std::is_convertible_v, zview> or +concept ZString = std::is_convertible_v, char const *> or + std::is_convertible_v, zview> or std::is_convertible_v; } // namespace pqxx::internal #endif // PQXX_HAVE_CONCEPTS diff --git a/src/params.cxx b/src/params.cxx index 815882723..43f14cbfe 100644 --- a/src/params.cxx +++ b/src/params.cxx @@ -93,7 +93,7 @@ pqxx::internal::c_params pqxx::params::make_c_params() const for (auto const ¶m : m_params) std::visit( [&p](auto const &value) { - using T = strip_t; + using T = std::remove_cvref_t; if constexpr (std::is_same_v) {