Skip to content

Commit

Permalink
Some minor tweaks for char_traits work.
Browse files Browse the repository at this point in the history
Patches up some very minor details after merging @tambry's great contribution in #751.

After this I'll run the automatic formatter as well.
  • Loading branch information
jtv committed Feb 9, 2024
1 parent 90f9c7c commit 97ae7f7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
5 changes: 1 addition & 4 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
- `std::basic_string<std::byte>` and `std::basic_string_view<std::byte>` have
been replaced with `pqxx::bytes` and `pqxx::bytes_view` respectively to
support the removal of generic `std::char_traits` in libc++ 19. Users must
switch to these aliases to support versions from libc++ 18 onward.
In a future major release that start requiring C++20 these are likely to
become aliases for `std::vector<std::byte>` and `std::span<std::byte>` to
better match the intent of the interfaces. (#726)
switch to these aliases to support versions from libc++ 18 onward. (#726)
7.8.1
- Regenerate build files. Should fix ARM Mac build. (#715)
- Reinstate `<ciso646>` that MSVC can't live with or without. (#713)
Expand Down
4 changes: 2 additions & 2 deletions include/pqxx/field.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public:
}
else
{
auto const bytes{c_str()};
from_string(bytes, obj);
auto const data{c_str()};
from_string(data, obj);
return true;
}
}
Expand Down
31 changes: 19 additions & 12 deletions include/pqxx/util.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,11 @@ struct PQXX_LIBEXPORT thread_safety_model
# define PQXX_POTENTIAL_BINARY_ARG typename
#endif

// A custom std::char_traits if the standard library lacks a generic
// implementation or a specialisation for std::byte. Notably they aren't
// required to provide either.
// libc++ 19 removed its generic implementation.
/// Custom `std::char_trast` if the compiler does not provide one.
/** Needed if the standard library lacks a generic implementation or a
* specialisation for std::byte. They aren't strictly required to provide
* either, and libc++ 19 removed its generic implementation.
*/
struct byte_char_traits : std::char_traits<char>
{
using char_type = std::byte;
Expand All @@ -297,6 +298,7 @@ struct byte_char_traits : std::char_traits<char>
return std::memcmp(a, b, size);
}

// XXX: See if we can leave this undefined.
// This is nonsense: we can't determine the length of a random sequence of
// bytes.
// But std::char_traits requires us to implement this so we treat 0 as a
Expand Down Expand Up @@ -360,24 +362,29 @@ inline constexpr bool has_generic_bytes_char_traits =
// Necessary for libc++ 18.
#include "pqxx/internal/ignore-deprecated-pre.hxx"

// Type alias for a container containing bytes.
// Required to support standard libraries without a generic implementation for
// std::char_traits<std::byte>.
// WARNING: Will change to std::vector<std::byte> in the next major release.
// C++20: Change this type.
/// Type alias for a container containing bytes.
/* Required to support standard libraries without a generic implementation for
* `std::char_traits<std::byte>`.
* @warn Will change to `std::vector<std::byte>` in the next major release.
*/
using bytes = std::conditional<
has_generic_bytes_char_traits, std::basic_string<std::byte>,
std::basic_string<std::byte, byte_char_traits>>::type;

// Type alias for a view of bytes.
// Required to support standard libraries without a generic implementation for
// std::char_traits<std::byte>.
// WARNING: Will change to std::span<std::byte> in the next major release.
// C++20: Change this type.
/// Type alias for a view of bytes.
/* Required to support standard libraries without a generic implementation for
* `std::char_traits<std::byte>`.
* @warn Will change to `std::span<std::byte>` in the next major release.
*/
using bytes_view = std::conditional<
has_generic_bytes_char_traits, std::basic_string_view<std::byte>,
std::basic_string_view<std::byte, byte_char_traits>>::type;

#include "pqxx/internal/ignore-deprecated-post.hxx"


/// Cast binary data to a type that libpqxx will recognise as binary.
/** There are many different formats for storing binary data in memory. You
* may have yours as a `std::string`, or a `std::vector<uchar_t>`, or one of
Expand Down

0 comments on commit 97ae7f7

Please sign in to comment.