enum_name
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Friends | List of all members
mgutility::basic_string_view< Char > Class Template Reference

A basic string view class template. More...

#include <string_view.hpp>

Public Member Functions

constexpr basic_string_view () noexcept
 Default constructor.
 
constexpr basic_string_view (const Char *str) noexcept
 Constructs a basic_string_view from a C-string.
 
constexpr basic_string_view (const std::basic_string< Char > &str) noexcept
 Constructs a basic_string_view from a std::string.
 
constexpr basic_string_view (const Char *str, size_t len) noexcept
 Constructs a basic_string_view from a C-string and length.
 
constexpr basic_string_view (const basic_string_view &other)
 Copy constructor.
 
constexpr basic_string_view (basic_string_view &&other) noexcept
 Move constructor.
 
MGUTILITY_CNSTXPR basic_string_view< Char > & operator= (const basic_string_view &other) noexcept
 Copy assignment operator.
 
MGUTILITY_CNSTXPR basic_string_view< Char > & operator= (basic_string_view &&other) noexcept
 Move assignment operator.
 
constexpr const Char operator[] (size_t index) const noexcept
 Accesses the character at the given index.
 
constexpr const Char * begin () const noexcept
 Returns an iterator to the beginning of the string.
 
constexpr const Char * end () const noexcept
 Returns an iterator to the end of the string.
 
constexpr bool empty () const noexcept
 Checks if the string is empty.
 
constexpr size_t size () const noexcept
 Returns the size of the string.
 
constexpr const Char * data () const noexcept
 Returns a pointer to the underlying data.
 
constexpr basic_string_view< Char > substr (size_t begin, size_t len=0U) const noexcept
 Returns a substring view.
 
constexpr size_t rfind (Char c, size_t pos=npos) const noexcept
 Finds the last occurrence of a character.
 
constexpr size_t find (Char c, size_t pos=0) const noexcept
 Finds the first occurrence of a character.
 
 operator std::string ()
 Converts the string view to an std::string.
 
 operator std::string () const
 Converts the string view to an std::string (const version).
 

Static Public Attributes

static constexpr auto npos = -1
 

Friends

constexpr friend bool operator== (basic_string_view< Char > lhs, basic_string_view< Char > rhs) noexcept
 Equality operator.
 
constexpr friend bool operator== (basic_string_view< Char > lhs, const Char *rhs) noexcept
 Equality operator.
 
constexpr friend bool operator!= (basic_string_view< Char > lhs, basic_string_view< Char > rhs) noexcept
 Inequality operator.
 
constexpr friend bool operator!= (basic_string_view< Char > lhs, const Char *rhs) noexcept
 Inequality operator.
 
std::ostreamoperator<< (std::ostream &os, const basic_string_view< Char > &sv)
 Stream insertion operator.
 

Detailed Description

template<typename Char = char>
class mgutility::basic_string_view< Char >

A basic string view class template.

Template Parameters
CharThe character type, default is char.

Constructor & Destructor Documentation

◆ basic_string_view() [1/5]

template<typename Char = char>
constexpr mgutility::basic_string_view< Char >::basic_string_view ( const Char * str)
inlineconstexprnoexcept

Constructs a basic_string_view from a C-string.

Parameters
strThe C-string.

◆ basic_string_view() [2/5]

template<typename Char = char>
constexpr mgutility::basic_string_view< Char >::basic_string_view ( const std::basic_string< Char > & str)
inlineconstexprnoexcept

Constructs a basic_string_view from a std::string.

Parameters
strThe std::string.

◆ basic_string_view() [3/5]

template<typename Char = char>
constexpr mgutility::basic_string_view< Char >::basic_string_view ( const Char * str,
size_t len )
inlineconstexprnoexcept

Constructs a basic_string_view from a C-string and length.

Parameters
strThe C-string.
lenThe length of the string.

◆ basic_string_view() [4/5]

template<typename Char = char>
constexpr mgutility::basic_string_view< Char >::basic_string_view ( const basic_string_view< Char > & other)
inlineconstexpr

Copy constructor.

Parameters
otherThe other basic_string_view to copy.

◆ basic_string_view() [5/5]

template<typename Char = char>
constexpr mgutility::basic_string_view< Char >::basic_string_view ( basic_string_view< Char > && other)
inlineconstexprnoexcept

Move constructor.

Parameters
otherThe other basic_string_view to move.

Member Function Documentation

◆ begin()

template<typename Char = char>
constexpr const Char * mgutility::basic_string_view< Char >::begin ( ) const
inlineconstexprnoexcept

Returns an iterator to the beginning of the string.

Returns
A pointer to the first character.

◆ data()

template<typename Char = char>
constexpr const Char * mgutility::basic_string_view< Char >::data ( ) const
inlineconstexprnoexcept

