pqxx::zview Class Reference

Marker-type wrapper: zero-terminated `std::string_view`. More...

`#include <zview.hxx>`

Inheritance diagram for pqxx::zview:
[legend]

## Public Member Functions

constexpr | zview () noexcept=default
constexpr | zview (char const text[], std::ptrdiff_t len) noexcept(noexcept(std::string_view{text, static_cast< std::size_t >(len)}))
| Convenience overload: construct using pointer and signed length.
constexpr | zview (char text[], std::ptrdiff_t len) noexcept(noexcept(std::string_view{text, static_cast< std::size_t >(len)}))
| Convenience overload: construct using pointer and signed length.
constexpr | zview (std::string_view other) noexcept
| Explicitly promote a `string_view` to a `zview`.
template<typename... Args>
constexpr | zview (Args &&...args)
| Construct from any initialiser you might use for `std::string_view`.
| zview (std::string const &str) noexcept
constexpr | zview (char const str[]) noexcept(noexcept(std::string_view{str}))
| Construct a `zview` from a C-style string.
template<size_t size>
constexpr | zview (char const (&literal)[size])
| Construct a `zview` from a string literal.
constexpr char const * | c_str () const &noexcept
| Either a null pointer, or a zero-terminated text buffer.

## Detailed Description

Marker-type wrapper: zero-terminated `std::string_view`.

Warning
  Use this only if the underlying string is zero-terminated.

When you construct a zview, you are promising that if the data pointer is non-null, the underlying string is zero-terminated. It otherwise behaves exactly like a std::string_view.

The terminating zero is not "in" the string, so it does not count as part of the view's length.

The added guarantee lets the view be used as a C-style string, which often matters since libpqxx builds on top of a C library. For this reason, zview also adds a c_str method.

## Constructor & Destructor Documentation

## zview() [1/8]

constexpr pqxx::zview::zview | ( |  | ) |

constexpr default noexcept

## zview() [2/8]

constexpr pqxx::zview::zview | ( | char const | text[],
|  | std::ptrdiff_t | len
| ) |  |

constexpr noexcept

Convenience overload: construct using pointer and signed length.

References pqxx::text.

## zview() [3/8]

constexpr pqxx::zview::zview | ( | char | text[],
|  | std::ptrdiff_t | len
| ) |  |

constexpr noexcept

Convenience overload: construct using pointer and signed length.

References pqxx::text.

## zview() [4/8]

constexpr pqxx::zview::zview | ( | std::string_view | other | ) |

explicit constexpr noexcept

Explicitly promote a `string_view` to a `zview`.

## zview() [5/8]

template<typename... Args>

constexpr pqxx::zview::zview | ( | Args &&... | args | ) |

explicit constexpr

Construct from any initialiser you might use for `std::string_view`.

Warning
  Only do this if you are sure that the string is zero-terminated.

## zview() [6/8]

pqxx::zview::zview | ( | std::string const & | str | ) |

noexcept

Warning
  There's an implicit conversion from `std::string`.

## zview() [7/8]

constexpr pqxx::zview::zview | ( | char const | str[] | ) |

constexpr noexcept

Construct a `zview` from a C-style string.

Warning
  This scans the string to discover its length. So if you need to do it many times, it's probably better to create the `zview` once and re-use it.

## zview() [8/8]

template<size_t size>

constexpr pqxx::zview::zview | ( | char const (&) | literal[size] | ) |

constexpr

Construct a `zview` from a string literal.

A C++ string literal ("foo") normally looks a lot like a pointer to char const, but that's not really true. It's actually an array of char, which devolves to a pointer when you pass it.

For the purpose of creating a `zview` there is one big difference: if we know the array's size, we don't need to scan through the string in order to find out its length.

## Member Function Documentation

## c_str()

constexpr char const * pqxx::zview::c_str | ( |  | ) | const &

constexpr noexcept

Either a null pointer, or a zero-terminated text buffer.

Referenced by pqxx::result::column_number(), pqxx::encrypt_password(), and pqxx::connection::encrypt_password().

The documentation for this class was generated from the following file:

- zview.hxx