libpqxx
The C++ client library for PostgreSQL
pqxx::internal::enum_traits< ENUM > Struct Template Reference

Helper class for defining enum conversions. More...

#include <strconv.hxx>

Public Types

using impl_type = std::underlying_type_t< ENUM >
 

Static Public Member Functions

static constexpr std::string_view to_buf (std::span< char > buf, ENUM const &value, ctx c={})
 
static ENUM from_string (std::string_view text, ctx c={})
 
static constexpr std::size_t size_buffer (ENUM const &value) noexcept
 

Detailed Description

template<enum_type ENUM>
struct pqxx::internal::enum_traits< ENUM >

Helper class for defining enum conversions.

The conversion will convert enum values to numeric strings, and vice versa.

Warning
These numeric strings do not actually help you with the database, where enum values are textual strings. Once we have reflection in C++26, it should become easier to provide real support.

To define a string conversion for an enum type, derive a string_traits specialisation for the enum from this struct.

There's usually an easier way though: the PQXX_DECLARE_ENUM_CONVERSION macro. Use enum_traits manually only if you need to customise your traits type in more detail.

Member Typedef Documentation

◆ impl_type

template<enum_type ENUM>
using pqxx::internal::enum_traits< ENUM >::impl_type = std::underlying_type_t<ENUM>

Member Function Documentation

◆ from_string()

template<enum_type ENUM>
static ENUM pqxx::internal::enum_traits< ENUM >::from_string ( std::string_view  text,
ctx  c = {} 
)
inlinestatic

◆ size_buffer()

template<enum_type ENUM>
static constexpr std::size_t pqxx::internal::enum_traits< ENUM >::size_buffer ( ENUM const &  value)
inlinestaticconstexprnoexcept

◆ to_buf()

template<enum_type ENUM>
static constexpr std::string_view pqxx::internal::enum_traits< ENUM >::to_buf ( std::span< char >  buf,
ENUM const &  value,
ctx  c = {} 
)
inlinestaticconstexpr

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