FE 0.6.0
A header-only C++ library for writing frontends
Loading...
Searching...
No Matches
fe::Sym Class Reference

A Symbol just wraps a pointer to Sym::String, so pass Sym itself around as value. More...

#include <fe/sym.h>

Classes

struct  String
 

Public Member Functions

constexpr Sym () noexcept=default
 
Getters
constexpr bool empty () const noexcept
 
constexpr size_t size () const noexcept
 
Access
constexpr char operator[] (size_t i) const noexcept
 
constexpr char front () const noexcept
 
constexpr char back () const noexcept
 
Iterators
constexpr auto begin () const noexcept
 
constexpr auto end () const noexcept
 
constexpr auto cbegin () const noexcept
 
constexpr auto cend () const noexcept
 
constexpr auto rbegin () const noexcept
 
constexpr auto rend () const noexcept
 
constexpr auto crbegin () const noexcept
 
constexpr auto crend () const noexcept
 
Comparisons
constexpr auto operator<=> (Sym other) const noexcept
 
constexpr bool operator== (Sym other) const noexcept
 
constexpr bool operator!= (Sym other) const noexcept
 
constexpr auto operator<=> (char c) const noexcept
 
constexpr auto operator== (char c) const noexcept
 
constexpr auto operator!= (char c) const noexcept
 
Conversions
constexpr const char * c_str () const noexcept
 
constexpr operator const char * () const noexcept
 
constexpr std::string_view view () const noexcept
 
constexpr operator std::string_view () const noexcept
 
constexpr std::string_view operator* () const noexcept
 
constexpr std::string str () const noexcept
 This involves a copy.
 
constexpr operator std::string () const noexcept
 explicit as this involves a copy.
 
constexpr operator bool () const noexcept
 Is not empty?
 

Static Public Attributes

static constexpr size_t Short_String_Bytes = sizeof(uintptr_t)
 
static constexpr size_t Short_String_Mask = Short_String_Bytes - 1
 

Friends

struct ::std::hash< fe::Sym >
 
class SymPool
 
std::ostream & operator<< (std::ostream &o, Sym sym)
 

Detailed Description

A Symbol just wraps a pointer to Sym::String, so pass Sym itself around as value.

Sym is compatible with:

This means that retrieving a std::string_view or a null-terminated C-string is basically free. You can also obtain a std::string (via Sym::str), but this involves a copy. With the exception of the empty string, you should only create Symbols via SymPool::sym. This in turn will toss all Symbols into a big hash set. This makes Sym::operator== and Sym::operator!= an O(1) operation. The empty string is internally handled as nullptr. Thus, you can create a Symbol representing an empty string without having access to the SymPool.

Note
The empty std::string/std::string_view, nullptr, and "\0" are all identified as Sym::Sym().
Warning
Big endian version has not been tested.

Definition at line 39 of file sym.h.

Constructor & Destructor Documentation

◆ Sym()

fe::Sym::Sym ( )
constexprdefaultnoexcept

Member Function Documentation

◆ back()

char fe::Sym::back ( ) const
inlineconstexprnoexcept

Definition at line 99 of file sym.h.

References size().

◆ begin()

auto fe::Sym::begin ( ) const
inlineconstexprnoexcept

Definition at line 104 of file sym.h.

References c_str().

Referenced by cbegin(), and rend().

◆ c_str()

const char * fe::Sym::c_str ( ) const
inlineconstexprnoexcept

Definition at line 132 of file sym.h.

References view().

Referenced by begin(), end(), operator const char *(), and operator[]().

◆ cbegin()

auto fe::Sym::cbegin ( ) const
inlineconstexprnoexcept

Definition at line 106 of file sym.h.

References begin().

◆ cend()

auto fe::Sym::cend ( ) const
inlineconstexprnoexcept

Definition at line 107 of file sym.h.

References end().

◆ crbegin()

auto fe::Sym::crbegin ( ) const
inlineconstexprnoexcept

Definition at line 110 of file sym.h.

References rbegin().

◆ crend()

auto fe::Sym::crend ( ) const
inlineconstexprnoexcept

Definition at line 111 of file sym.h.

References rend().

◆ empty()

bool fe::Sym::empty ( ) const
inlineconstexprnoexcept

Definition at line 84 of file sym.h.

