Skip to content

Commit ad7811a

Browse files
committed
Work through some C++20 notes.
1 parent 9edac8d commit ad7811a

File tree

11 files changed

+21
-29
lines changed

11 files changed

+21
-29
lines changed

include/pqxx/connection.hxx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,6 @@ public:
10581058
*/
10591059
void set_verbosity(error_verbosity verbosity) & noexcept;
10601060

1061-
// C++20: Use std::callable.
1062-
10631061
/// Set a notice handler to the connection.
10641062
/** When a notice comes in (a warning or error message), the connection or
10651063
* result object on which it happens will call the notice handler, passing

include/pqxx/doc/binary-data.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Generally you'll want to use `BYTEA` for reasonably-sized values, and large
99
objects for very large values.
1010

1111
That's the database side. On the C++ side, in libpqxx, all binary data must be
12-
either `pqxx::bytes` or `pqxx::bytes_view`; or if you're building in C++20 or
13-
better, anything that's a block of contiguous `std::byte` in memory.
12+
either `pqxx::bytes` or `pqxx::bytes_view`, or anything else that's a block of
13+
contiguous `std::byte` in memory.
1414

1515
So for example, if you want to write a large object, you'd create a
1616
`pqxx::blob` object. And you might use that to write data in the form of

include/pqxx/internal/conversions.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ inline char *generic_into_buf(char *begin, char *end, T const &value)
103103
}
104104

105105

106-
// C++20: Guard with concept?
106+
// TODO: Define type_traits<std::integral T> directly?
107107
/// String traits for builtin integral types (though not bool).
108-
template<typename T> struct integral_traits
108+
template<std::integral T> struct integral_traits
109109
{
110110
static constexpr bool converts_to_string{true};
111111
static constexpr bool converts_from_string{true};

include/pqxx/params.hxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public:
5656
return m_params.size();
5757
}
5858

59-
// C++20: noexcept.
6059
/// Get the number of parameters (signed).
6160
/** Unlike `size()`, this is not yet `noexcept`. That's because C++17's
6261
* `std::vector` does not have a `ssize()` member function. These member

include/pqxx/prepared_statement.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ namespace pqxx
3939
* zero. If you need a zero byte, you're dealing with binary strings, not
4040
* regular strings. Represent binary strings on the SQL side as `BYTEA`
4141
* (or as large objects). On the C++ side, use types like `pqxx::bytes` or
42-
* `pqxx::bytes_view` or (in C++20) `std::vector<std::byte>`. Also, consider
43-
* large objects on the SQL side and @ref blob on the C++ side.
42+
* `pqxx::bytes_view` or `std::vector<std::byte>`. Also, consider large
43+
* objects on the SQL side and @ref blob on the C++ side.
4444
*
4545
* @warning Passing the wrong number of parameters to a prepared or
4646
* parameterised statement will _break the connection._ The usual exception

src/connection.cxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,13 @@ int pqxx::connection::get_notifs()
639639
}
640640

641641
auto const handler{m_notification_handlers.find(N->relname)};
642-
// C++20: Use "dot notation" to initialise struct fields.
643642
if (handler != std::end(m_notification_handlers))
644-
(handler->second)(notification{*this, channel, N->extra, N->be_pid});
643+
(handler->second)(notification{
644+
.conn=*this,
645+
.channel=channel,
646+
.payload=N->extra,
647+
.backend_pid=N->be_pid,
648+
});
645649

646650
N.reset();
647651
}

src/encodings.cxx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ pqxx::internal::encoding_group enc_group(std::string_view encoding_name)
6565
return pqxx::internal::encoding_group::BIG5;
6666
[[unlikely]] break;
6767
case 'E':
68-
// C++20: Use string_view::starts_with().
69-
if ((sz >= 6u) and (encoding_name.substr(0, 4) == "EUC_"sv))
68+
if (encoding_name.starts_with("EUC_"sv))
7069
{
7170
auto const subtype{encoding_name.substr(4)};
7271
static constexpr std::array<mapping, 5> subtypes{
@@ -90,8 +89,7 @@ pqxx::internal::encoding_group enc_group(std::string_view encoding_name)
9089
[[unlikely]] break;
9190
case 'I':
9291
// We know iso-8859-X, where 5 <= X < 9. They're all monobyte encodings.
93-
// C++20: Use string_view::starts_with().
94-
if ((sz == 10) and (encoding_name.substr(0, 9) == "ISO_8859_"sv))
92+
if (encoding_name.starts_with("ISO_8859_"sv))
9593
{
9694
char const subtype{encoding_name[9]};
9795
if (('5' <= subtype) and (subtype < '9'))
@@ -108,8 +106,7 @@ pqxx::internal::encoding_group enc_group(std::string_view encoding_name)
108106
[[unlikely]] break;
109107
case 'L':
110108
// We know LATIN1 through LATIN10.
111-
// C++20: Use string_view::starts_with().
112-
if (encoding_name.substr(0, 5) == "LATIN"sv)
109+
if (encoding_name.starts_with("LATIN"sv))
113110
{
114111
auto const subtype{encoding_name.substr(5)};
115112
if (subtype.size() == 1)
@@ -140,7 +137,7 @@ pqxx::internal::encoding_group enc_group(std::string_view encoding_name)
140137
if (encoding_name == "UHC"sv)
141138
return pqxx::internal::encoding_group::UHC;
142139
else if (encoding_name == "UTF8"sv)
143-
return pqxx::internal::encoding_group::UTF8;
140+
[[likely]] return pqxx::internal::encoding_group::UTF8;
144141
[[unlikely]] break;
145142
case 'W':
146143
if (encoding_name.substr(0, 3) == "WIN"sv)

src/sql_cursor.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ find_query_end(std::string_view query, pqxx::internal::encoding_group enc)
6666
if (enc == pqxx::internal::encoding_group::MONOBYTE)
6767
{
6868
// This is an encoding where we can scan backwards from the end.
69-
// C++20: Use string_view::ends_with() and sub-view.
7069
while (end > 0 and useless_trail(query[end - 1])) --end;
7170
}
7271
else

src/strconv.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ inline char *wrap_to_chars(char *begin, char *end, T const &value)
146146

147147
namespace pqxx::internal
148148
{
149-
template<typename T>
149+
template<std::integral T>
150150
// NOLINTNEXTLINE(readability-non-const-parameter)
151151
zview integral_traits<T>::to_buf(char *begin, char *end, T const &value)
152152
{
@@ -189,7 +189,7 @@ template zview integral_traits<unsigned long long>::to_buf(
189189
char *, char *, unsigned long long const &);
190190

191191

192-
template<typename T>
192+
template<std::integral T>
193193
char *integral_traits<T>::into_buf(char *begin, char *end, T const &value)
194194
{
195195
// This is exactly what to_chars is good at. Trust standard library
@@ -527,7 +527,7 @@ template<typename T> std::string to_string_float(T value)
527527

528528
namespace pqxx::internal
529529
{
530-
template<typename T> T integral_traits<T>::from_string(std::string_view text)
530+
template<std::integral T> T integral_traits<T>::from_string(std::string_view text)
531531
{
532532
return from_string_arithmetic<T>(text);
533533
}

test/unit/test_range.cxx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,7 @@ void test_range_conversion()
543543

544544
constexpr void test_range_is_constexpr()
545545
{
546-
// Test compile-time operations.
547-
//
548-
// A few things in the standard library need to be constexpr for this to work,
549-
// so we only test it in C++20.
550-
#if __cplusplus >= 202002L
546+
// Test compile-time operations.
551547
using range = pqxx::range<int>;
552548
using ibound = pqxx::inclusive_bound<int>;
553549

@@ -556,7 +552,6 @@ constexpr void test_range_is_constexpr()
556552
static_assert(oneone == oneone);
557553
static_assert(oneone != onethree);
558554
static_assert(onethree.contains(oneone));
559-
#endif
560555
}
561556

562557

0 commit comments

Comments
 (0)