...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::log::basic_string_literal — String literal wrapper.
// In header: <boost/log/utility/string_literal.hpp> template<typename CharT, typename TraitsT> class basic_string_literal { public: // types typedef CharT value_type; typedef TraitsT traits_type; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; typedef const value_type * const_pointer; typedef value_type const & const_reference; typedef const value_type * const_iterator; typedef std::reverse_iterator< const_iterator > const_reverse_iterator; typedef std::basic_string< value_type, traits_type > string_type; // Corresponding STL string type. // construct/copy/destruct basic_string_literal() noexcept; template<typename T, size_type LenV> basic_string_literal(T(&)) noexcept; basic_string_literal(basic_string_literal const &) noexcept; this_type & operator=(this_type const &) noexcept; template<typename T, size_type LenV> this_type & operator=(T(&)) noexcept; // public member functions bool operator==(this_type const &) const noexcept; bool operator==(const_pointer) const noexcept; bool operator==(string_type const &) const; bool operator<(this_type const &) const noexcept; bool operator<(const_pointer) const noexcept; bool operator<(string_type const &) const; bool operator>(this_type const &) const noexcept; bool operator>(const_pointer) const noexcept; bool operator>(string_type const &) const; const_reference operator[](size_type) const noexcept; const_reference at(size_type) const; const_pointer c_str() const noexcept; const_pointer data() const noexcept; size_type size() const noexcept; size_type length() const noexcept; bool empty() const noexcept; const_iterator begin() const noexcept; const_iterator end() const noexcept; const_reverse_iterator rbegin() const noexcept; const_reverse_iterator rend() const noexcept; string_type str() const; void clear() noexcept; void swap(this_type &) noexcept; this_type & assign(this_type const &) noexcept; template<typename T, size_type LenV> this_type & assign(T(&)) noexcept; size_type copy(value_type *, size_type, size_type = 0) const; int compare(size_type, size_type, const_pointer, size_type) const; int compare(size_type, size_type, const_pointer) const noexcept; int compare(size_type, size_type, this_type const &) const noexcept; int compare(const_pointer, size_type) const noexcept; int compare(const_pointer) const noexcept; int compare(this_type const &) const noexcept; };
The basic_string_literal
is a thin wrapper around a constant string literal. It provides interface similar to STL strings, but because of read-only nature of string literals, lacks ability to modify string contents. However, basic_string_literal
objects can be assigned to and cleared.
The main advantage of this class comparing to other string classes is that it doesn't dynamically allocate memory and therefore is fast, thin and exception safe.
basic_string_literal
public
construct/copy/destructbasic_string_literal() noexcept;
Constructor
Postconditions: |
|
template<typename T, size_type LenV> basic_string_literal(T(&) p) noexcept;
Constructor from a string literal
Parameters: |
|
||
Postconditions: |
|
basic_string_literal(basic_string_literal const & that) noexcept;
Copy constructor
Parameters: |
|
||
Postconditions: |
|
this_type & operator=(this_type const & that) noexcept;
Assignment operator
Parameters: |
|
||
Postconditions: |
|
template<typename T, size_type LenV> this_type & operator=(T(&) p) noexcept;
Assignment from a string literal
Parameters: |
|
||
Postconditions: |
|
basic_string_literal
public member functionsbool operator==(this_type const & that) const noexcept;
Lexicographical comparison (equality)
Parameters: |
|
||
Returns: |
|
bool operator==(const_pointer str) const noexcept;
Lexicographical comparison (equality)
Parameters: |
|
||
Returns: |
|
bool operator==(string_type const & that) const;
Lexicographical comparison (equality)
Parameters: |
|
||
Returns: |
|
bool operator<(this_type const & that) const noexcept;
Lexicographical comparison (less ordering)
Parameters: |
|
||
Returns: |
|
bool operator<(const_pointer str) const noexcept;
Lexicographical comparison (less ordering)
Parameters: |
|
||
Returns: |
|
bool operator<(string_type const & that) const;
Lexicographical comparison (less ordering)
Parameters: |
|
||
Returns: |
|
bool operator>(this_type const & that) const noexcept;
Lexicographical comparison (greater ordering)
Parameters: |
|
||
Returns: |
|
bool operator>(const_pointer str) const noexcept;
Lexicographical comparison (greater ordering)
Parameters: |
|
||
Returns: |
|
bool operator>(string_type const & that) const;
Lexicographical comparison (greater ordering)
Parameters: |
|
||
Returns: |
|
const_reference operator[](size_type i) const noexcept;
Subscript operator
Parameters: |
|
||
Requires: |
|
||
Returns: |
Constant reference to the requested character |
const_reference at(size_type i) const;
Checked subscript
Throws: An std::exception
-based exception if index i is out of string boundaries
Parameters: |
|
||
Returns: |
Constant reference to the requested character |
const_pointer c_str() const noexcept;
Returns: |
Pointer to the beginning of the literal |
const_pointer data() const noexcept;
Returns: |
Pointer to the beginning of the literal |
size_type size() const noexcept;
Returns: |
Length of the literal |
size_type length() const noexcept;
Returns: |
Length of the literal |
bool empty() const noexcept;
Returns: |
|
const_iterator begin() const noexcept;
Returns: |
Iterator that points to the first character of the literal |
const_iterator end() const noexcept;
Returns: |
Iterator that points after the last character of the literal |
const_reverse_iterator rbegin() const noexcept;
Returns: |
Reverse iterator that points to the last character of the literal |
const_reverse_iterator rend() const noexcept;
Returns: |
Reverse iterator that points before the first character of the literal |
string_type str() const;
Returns: |
STL string constructed from the literal |
void clear() noexcept;
The method clears the literal
Postconditions: |
|
void swap(this_type & that) noexcept;
The method swaps two literals
this_type & assign(this_type const & that) noexcept;
Assignment from another literal
Parameters: |
|
||
Postconditions: |
|
template<typename T, size_type LenV> this_type & assign(T(&) p) noexcept;
Assignment from another literal
Parameters: |
|
||
Postconditions: |
|
size_type copy(value_type * str, size_type n, size_type pos = 0) const;
The method copies the literal or its portion to an external buffer
Throws: An std::exception
-based exception if pos is out of range.
Parameters: |
|
||||||
Requires: |
|
||||||
Returns: |
Number of characters copied |
int compare(size_type pos, size_type n, const_pointer str, size_type len) const;
Lexicographically compares the argument string to a part of this string
Throws: An std::exception
-based exception if pos is out of range.
Parameters: |
|
||||||||
Requires: |
|
||||||||
Returns: |
Zero if the comparand equals this string, a negative value if this string is less than the comparand, a positive value if this string is greater than the comparand. |
int compare(size_type pos, size_type n, const_pointer str) const noexcept;
Lexicographically compares the argument string to a part of this string
Throws: An std::exception
-based exception if pos is out of range.
Parameters: |
|
||||||
Requires: |
|
||||||
Returns: |
Zero if the comparand equals this string, a negative value if this string is less than the comparand, a positive value if this string is greater than the comparand. |
int compare(size_type pos, size_type n, this_type const & that) const noexcept;
Lexicographically compares the argument string literal to a part of this string
Throws: An std::exception
-based exception if pos is out of range.
Parameters: |
|
||||||
Requires: |
|
||||||
Returns: |
Zero if the comparand equals this string, a negative value if this string is less than the comparand, a positive value if this string is greater than the comparand. |
int compare(const_pointer str, size_type len) const noexcept;
Lexicographically compares the argument string to this string
Parameters: |
|
||||
Returns: |
Zero if the comparand equals this string, a negative value if this string is less than the comparand, a positive value if this string is greater than the comparand. |
int compare(const_pointer str) const noexcept;
Lexicographically compares the argument string to this string
Parameters: |
|
||
Returns: |
Zero if the comparand equals this string, a negative value if this string is less than the comparand, a positive value if this string is greater than the comparand. |
int compare(this_type const & that) const noexcept;
Lexicographically compares the argument string to this string
Parameters: |
|
||
Returns: |
Zero if the comparand equals this string, a negative value if this string is less than the comparand, a positive value if this string is greater than the comparand. |