Classes | Public Member Functions | List of all members
static_string_view Class Reference

static_string_view More...

#include <static_string_view.hh>


struct  lifetime_ok_tag

Public Member Functions

template<size_t N>
constexpr static_string_view (char(&buf)[N])=delete
template<size_t N>
constexpr static_string_view (const char(&buf)[N])
constexpr static_string_view (lifetime_ok_tag, std::string_view v)
constexpr operator std::string_view () const

Detailed Description


This is like std::string_view, but points to a string with static lifetime (e.g. a string literal). In other words, the pointed-to-string is guaranteed to remain valid. This allows to store just a reference to the string instead of having to copy it into e.g. a std::string object.

The intention is that objects of this class can only be constructed from string-literals. For example constructing from std::string, std::string_view or 'const char*' will result in compile errors. (See unittest for more details).

In some (rare?) cases you may want something like this, but string literals are too restrictive. Using the 'make_string_storage()' function below might be a solution. But then the programmer takes responsibility of correctly managing lifetimes (then the c++ compiler doesn't help anymore).

Definition at line 27 of file static_string_view.hh.

Constructor & Destructor Documentation

◆ static_string_view() [1/3]

template<size_t N>
constexpr static_string_view::static_string_view ( char(&)  buf[N])

◆ static_string_view() [2/3]

template<size_t N>
constexpr static_string_view::static_string_view ( const char(&)  buf[N])

Definition at line 36 of file static_string_view.hh.

◆ static_string_view() [3/3]

constexpr static_string_view::static_string_view ( lifetime_ok_tag  ,
std::string_view  v 

Definition at line 44 of file static_string_view.hh.

Member Function Documentation

◆ operator std::string_view()

constexpr static_string_view::operator std::string_view ( ) const

Definition at line 48 of file static_string_view.hh.

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