Returns a pointer to the underlying data.

Returns
A pointer to the data.

◆ empty()

template<typename Char = char>
constexpr bool mgutility::basic_string_view< Char >::empty ( ) const
inlineconstexprnoexcept

Checks if the string is empty.

Returns
True if the string is empty, otherwise false.

◆ end()

template<typename Char = char>
constexpr const Char * mgutility::basic_string_view< Char >::end ( ) const
inlineconstexprnoexcept

Returns an iterator to the end of the string.

Returns
A pointer to one past the last character.

◆ find()

template<typename Char = char>
constexpr size_t mgutility::basic_string_view< Char >::find ( Char c,
size_t pos = 0 ) const
inlineconstexprnoexcept

Finds the first occurrence of a character.

Parameters
cThe character to find.
posThe position to start from, default is 0.
Returns
The position of the character or npos if not found.

◆ operator std::string() [1/2]

template<typename Char = char>
mgutility::basic_string_view< Char >::operator std::string ( )
inline

Converts the string view to an std::string.

Returns
An std::string representing the same string.

◆ operator std::string() [2/2]

template<typename Char = char>
mgutility::basic_string_view< Char >::operator std::string ( ) const
inline

Converts the string view to an std::string (const version).

Returns
An std::string representing the same string.

◆ operator=() [1/2]

template<typename Char = char>
MGUTILITY_CNSTXPR basic_string_view< Char > & mgutility::basic_string_view< Char >::operator= ( basic_string_view< Char > && other)
inlinenoexcept

Move assignment operator.

Parameters
otherThe other basic_string_view to move.
Returns
A reference to this object.

◆ operator=() [2/2]

template<typename Char = char>
MGUTILITY_CNSTXPR basic_string_view< Char > & mgutility::basic_string_view< Char >::operator= ( const basic_string_view< Char > & other)
inlinenoexcept

Copy assignment operator.

Parameters
otherThe other basic_string_view to copy.
Returns
A reference to this object.

◆ operator[]()

template<typename Char = char>
constexpr const Char mgutility::basic_string_view< Char >::operator[] ( size_t index) const
inlineconstexprnoexcept

Accesses the character at the given index.

Parameters
indexThe index.
Returns
The character at the index.

◆ rfind()

template<typename Char = char>
constexpr size_t mgutility::basic_string_view< Char >::rfind ( Char c,
size_t pos = npos ) const
inlineconstexprnoexcept

Finds the last occurrence of a character.

Parameters
cThe character to find.
posThe position to start from, default is npos.
Returns
The position of the character or npos if not found.

◆ size()

template<typename Char = char>
constexpr size_t mgutility::basic_string_view< Char >::size ( ) const
inlineconstexprnoexcept

Returns the size of the string.

Returns
The size of the string.

◆ substr()

template<typename Char = char>
constexpr basic_string_view< Char > mgutility::basic_string_view< Char >::substr ( size_t begin,
size_t len = 0U ) const
inlineconstexprnoexcept

Returns a substring view.

Parameters
beginThe starting position.
lenThe length of the substring.
Returns
A basic_string_view representing the substring.

Friends And Related Symbol Documentation

◆ operator!= [1/2]

template<typename Char = char>
constexpr friend bool operator!= ( basic_string_view< Char > lhs,
basic_string_view< Char > rhs )
friend

Inequality operator.

Parameters
lhsThe left-hand side basic_string_view.
rhsThe right-hand side basic_string_view.
Returns
True if the strings are not equal, otherwise false.

◆ operator!= [2/2]

template<typename Char = char>
constexpr friend bool operator!= ( basic_string_view< Char > lhs,
const Char * rhs )
friend

Inequality operator.

Parameters
lhsThe left-hand side basic_string_view.
rhsThe right-hand side C-string.
Returns
True if the strings are not equal, otherwise false.

◆ operator<<

template<typename Char = char>
std::ostream & operator<< ( std::ostream & os,
const basic_string_view< Char > & sv )
friend

Stream insertion operator.

Parameters
osThe output stream.
svThe basic_string_view.
Returns
A reference to the output stream.

◆ operator== [1/2]

template<typename Char = char>
constexpr friend bool operator== ( basic_string_view< Char > lhs,
basic_string_view< Char > rhs )
friend

Equality operator.

Parameters
lhsThe left-hand side basic_string_view.
rhsThe right-hand side basic_string_view.
Returns
True if the strings are equal, otherwise false.

◆ operator== [2/2]

template<typename Char = char>
constexpr friend bool operator== ( basic_string_view< Char > lhs,
const Char * rhs )
friend

Equality operator.

Parameters
lhsThe left-hand side basic_string_view.
rhsThe right-hand side C-string.
Returns
True if the strings are equal, otherwise false.

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