Referenced by size(), and view().

◆ end()

auto fe::Sym::end ( ) const
inlineconstexprnoexcept

Definition at line 105 of file sym.h.

References c_str(), and size().

Referenced by cend(), and rbegin().

◆ front()

char fe::Sym::front ( ) const
inlineconstexprnoexcept

Definition at line 98 of file sym.h.

◆ operator bool()

fe::Sym::operator bool ( ) const
inlineexplicitconstexprnoexcept

Is not empty?

Definition at line 150 of file sym.h.

◆ operator const char *()

fe::Sym::operator const char * ( ) const
inlineconstexprnoexcept

Definition at line 133 of file sym.h.

References c_str().

◆ operator std::string()

fe::Sym::operator std::string ( ) const
inlineexplicitconstexprnoexcept

explicit as this involves a copy.

Definition at line 149 of file sym.h.

References str().

◆ operator std::string_view()

fe::Sym::operator std::string_view ( ) const
inlineconstexprnoexcept

Definition at line 143 of file sym.h.

References view().

◆ operator!=() [1/2]

auto fe::Sym::operator!= ( char c) const
inlineconstexprnoexcept

Definition at line 127 of file sym.h.

◆ operator!=() [2/2]

bool fe::Sym::operator!= ( Sym other) const
inlineconstexprnoexcept

Definition at line 118 of file sym.h.

◆ operator*()

std::string_view fe::Sym::operator* ( ) const
inlineconstexprnoexcept

Definition at line 144 of file sym.h.

References view().

◆ operator<=>() [1/2]

auto fe::Sym::operator<=> ( char c) const
inlineconstexprnoexcept

Definition at line 119 of file sym.h.

References size().

◆ operator<=>() [2/2]

auto fe::Sym::operator<=> ( Sym other) const
inlineconstexprnoexcept

Definition at line 116 of file sym.h.

References view().

◆ operator==() [1/2]

auto fe::Sym::operator== ( char c) const
inlineconstexprnoexcept

Definition at line 126 of file sym.h.

◆ operator==() [2/2]

bool fe::Sym::operator== ( Sym other) const
inlineconstexprnoexcept

Definition at line 117 of file sym.h.

◆ operator[]()

char fe::Sym::operator[] ( size_t i) const
inlineconstexprnoexcept

Definition at line 94 of file sym.h.

References c_str(), and size().

◆ rbegin()

auto fe::Sym::rbegin ( ) const
inlineconstexprnoexcept

Definition at line 108 of file sym.h.

References end().

Referenced by crbegin().

◆ rend()

auto fe::Sym::rend ( ) const
inlineconstexprnoexcept

Definition at line 109 of file sym.h.

References begin().

Referenced by crend().

◆ size()

size_t fe::Sym::size ( ) const
inlineconstexprnoexcept

Definition at line 85 of file sym.h.

References empty(), Short_String_Mask, and size().

Referenced by back(), end(), operator<=>(), operator[](), size(), and view().

◆ str()

std::string fe::Sym::str ( ) const
inlineconstexprnoexcept

This involves a copy.

Definition at line 148 of file sym.h.

References view().

Referenced by operator std::string().

◆ view()

std::string_view fe::Sym::view ( ) const
inlineconstexprnoexcept

Definition at line 135 of file sym.h.

References empty(), Short_String_Mask, and size().

Referenced by c_str(), operator std::string_view(), operator*(), operator<=>(), and str().

Friends And Related Symbol Documentation

◆ ::std::hash< fe::Sym >

friend struct ::std::hash< fe::Sym >
friend

Definition at line 150 of file sym.h.

◆ operator<<

std::ostream & operator<< ( std::ostream & o,
Sym sym )
friend

Definition at line 159 of file sym.h.

◆ SymPool

friend class SymPool
friend

Definition at line 166 of file sym.h.

Member Data Documentation

◆ Short_String_Bytes

size_t fe::Sym::Short_String_Bytes = sizeof(uintptr_t)
staticconstexpr

Definition at line 41 of file sym.h.

Referenced by fe::SymPool::sym().

◆ Short_String_Mask

size_t fe::Sym::Short_String_Mask = Short_String_Bytes - 1
staticconstexpr

Definition at line 42 of file sym.h.

Referenced by size(), and view().


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