Struct string

Synopsis

#include <toml/string.hpp>

struct string

Description

No description yet.

Methods

string overload
~string
operator std::string &
operator std::string &&
operator std::string const &
operator+= overload
operator= overload

Source

Lines 25-71 in toml/string.hpp.

struct string
{
    string()  = default;
    ~string() = default;
    string(const string& s) = default;
    string(string&& s)      = default;
    string& operator=(const string& s) = default;
    string& operator=(string&& s)      = default;

    string(const std::string& s): kind(string_t::basic), str(s){}
    string(const std::string& s, string_t k):   kind(k), str(s){}
    string(const char* s):        kind(string_t::basic), str(s){}
    string(const char* s,        string_t k):   kind(k), str(s){}

    string(std::string&& s): kind(string_t::basic), str(std::move(s)){}
    string(std::string&& s, string_t k):   kind(k), str(std::move(s)){}

    string& operator=(const std::string& s)
    {kind = string_t::basic; str = s; return *this;}
    string& operator=(std::string&& s)
    {kind = string_t::basic; str = std::move(s); return *this;}

    operator std::string&       () &      noexcept {return str;}
    operator std::string const& () const& noexcept {return str;}
    operator std::string&&      () &&     noexcept {return std::move(str);}

    string& operator+=(const char*        rhs) {str += rhs; return *this;}
    string& operator+=(const char         rhs) {str += rhs; return *this;}
    string& operator+=(const std::string& rhs) {str += rhs; return *this;}
    string& operator+=(const string&      rhs) {str += rhs.str; return *this;}

#if __cplusplus >= 201703L
    explicit string(std::string_view s): kind(string_t::basic), str(s){}
    string(std::string_view s, string_t k): kind(k), str(s){}

    string& operator=(std::string_view s)
    {kind = string_t::basic; str = s; return *this;}

    explicit operator std::string_view() const noexcept
    {return std::string_view(str);}

    string& operator+=(const std::string_view& rhs) {str += rhs; return *this;}
#endif

    string_t    kind;
    std::string str;
};





Add Discussion as Guest

Log in