libpqxx
The C++ client library for PostgreSQL
pqxx::zview Class Referencefinal

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

#include <zview.hxx>

+ Inheritance diagram for pqxx::zview:
+ Collaboration diagram for pqxx::zview:

Public Member Functions

constexpr zview () noexcept
 Default constructor produces a zero-terminated empty string. More...
 
constexpr PQXX_ZARGS 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. More...
 
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. More...
 
constexpr zview (std::string_view other) noexcept
 Explicitly promote a string_view to a zview. More...
 
template<typename... Args>
constexpr zview (Args &&...args)
 Construct from any initialiser you might use for std::string_view. More...
 
constexpr zview (std::string const &str) noexcept
 
constexpr PQXX_ZARGS zview (char const str[]) noexcept(noexcept(std::string_view{str}))
 Construct a zview from a C-style string. More...
 
 zview (std::nullptr_t)=delete
 
template<size_t size>
constexpr PQXX_ZARGS zview (char const (&literal)[size])
 Construct a zview from a string literal. More...
 
constexpr char const * c_str () const &noexcept
 Return as C string. More...
 
constexpr operator char const * () const noexcept
 Return as C string. More...
 
constexpr bool operator== (zview const &rhs) const noexcept
 Disambiguating comparison operator: leave it to std::string_view. More...
 
constexpr bool operator!= (zview const &rhs) const noexcept
 Disambiguating comparison operator: leave it to std::string_view. More...
 

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 the data pointer is non-null, and 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/9]

constexpr pqxx::zview::zview ( )
inlineconstexprnoexcept

Default constructor produces a zero-terminated empty string.

◆ zview() [2/9]

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

Convenience overload: construct using pointer and signed length.

Even though you specify the length, there must still be a zero byte just beyond that length, at text[len].

◆ zview() [3/9]

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

Convenience overload: construct using pointer and signed length.

◆ zview() [4/9]

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

Explicitly promote a string_view to a zview.

Warning
This is not just a type conversion. It's the caller making a promise that the string is zero-terminated.

◆ zview() [5/9]

template<typename... Args>
constexpr pqxx::zview::zview ( Args &&...  args)
inlineexplicitconstexpr

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/9]

constexpr pqxx::zview::zview ( std::string const &  str)
inlineconstexprnoexcept
Warning
There's an implicit conversion from std::string.

◆ zview() [7/9]

constexpr PQXX_ZARGS pqxx::zview::zview ( char const  str[])
inlineconstexprnoexcept

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/9]

pqxx::zview::zview ( std::nullptr_t  )
delete

◆ zview() [9/9]

template<size_t size>
constexpr PQXX_ZARGS pqxx::zview::zview ( char const (&)  literal[size])
inlineconstexpr

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 &
inlineconstexprnoexcept

Return as C string.

◆ operator char const *()

constexpr pqxx::zview::operator char const * ( ) const
inlineconstexprnoexcept

Return as C string.

◆ operator!=()

constexpr bool pqxx::zview::operator!= ( zview const &  rhs) const
inlineconstexprnoexcept

Disambiguating comparison operator: leave it to std::string_view.

◆ operator==()

constexpr bool pqxx::zview::operator== ( zview const &  rhs) const
inlineconstexprnoexcept

Disambiguating comparison operator: leave it to std::string_view.


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