Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept ranges where we currently use pqxx::bytes and pqxx::bytes_view #925

Open
jtv opened this issue Jan 9, 2025 · 1 comment
Open
Labels

Comments

@jtv
Copy link
Owner

jtv commented Jan 9, 2025

We've got two C++ types to wrap binary data:

  • pqxx::bytes
  • pqxx::bytes_view

One thing we can do to make this easier for users is to accept C++20 ranges of std::byte where possible (probably have to be contiguous ranges). In places where we ultimately need to call out to a non-inline implementation, we can use std::span<std::byte> as the generic base implementation.

We can get the spans from std::as_bytes and std::as_writable_bytes. The concept for "a contiguous range of bytes" is encoded as the pqxx::binary concept.

@jtv jtv added the 8.0 label Jan 9, 2025
@jtv jtv changed the title Accept ranges where we currently use std::vector<std::byte> etc. Accept ranges where we currently use pqxx::bytes and pqxx::bytes_view Jan 19, 2025
jtv added a commit that referenced this issue Jan 20, 2025
Fixes: #925

Extends a bunch more functions that accept `pqxx::bytes_view` with
variants which accept any type that satisfies the `pqxx::binary`
concept.

Also, change the `pqxx::bytes_view` type alies from being a
`std::basic_string_view<std::byte>` (which doesn't actually have to work
according to the standard!) to being a `std::span<std::byte>`.  This
seems to be broadly compatible with existing code.  For completeness I'm
adding a `pqxx::writable_bytes_view` as well.

Along the way I'm assuming support for C++17's `std::filesystem::path`,
and adding a conversion to `pqxx::zview`.  With that, `pqxx::blob` no
longer needs explicit support for `std::filesystem::path` filenames; it
just accepts `pqxx::zview` and passing a `std::filesystem::path` will
just work.  It avoids some ambiguities.
jtv added a commit that referenced this issue Jan 25, 2025
Fixes: #925

Extends a bunch more functions that accept `pqxx::bytes_view` with
variants which accept any type that satisfies the `pqxx::binary`
concept.

Also, change the `pqxx::bytes_view` type alias from being a
`std::basic_string_view<std::byte>` (which doesn't actually have to work
according to the standard!) to being a `std::span<std::byte>`.  This
seems to be broadly compatible with existing code.  For completeness I'm
adding a `pqxx::writable_bytes_view` as well.
@jtv
Copy link
Owner Author

jtv commented Jan 25, 2025

I've merged a fix into the start-8 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant