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  Eq
 
struct  Hash
 
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
 
Conversions
constexpr const char * c_str () 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)
 
Comparison: Sym w/ Sym
constexpr auto operator<=> (Sym s1, Sym s2) noexcept
 
constexpr bool operator== (Sym s1, Sym s2) noexcept
 
Comparison: Sym w/ char
constexpr std::strong_ordering operator<=> (Sym s, char c) noexcept
 
constexpr std::strong_ordering operator<=> (char c, Sym s) noexcept
 
constexpr bool operator== (Sym s, char c) noexcept
 
constexpr bool operator== (char c, Sym s) noexcept
 
Comparison: Sym w/ convertible to std::string_view
template<typename T >
requires std::is_convertible_v<T, std::string_view>
constexpr auto operator<=> (Sym lhs, const T &rhs) noexcept
 
template<typename T >
requires std::is_convertible_v<T, std::string_view>
constexpr auto operator<=> (const T &lhs, Sym rhs) noexcept
 
template<typename T >
requires std::is_convertible_v<T, std::string_view>
constexpr bool operator== (Sym lhs, const T &rhs) noexcept
 
template<typename T >
requires std::is_convertible_v<T, std::string_view>
constexpr bool operator== (const T &lhs, Sym rhs) noexcept
 

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 36 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 98 of file sym.h.

References size().

◆ begin()

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

Definition at line 103 of file sym.h.

References c_str().

Referenced by cbegin(), and rend().

◆ c_str()

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

Definition at line 155 of file sym.h.

References view().

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

◆ cbegin()

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

Definition at line 105 of file sym.h.

References begin().

◆ cend()

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

Definition at line 106 of file sym.h.

References end().

◆ crbegin()

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

Definition at line 109 of file sym.h.

References rbegin().

◆ crend()

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

Definition at line 110 of file sym.h.

References rend().

◆ empty()

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

Definition at line 83 of file sym.h.

Referenced by size(), and view().

◆ end()

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

Definition at line 104 of file sym.h.

References c_str(), and size().

Referenced by cend(), and rbegin().

◆ front()

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

Definition at line 97 of file sym.h.

◆ operator bool()

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

Is not empty?

Definition at line 173 of file sym.h.

◆ operator std::string()

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

explicit as this involves a copy.

Definition at line 172 of file sym.h.

References str().

◆ operator std::string_view()

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

Definition at line 166 of file sym.h.

References view().

◆ operator*()

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

Definition at line 167 of file sym.h.

References view().

◆ operator[]()

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

Definition at line 93 of file sym.h.

References c_str(), and size().

◆ rbegin()

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

Definition at line 107 of file sym.h.

References end().

Referenced by crbegin().

◆ rend()

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

Definition at line 108 of file sym.h.

References begin().

Referenced by crend().

◆ size()

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

Definition at line 84 of file sym.h.

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

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

◆ str()

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

This involves a copy.

Definition at line 171 of file sym.h.

References view().

Referenced by operator std::string().

◆ view()

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

Definition at line 157 of file sym.h.

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

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

Friends And Related Symbol Documentation

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

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

Definition at line 173 of file sym.h.

◆ operator<<

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

Definition at line 183 of file sym.h.

◆ operator<=> [1/5]

std::strong_ordering operator<=> ( char c,
Sym s )
friend

Definition at line 122 of file sym.h.

◆ operator<=> [2/5]

template<typename T >
requires std::is_convertible_v<T, std::string_view>
auto operator<=> ( const T & lhs,
Sym rhs )
friend

Definition at line 136 of file sym.h.

◆ operator<=> [3/5]

template<typename T >
requires std::is_convertible_v<T, std::string_view>
auto operator<=> ( Sym lhs,
const T & rhs )
friend

Definition at line 131 of file sym.h.

◆ operator<=> [4/5]

std::strong_ordering operator<=> ( Sym s,
char c )
friend

Definition at line 121 of file sym.h.

◆ operator<=> [5/5]

auto operator<=> ( Sym s1,
Sym s2 )
friend

Definition at line 115 of file sym.h.

◆ operator== [1/5]

bool operator== ( char c,
Sym s )
friend

Definition at line 124 of file sym.h.

◆ operator== [2/5]

template<typename T >
requires std::is_convertible_v<T, std::string_view>
bool operator== ( const T & lhs,
Sym rhs )
friend

Definition at line 148 of file sym.h.

◆ operator== [3/5]

template<typename T >
requires std::is_convertible_v<T, std::string_view>
bool operator== ( Sym lhs,
const T & rhs )
friend

Definition at line 142 of file sym.h.

◆ operator== [4/5]

bool operator== ( Sym s,
char c )
friend

Definition at line 123 of file sym.h.

◆ operator== [5/5]

bool operator== ( Sym s1,
Sym s2 )
friend

Definition at line 116 of file sym.h.

◆ SymPool

friend class SymPool
friend

Definition at line 218 of file sym.h.

Member Data Documentation

◆ Short_String_Bytes

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

Definition at line 38 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 39 of file sym.h.

Referenced by size(), and view().


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