Skip to content

Commit

Permalink
Use std::remove_cvref_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtv committed Jan 2, 2025
1 parent 38d715b commit 2a31544
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 26 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<ciso646>` header.
Expand Down
8 changes: 4 additions & 4 deletions include/pqxx/internal/conversions.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ template<typename... T> struct nullness<std::variant<T...>>
return value.valueless_by_exception() or
std::visit(
[](auto const &i) noexcept {
return nullness<strip_t<decltype(i)>>::is_null(i);
return nullness<std::remove_cvref_t<decltype(i)>>::is_null(i);
},
value);
}
Expand All @@ -357,15 +357,15 @@ template<typename... T> struct string_traits<std::variant<T...>>
{
return std::visit(
[begin, end](auto const &i) {
return string_traits<strip_t<decltype(i)>>::into_buf(begin, end, i);
return string_traits<std::remove_cvref_t<decltype(i)>>::into_buf(begin, end, i);
},
value);
}
static zview to_buf(char *begin, char *end, std::variant<T...> const &value)
{
return std::visit(
[begin, end](auto const &i) {
return string_traits<strip_t<decltype(i)>>::to_buf(begin, end, i);
return string_traits<std::remove_cvref_t<decltype(i)>>::to_buf(begin, end, i);
},
value);
}
Expand Down Expand Up @@ -1031,7 +1031,7 @@ namespace pqxx::internal
template<typename Container> struct array_string_traits
{
private:
using elt_type = strip_t<value_type<Container>>;
using elt_type = std::remove_cvref_t<value_type<Container>>;
using elt_traits = string_traits<elt_type>;
static constexpr zview s_null{"NULL"};

Expand Down
2 changes: 1 addition & 1 deletion include/pqxx/internal/stream_query.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private:
template<typename TARGET>
TARGET parse_field(zview line, std::size_t &offset, char *&write)
{
using field_type = strip_t<TARGET>;
using field_type = std::remove_cvref_t<TARGET>;
using nullity = nullness<field_type>;

assert(offset <= std::size(line));
Expand Down
2 changes: 1 addition & 1 deletion include/pqxx/params.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public:
template<typename TYPE> void append(TYPE const &value) &
{
// TODO: Pool storage for multiple string conversions in one buffer?
if constexpr (nullness<strip_t<TYPE>>::always_null)
if constexpr (nullness<std::remove_cvref_t<TYPE>>::always_null)
{
ignore_unused(value);
m_params.emplace_back();
Expand Down
2 changes: 1 addition & 1 deletion include/pqxx/row.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ const_row_iterator::operator-(const_row_iterator const &i) const noexcept
template<typename Tuple, std::size_t index>
inline void row::extract_value(Tuple &t) const
{
using field_type = strip_t<decltype(std::get<index>(t))>;
using field_type = std::remove_cvref_t<decltype(std::get<index>(t))>;
field const f{m_result, m_index, index};
std::get<index>(t) = from_string<field_type>(f);
}
Expand Down
2 changes: 1 addition & 1 deletion include/pqxx/separated_list.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<decltype(access(begin))>;
using elt_type = std::remove_cvref_t<decltype(access(begin))>;
using traits = string_traits<elt_type>;

std::size_t budget{0};
Expand Down
6 changes: 3 additions & 3 deletions include/pqxx/strconv.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ inline void into_string(TYPE const &value, std::string &out);
template<typename TYPE>
[[nodiscard]] inline constexpr bool is_null(TYPE const &value) noexcept
{
return nullness<strip_t<TYPE>>::is_null(value);
return nullness<std::remove_cvref_t<TYPE>>::is_null(value);
}


Expand All @@ -521,7 +521,7 @@ template<typename TYPE>
template<typename... TYPE>
[[nodiscard]] inline std::size_t size_buffer(TYPE const &...value) noexcept
{
return (string_traits<strip_t<TYPE>>::size_buffer(value) + ...);
return (string_traits<std::remove_cvref_t<TYPE>>::size_buffer(value) + ...);
}


Expand Down Expand Up @@ -602,7 +602,7 @@ inline zview generic_to_buf(char *begin, char *end, TYPE const &value)
*/
template<class TYPE>
concept binary = std::ranges::contiguous_range<TYPE> and
std::is_same_v<strip_t<value_type<TYPE>>, std::byte>;
std::is_same_v<std::remove_cvref_t<value_type<TYPE>>, std::byte>;
#endif
//@}
} // namespace pqxx
Expand Down
2 changes: 1 addition & 1 deletion include/pqxx/stream_from.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ template<typename Tuple> inline stream_from &stream_from::operator>>(Tuple &t)
template<typename Tuple, std::size_t index>
inline void stream_from::extract_value(Tuple &t) const
{
using field_type = strip_t<decltype(std::get<index>(t))>;
using field_type = std::remove_cvref_t<decltype(std::get<index>(t))>;
using nullity = nullness<field_type>;
assert(index < std::size(m_fields));
if constexpr (nullity::always_null)
Expand Down
13 changes: 7 additions & 6 deletions include/pqxx/types.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <cstdint>
#include <iterator>
#include <ranges>
#include <type_traits>


namespace pqxx
Expand Down Expand Up @@ -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<typename TYPE>
using strip_t = std::remove_cv_t<std::remove_reference_t<TYPE>>;
using strip_t = std::remove_cvref_t<TYPE>;


#if defined(PQXX_HAVE_CONCEPTS)
Expand All @@ -82,27 +83,27 @@ using strip_t = std::remove_cv_t<std::remove_reference_t<TYPE>>;
* which we may or may not end up using for this.
*/
template<std::ranges::range CONTAINER>
using value_type = strip_t<decltype(*std::begin(std::declval<CONTAINER>()))>;
using value_type = std::remove_cvref_t<decltype(*std::begin(std::declval<CONTAINER>()))>;
#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<typename CONTAINER>
using value_type = strip_t<decltype(*std::begin(std::declval<CONTAINER>()))>;
using value_type = std::remove_cvref_t<decltype(*std::begin(std::declval<CONTAINER>()))>;
#endif // PQXX_HAVE_CONCEPTS


#if defined(PQXX_HAVE_CONCEPTS)
/// Concept: Any type that we can read as a string of `char`.
template<typename STRING>
concept char_string = std::ranges::contiguous_range<STRING> and
std::same_as<strip_t<value_type<STRING>>, char>;
std::same_as<std::remove_cvref_t<value_type<STRING>>, char>;

/// Concept: Anything we can iterate to get things we can read as strings.
template<typename RANGE>
concept char_strings =
std::ranges::range<RANGE> and char_string<strip_t<value_type<RANGE>>>;
std::ranges::range<RANGE> and char_string<std::remove_cvref_t<value_type<RANGE>>>;

/// Concept: Anything we might want to treat as binary data.
template<typename DATA>
Expand Down
10 changes: 5 additions & 5 deletions include/pqxx/util.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ bytes_view binary_cast(TYPE const &data)
// C++20: Use std::as_bytes.
return {
reinterpret_cast<std::byte const *>(
const_cast<strip_t<decltype(*std::data(data))> const *>(
const_cast<std::remove_cvref_t<decltype(*std::data(data))> const *>(
std::data(data))),
std::size(data)};
}
Expand Down Expand Up @@ -539,15 +539,15 @@ template<typename CALLABLE>
using args_t = decltype(args_f(std::declval<CALLABLE>()));


/// 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<typename... TYPES>
std::tuple<strip_t<TYPES>...> strip_types(std::tuple<TYPES...> const &);
std::tuple<std::remove_cvref_t<TYPES>...> strip_types(std::tuple<TYPES...> 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<typename... TYPES>
using strip_types_t = decltype(strip_types(std::declval<TYPES...>()));

Expand Down Expand Up @@ -591,7 +591,7 @@ error_string(int err_num, std::array<char, BYTES> &buffer)
# else
auto const err_result{strerror_r(err_num, std::data(buffer), BYTES)};
# endif
if constexpr (std::is_same_v<pqxx::strip_t<decltype(err_result)>, char *>)
if constexpr (std::is_same_v<std::remove_cvref_t<decltype(err_result)>, char *>)
{
// GNU version of strerror_r; returns the error string, which may or may
// not reside within buffer.
Expand Down
4 changes: 2 additions & 2 deletions include/pqxx/zview.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ namespace pqxx::internal
* support each of these individually.
*/
template<typename T>
concept ZString = std::is_convertible_v<strip_t<T>, char const *> or
std::is_convertible_v<strip_t<T>, zview> or
concept ZString = std::is_convertible_v<std::remove_cvref_t<T>, char const *> or
std::is_convertible_v<std::remove_cvref_t<T>, zview> or
std::is_convertible_v<T, std::string const &>;
} // namespace pqxx::internal
#endif // PQXX_HAVE_CONCEPTS
Expand Down
2 changes: 1 addition & 1 deletion src/params.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pqxx::internal::c_params pqxx::params::make_c_params() const
for (auto const &param : m_params)
std::visit(
[&p](auto const &value) {
using T = strip_t<decltype(value)>;
using T = std::remove_cvref_t<decltype(value)>;

if constexpr (std::is_same_v<T, std::nullptr_t>)
{
Expand Down

0 comments on commit 2a31544

Please sign in to comment.