MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
mtcore Namespace Reference

Core library for C++ with Zig-related functionality. More...

Namespaces

namespace  ascii
 ASCII-related methods for parsing and character classification Split into its own namespace to allow for clear differentiation from any unicode-related methods.
 
namespace  csv
 CSV namespace for CSV-related utilities.
 
namespace  endian
 
namespace  io
 
namespace  iter
 Generic iterator defaults built on common contracts Does not guarantee performance of iterators Actual performance is \(O(N * complexityOfOperator[])\) IE an operator[] with \(O(1)\) will get an iterator complexity of \(O(N)\), while an operator[] with \(O(N)\) will get an iterator complexity of \(O(N^2)\).
 
namespace  results
 Additional algorithms and pipeline functionality that can be performed on groups of results.
 
namespace  slices
 Additional algorithms that can be performed on slices, such as comparisons, searching, etc.
 
namespace  thread
 Thread-related namespace The methods and classes provided by this class are thread-safe Classes and methods provided outside of this class are not thread-safe (with the exception of malloc_alloc) This requires linking mtcore_thread to your application.
 

Classes

struct  Allocator
 Represents a memory allocator Exact behavior depends on the underlying VTable used Should use the a_* methods for working with an allocator. More...
 
struct  ArrayList
 Array list is a growable, dynamic array with elements inside Elements are stored in an array, and are copied when resizing needs to happen Accessing elements is \(O(1)\) Adding elements is worst case \(O(N)\) Removing elements while preserving order is \(O(N)\) Removing elements while not preserving order is \(O(1)\). More...
 
struct  Bitset
 Represents a bitset with dynamically allocated memory (using an mtcore allocator) Allows operating on an arbitrary number of bits. More...
 
struct  Bitset2D
 Represents a bitset with dynamically allocated memory (using an mtcore allocator) Allows operating on an arbitrary number of bits. More...
 
struct  BitsetFixed
 Represents a bitset with dynamically allocated memory (using an mtcore allocator) Allows operating on an arbitrary number of bits. More...
 
struct  ConstPtrIter
 Iterator that gives const pointers to elements of a collection. More...
 
struct  EndianSlice
 A Slice with Endian-aware data which is just a pointer + length + endian direction Accessing elements through the array operator will do bounds checks and will convert to native endian by default (this can be overridden with access methods) Accessing out of bounds will terminate the program instead of throw Can also get sub slices. More...
 
struct  Error
 A struct representing an error Auto convertible to a Result of any type. More...
 
struct  FixedQueue
 Statically allocated FIFO queue with fixed maximum capacity. More...
 
struct  FixedRingBuffer
 Represents a ring buffer with static memory allocation Can be used as a FIFO or LIFO queue Allows memory reuse by wrapping pointers Cannot be dynamically resized. More...
 
struct  GenList
 Represents a generational list where removed items are marked and recycled. More...
 
struct  Handle
 Handle to an item in the list. More...
 
struct  IPv4
 Represents an IP version 4 address (32 bits) Can be converted to an IPv6. More...
 
struct  IPv6
 Represents an IP version 6 address (128 bits) If it represents an IPv4 address, can be converted to an IPv4 address. More...
 
struct  MallocAllocator
 State variable for malloc-based allocator. More...
 
struct  Nullopt
 Placeholder value for any empty Optional (similar to std::nullopt) More...
 
struct  Optional
 Represents a value that may or may not exist (an "Optional" value) Similar concept to std::optional, but different implementation and additional nicety methods which makes this a better alternative for simple loop-based iteration (via copy_if_present and move_if_present) More...
 
struct  Optional< T * >
 Represents a pointer that may or may not be null. More...
 
struct  overload
 Visit overload pattern for std::variant. More...
 
struct  Prng
 Represents a Pseudo Random Number Generator. More...
 
struct  PrngState
 Internal PRNG state. More...
 
struct  PrngVTable
 V-Table for PRNG Designed for having a simple PRNG implementation. More...
 
struct  PtrIter
 Iterator that gives pointers to elements of a collection. More...
 
struct  Queue
 FIFO Queue (First In, First Out) Dynamically allocated, can be resized. More...
 
struct  Rc
 Thread-local reference counted pointer Not thread safe, don't share Reference counting for cleaning up memory Supports weak references as well. More...
 
struct  Result
 Represents a Result that may have an error (error code) or a success value A type of "void" means there is no Result value, but there may be a failure. More...
 
struct  Result< void, ErrType >
 Represents a Result that may have an error (error code) or a success (without a value) More...
 
struct  RingBuffer
 Represents a ring buffer with dynamically allocated memory Can be used as a FIFO or LIFO queue Allows memory reuse rather than continuous memory allocations as it is used May be dynamically resized. More...
 
struct  RuneIterator
 Iterates over runes of utf8 sequences (char, char_t) More...
 
struct  RuneIterator< char16_t >
 Iterates over runes of utf16 sequences Also handles flipping endianness to native endian. More...
 
struct  RuneIterator< char32_t >
 Iterates over runes of utf32 sequences Also handles flipping endianness to native endian. More...
 
struct  SegmentedList
 Segmented list where each segment contains multiple nodes Allows growing the list without having to invalidate all previous memory addresses. More...
 
struct  Slice
 A Slice which is just a pointer + length Accessing elements through the array operator will do bounds checks Accessing out of bounds will terminate the program instead of throw Can also get sub slices. More...
 
struct  SubnetMaskV4
 Represents the bitwise mask for a version 4 subnet. More...
 
struct  SubnetMaskV6
 Gets a subnet mask for an IP version 6 subnet. More...
 
struct  SubnetV4
 A masked IP version 4 address. More...
 
struct  SubnetV6
 A masked IP version 6 address. More...
 
struct  Success
 Represents a success result (auto castable to Result) More...
 
struct  Success< void >
 Represents a success value. More...
 
struct  ThreadLocalDebugAllocator
 State variable for thread local debug allocator Must live longer (and at the same memory address) than all allocators returned by allocator() More...
 
struct  ThreadLocalDynamicArenaAllocator
 State variable for thread local dynamic arena allocator Must live longer (and at the same memory address) than all allocators returned by allocator() More...
 
struct  ThreadLocalFixedArenaAllocator
 State variable for thread local fixed arena allocator Must live longer (and at the same memory address) than all allocators returned by allocator() More...
 
struct  ThreadLocalFixedBufferAllocator
 State variable for thread local fixed buffer allocator Must live longer (and at the same memory address) than all allocators returned by allocator() More...
 
struct  ValIter
 Iterator that gives copies of elements of a collection. More...
 
struct  WeakRc
 Thread-local weak reference counted pointer Not thread safe, don't share Does not hold lifetime. More...
 

Concepts

concept  Ostreamable
 The Ostreamable trait for types Something that implements this trait allows ostream operations.
 
concept  Addressable
 The Addressable trait for types Something that implements this trait allows addressing items by index.
 
concept  MutableAddressable
 The Addressable trait for types Something that implements this trait allows addressing items by index.
 
concept  Iterator
 The Addressable trait for types Something that implements this trait allows addressing items by index.
 
concept  Initable
 
concept  Iterable
 The Iterable trait for types Something that implements this trait can give an iterator to iterate over the elements.
 
concept  StdIterable
 Detect if something is C++ standard iterable.
 
concept  DefaultDeinit
 Represents a type that has a default (no allocator) deinit method.
 
concept  AllocatorDeinit
 Represents a type that has a deinit which takes an allocator (usually does memory cleanup)
 
concept  ResultLike
 Represents a type that fulfills the "result" contract.
 
concept  ResultLikeWithValue
 Represents a type that fulfills the "result" contract while having a success value of a specific type Does NOT check the error value (the error can be of any type)
 
concept  ResultLikeWithVoid
 Represents a type that fulfills the "result" contract while having no success value Does NOT check the error value (the error can be of any type)
 
concept  WriterImpl
 Represents an implementation of a writer (basically checks if the type can be wrapped with Writer<>)
 
concept  WriterImplBytes
 Represents an implementation of a writer that we can get how many bytes were written.
 
concept  WriterImplWritten
 Represents an implementation of a writer that we can get the output.
 
concept  WriterImplResettable
 Represents an implementation of a writer that we can reset.
 
concept  Pointer
 
concept  WriteThrough
 Checks if a writer type is a write-through writer.
 
concept  Flushable
 Represents a type that can be "flushed" (e.g.
 
concept  ReaderImpl
 Represents an implementation of a reader (basically checks if the type can be wrapped with Reader<>)
 
concept  InlineFormattable
 
concept  Formattable
 Represents a type that can be formatted.
 
concept  DefaultFormattable
 Types we want to specify default ostream operators based on Formatter We exclude StdIterable types to exclude the standard library (which generally has ostream operators already) We also exclude several primitives that we define formatting for (they generally have ostream operators as well)
 

Typedefs

using CharSeq = impl::ShortSeq<char, 4>
 
using U8Seq = impl::ShortSeq<char8_t, 4>
 
using U16Seq = impl::ShortSeq<char16_t, 2>
 
using SliceU16Native = EndianSlice<char16_t, std::endian::native>
 Slice type representing native UTF-16 string *.
 
using SliceU16Le = EndianSlice<char16_t, std::endian::little>
 Slice type representing little endian UTF-16 string *.
 
using SliceU16Be = EndianSlice<char16_t, std::endian::big>
 Slice type representing big endian UTF-16 string *.
 
using SliceConstU16Native = EndianSlice<const char16_t, std::endian::native>
 Slice type representing const native UTF-16 string *.
 
using SliceConstU16Le = EndianSlice<const char16_t, std::endian::little>
 Slice type representing const little endian UTF-16 string *.
 
using SliceConstU16Be = EndianSlice<const char16_t, std::endian::big>
 Slice type representing const big endian UTF-16 string *.
 
using SliceU32Native = EndianSlice<char32_t, std::endian::native>
 Slice type representing native UTF-32 string *.
 
using SliceU32Le = EndianSlice<char32_t, std::endian::little>
 Slice type representing little endian UTF-32 string *.
 
using SliceU32Be = EndianSlice<char32_t, std::endian::big>
 Slice type representing big endian UTF-32 string.
 
using SliceConstU32Native = EndianSlice<const char32_t, std::endian::native>
 Slice type representing const native UTF-32 string.
 
using SliceConstU32Le = EndianSlice<const char32_t, std::endian::little>
 Slice type representing const little endian UTF-32 string.
 
using SliceConstU32Be = EndianSlice<const char32_t, std::endian::big>
 Slice type representing const big endian UTF-32 string.
 
using Rune = char32_t
 
using SeedError = int
 Seeding errors can vary differently, using an int to indicate the error code.
 

Enumerations

enum class  AllocationError { AllocationError::ALLOCATION_FAILED }
 Error indicating failed allocation. More...
 
enum class  AllocatorError { AllocatorError::MEMORY_LEAK_DETECTED }
 Error indicating allocator internal state failed (e.g. More...
 
enum class  RuneConversionError { RuneConversionError::NoInput , RuneConversionError::InvalidChars }
 Errors that can occur when doing conversions to a rune. More...
 
enum class  BitStrInitError { BitStrInitError::ALLOCATION_FAILED = static_cast<int>(AllocationError::ALLOCATION_FAILED) , BitStrInitError::INVALID_BINARY_STRING }
 Bitset String-based Initialization Errors. More...
 
enum class  CollectionAddNoAllocationError { CollectionAddNoAllocationError::NO_ROOM }
 Errors when adding elements to collections when no allocation is allowed. More...
 
enum class  IpInitError { IpInitError::INVALID_INPUT }
 Error when initializing an IP address. More...
 
enum class  Ip6ConversionError { Ip6ConversionError::NOT_IP4 }
 Error when converting from IPv6 to IPv4. More...
 
enum class  SubnetMaskError { SubnetMaskError::INVALID_SUBNET_ID }
 Error when creating a subnet mask. More...
 
enum class  Mt19937_64Error { Mt19937_64Error::ALLOCATION_FAILED , Mt19937_64Error::MT19937_BAD_INIT }
 Errors that can happen when making a Mersenne Twister. More...
 
enum class  RcError { CANNOT_ACQUIRE }
 Error for thread-local reference counting. More...
 

Functions

MallocAllocator malloc_alloc () noexcept
 Creates a memory allocator using the standard's malloc under the hood Does no memory tracking Ideal for production/release/high performance.
 
ThreadLocalDebugAllocator debug_alloc_thread_local () noexcept
 NOT THREAD SAFE!
 
ThreadLocalFixedBufferAllocator fixed_buff_thread_local (Slice< u8 > bytes) noexcept
 NOT THREAD SAFE!
 
ThreadLocalFixedArenaAllocator fixed_arena_thread_local (Slice< u8 > bytes) noexcept
 NOT THREAD SAFE!
 
ThreadLocalDynamicArenaAllocator dynamic_arena_thread_local (Allocator *root, size_t elementSizeHint, size_t elementCountHint) noexcept
 NOT THREAD SAFE!
 
constexpr auto is_bom (const char32_t ch)
 Checks if a character is a BOM in native ordering.
 
constexpr auto is_bom_rev_16_bit (const char16_t ch)
 Checks if a 16-bit character is a BOM in reverse ordering.
 
constexpr auto is_bom_rev_32_bit (const char32_t ch)
 Checks if a 32-bit character is a BOM in reverse ordering.
 
Optional< std::endian > u16_detect_endian (const char16_t ch)
 Tries to detect the endian encoding based on a possible BOM mark.
 
Optional< std::endian > u32_detect_endian (const char32_t ch)
 Tries to detect the endian encoding based on a possible BOM mark.
 
constexpr bool is_surrogate (char16_t ch)
 Checks if UTF-16 character is a surrogate.
 
constexpr bool is_high_surrogate (char16_t ch)
 Checks if UTF-16 character is a high surrogate *.
 
constexpr bool is_low_surrogate (char16_t ch)
 Checks if UTF-16 character is a low surrogate *.
 
SliceU16Native endian_from_native_slice (Slice< char16_t > s)
 Gets a UTF-16 endian slice from a slice which is assumed ot be native endian.
 
SliceU32Native endian_from_native_slice (Slice< char32_t > s)
 Gets a UTF-32 endian slice from a slice which is assumed ot be native endian.
 
SliceU16Le endian_from_le_slice (Slice< char16_t > s)
 Gets a UTF-16 endian slice from a slice which is assumed ot be little endian.
 
SliceU32Le endian_from_le_slice (Slice< char32_t > s)
 Gets a UTF-32 endian slice from a slice which is assumed ot be little endian.
 
SliceU16Be endian_from_be_slice (Slice< char16_t > s)
 Gets a UTF-16 endian slice from a slice which is assumed ot be big endian.
 
SliceU32Be endian_from_be_slice (Slice< char32_t > s)
 Gets a UTF-32 endian slice from a slice which is assumed ot be big endian.
 
std::variant< SliceU16Le, SliceU16Beendian_from_slice (Slice< char16_t > s)
 Gets a UTF-16 endian slice from an input slice Will try to use the first character of the slice as a BOM to detect endianness If endian detection fails, will assume native endian Since endian slices are distinct types, this will return a variant (typed union) If there is a BOM, will drop it.
 
std::variant< SliceU32Le, SliceU32Beendian_from_slice (Slice< char32_t > s)
 Gets a UTF-32 endian slice from an input slice Will try to use the first character of the slice as a BOM to detect endianness If endian detection fails, will assume native endian Since endian slices are distinct types, this will return a variant (typed union) If there is a BOM, will drop it.
 
Slice< char16_t > slice_from_native_endian (SliceU16Native s)
 Gets a normal slice from a native endian slice.
 
Slice< const char16_t > slice_from_native_endian (SliceConstU16Native s)
 Gets a normal slice from a native endian slice.
 
Slice< char32_t > slice_from_native_endian (SliceU32Native s)
 Gets a normal slice from a native endian slice.
 
Slice< const char32_t > slice_from_native_endian (SliceConstU32Native s)
 Gets a normal slice from a native endian slice.
 
Slice< char16_t > slice_from_le_endian (SliceU16Native s)
 Gets a normal slice from a little endian slice.
 
Slice< const char16_t > slice_from_le_endian (SliceConstU16Native s)
 Gets a normal slice from a little endian slice.
 
Slice< char32_t > slice_from_le_endian (SliceU32Native s)
 Gets a normal slice from a little endian slice.
 
Slice< const char32_t > slice_from_le_endian (SliceConstU32Native s)
 Gets a normal slice from a little endian slice.
 
Slice< char16_t > slice_from_be_endian (SliceU16Native s)
 Gets a normal slice from a big endian slice.
 
Slice< const char16_t > slice_from_be_endian (SliceConstU16Native s)
 Gets a normal slice from a big endian slice.
 
Slice< char32_t > slice_from_be_endian (SliceU32Native s)
 Gets a normal slice from a big endian slice.
 
Slice< const char32_t > slice_from_be_endian (SliceConstU32Native s)
 Gets a normal slice from a big endian slice.
 
CharSeq rune_to_str (Rune rune)
 Converts a UTF-32 Rune to a sequence of char.
 
U8Seq rune_to_utf8 (Rune rune)
 Converts a UTF-32 Rune to a utf-8 sequence.
 
U16Seq rune_to_utf16 (Rune rune)
 Converts a UTF-32 Rune to a utf-16 sequence.
 
Result< Rune, RuneConversionErrorutf8_to_rune (const Slice< const char8_t > &rune)
 UTF-8 to a Rune.
 
Result< Rune, RuneConversionErrorstr_to_rune (const Slice< const char > &rune)
 Characters to a Rune.
 
Result< Rune, RuneConversionErrorutf16_to_rune (const Slice< const char16_t > &rune)
 UTF-16 to a Rune.
 
Result< Rune, RuneConversionErrorutf16_to_rune (const SliceConstU16Native &rune)
 UTF-16 to a Rune.
 
RuneIterator< char > str_rune_iterator (const Slice< const char > &s)
 Rune iterator for a slice of characters.
 
RuneIterator< char8_t > utf8_rune_iterator (const Slice< const char8_t > &s)
 Rune iterator for a UTF8 sequence.
 
RuneIterator< char16_t > utf16_rune_iterator (const Slice< const char16_t > &s)
 Rune iterator for a UTF16 sequence.
 
RuneIterator< char16_t > utf16_rune_iterator (const SliceConstU16Le &s)
 Rune iterator for a little endian UTF16 sequence.
 
RuneIterator< char16_t > utf16_rune_iterator (const SliceConstU16Be &s)
 Rune iterator for a big endian UTF16 sequence.
 
RuneIterator< char16_t > utf16_rune_iterator (const SliceU16Le &s)
 Rune iterator for a little endian UTF16 sequence.
 
RuneIterator< char16_t > utf16_rune_iterator (const SliceU16Be &s)
 Rune iterator for a big endian UTF16 sequence.
 
RuneIterator< char32_t > utf32_rune_iterator (const Slice< const char32_t > &s)
 Rune iterator for a UTF32 sequence.
 
RuneIterator< char32_t > utf32_rune_iterator (const SliceConstU32Le &s)
 Rune iterator for a little endian UTF32 sequence.
 
RuneIterator< char32_t > utf32_rune_iterator (const SliceConstU32Be &s)
 Rune iterator for a big endian UTF32 sequence.
 
RuneIterator< char32_t > utf32_rune_iterator (const SliceU32Le &s)
 Rune iterator for a little endian UTF32 sequence.
 
RuneIterator< char32_t > utf32_rune_iterator (const SliceU32Be &s)
 Rune iterator for a big endian UTF32 sequence.
 
template<WriterImpl WI>
auto utf32_to_utf16 (io::Writer< WI > &writer, const SliceConstU32Be &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to UTF-16 string Can optionally write a BOM to the prefix.
 
template<WriterImpl WI>
auto utf32_to_utf16 (io::Writer< WI > &writer, const SliceConstU32Le &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to UTF-16 string Can optionally write a BOM to the prefix.
 
template<WriterImpl WI>
auto utf32_to_utf16 (io::Writer< WI > &writer, const Slice< const char32_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to UTF-16 string Can optionally write a BOM to the prefix.
 
template<WriterImpl WI>
auto utf32_to_utf8 (io::Writer< WI > &writer, const SliceConstU32Be &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to UTF-8 string.
 
template<WriterImpl WI>
auto utf32_to_utf8 (io::Writer< WI > &writer, const SliceConstU32Le &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to UTF-8 string.
 
template<WriterImpl WI>
auto utf32_to_utf8 (io::Writer< WI > &writer, const Slice< const char32_t > &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to UTF-8 string.
 
template<WriterImpl WI>
auto utf32_to_str (io::Writer< WI > &writer, const SliceConstU32Be &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to character sequence (UTF-8 encoded chars)
 
template<WriterImpl WI>
auto utf32_to_str (io::Writer< WI > &writer, const SliceConstU32Le &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to character sequence (UTF-8 encoded chars)
 
template<WriterImpl WI>
auto utf32_to_str (io::Writer< WI > &writer, const Slice< const char32_t > &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to character sequence (UTF-8 encoded chars)
 
template<WriterImpl WI>
auto utf8_to_utf32 (io::Writer< WI > &writer, const Slice< const char8_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-8 string to UTF-32.
 
template<WriterImpl WI>
auto str_to_utf32 (io::Writer< WI > &writer, const Slice< const char > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-8 string to UTF-32.
 
template<WriterImpl WI>
auto utf16_to_utf8 (io::Writer< WI > &writer, const SliceConstU16Be &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-8.
 
template<WriterImpl WI>
auto utf16_to_utf32 (io::Writer< WI > &writer, const SliceConstU16Le &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-32.
 
template<WriterImpl WI>
auto utf16_to_utf32 (io::Writer< WI > &writer, const SliceConstU16Be &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-32.
 
template<WriterImpl WI>
auto utf16_to_utf32 (io::Writer< WI > &writer, const Slice< const char16_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-32.
 
template<WriterImpl WI>
auto utf16_to_utf8 (io::Writer< WI > &writer, const SliceConstU16Le &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-8.
 
template<WriterImpl WI>
auto utf16_to_str (io::Writer< WI > &writer, const SliceConstU16Be &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-8.
 
template<WriterImpl WI>
auto utf16_to_str (io::Writer< WI > &writer, const SliceConstU16Le &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-8.
 
template<WriterImpl WI>
auto utf16_to_utf8 (io::Writer< WI > &writer, const Slice< const char16_t > &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-8.
 
template<WriterImpl WI>
auto utf16_to_str (io::Writer< WI > &writer, const Slice< const char16_t > &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-8.
 
template<WriterImpl WI>
auto utf8_to_utf16 (io::Writer< WI > &writer, const Slice< const char8_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-8 string to UTF-16.
 
template<WriterImpl WI>
auto str_to_utf16 (io::Writer< WI > &writer, const Slice< const char > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-8 string to UTF-16.
 
template<WriterImpl WI>
auto utf8_to_str (io::Writer< WI > &writer, const Slice< const char8_t > &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-8 string to character sequence.
 
template<WriterImpl WI>
auto str_to_utf8 (io::Writer< WI > &writer, const Slice< const char > &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a character sequence to UTF-8 string.
 
template<WriterImpl WI>
auto utf16_to_utf16le (io::Writer< WI > &writer, const SliceConstU16Native &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts native UTF-16 to UTF-16 Little Endian.
 
template<WriterImpl WI>
auto utf16_to_utf16le (io::Writer< WI > &writer, const Slice< const char16_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts native UTF-16 to UTF-16 Little Endian.
 
template<WriterImpl WI>
auto utf16_to_utf16be (io::Writer< WI > &writer, const SliceConstU16Native &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts native UTF-16 to UTF-16 Big Endian.
 
template<WriterImpl WI>
auto utf16_to_utf16be (io::Writer< WI > &writer, const Slice< const char16_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts native UTF-16 to UTF-16 Big Endian.
 
template<WriterImpl WI>
auto utf16le_to_utf16be (io::Writer< WI > &writer, const SliceConstU16Le &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-16 Little Endian to UTF-16 Big Endian.
 
template<WriterImpl WI>
auto utf16be_to_utf16le (io::Writer< WI > &writer, const SliceConstU16Be &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-16 Big Endian to UTF-16 Little Endian.
 
template<WriterImpl WI>
auto utf16le_to_utf16 (io::Writer< WI > &writer, const SliceConstU16Le &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-16 Little Endian to Native UTF-16.
 
template<WriterImpl WI>
auto utf16be_to_utf16 (io::Writer< WI > &writer, const SliceConstU16Be &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-16 Big Endian to Native UTF-16.
 
template<WriterImpl WI>
auto utf32_to_utf32le (io::Writer< WI > &writer, const SliceConstU32Native &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Native Endian to UTF-32 Little Endian.
 
template<WriterImpl WI>
auto utf32_to_utf32le (io::Writer< WI > &writer, const Slice< const char32_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Native Endian to UTF-32 Little Endian.
 
template<WriterImpl WI>
auto utf32_to_utf32be (io::Writer< WI > &writer, const SliceConstU32Native &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Native Endian to UTF-32 Big Endian.
 
template<WriterImpl WI>
auto utf32_to_utf32be (io::Writer< WI > &writer, const Slice< const char32_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Native Endian to UTF-32 Big Endian.
 
template<WriterImpl WI>
auto utf32le_to_utf32be (io::Writer< WI > &writer, const SliceConstU32Le &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Little Endian to UTF-32 Big Endian.
 
template<WriterImpl WI>
auto utf32be_to_utf32le (io::Writer< WI > &writer, const SliceConstU32Be &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Big Endian to UTF-32 Little Endian.
 
template<WriterImpl WI>
auto utf32le_to_utf32 (io::Writer< WI > &writer, const SliceConstU32Le &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Little Endian to UTF-32 Native Endian.
 
template<WriterImpl WI>
auto utf32be_to_utf32 (io::Writer< WI > &writer, const SliceConstU32Be &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Big Endian to UTF-32 Native Endian.
 
constexpr u16 flip_endian_u16 (const u16 bytes)
 Flips the endianness of a u16.
 
constexpr char16_t flip_endian_ch16 (const char16_t ch)
 Flips the endianness of a char16.
 
constexpr u32 flip_endian_u32 (const u32 bytes)
 Flips the endianness of a u3.
 
constexpr char32_t flip_endian_ch32 (const char32_t ch)
 Flips the endianness of a char32.
 
template<typename T>
constexpr auto flip_endian (const T bytes)
 Flips the endian of a u16, char16, u32, or char32.
 
template<typename T>
Success< T > success (const T &v)
 Creates a successful Result.
 
Success< void > success ()
 Creates a successful void Result object.
 
template<typename Underlying>
Error< Underlying > error (Underlying err)
 Creates an error.
 
constexpr Slice< char32_t > mut_slice_from (char32_t *cstr, size_t len)
 Creates a mutable slice from a utf32 string and length.
 
constexpr Slice< char32_t > mut_slice_from (char32_t *cstr)
 Creates a mutable slice from a utf32 string in the form of a c string.
 
constexpr Slice< const char32_t > slice_from (char32_t *cstr)
 Creates a slice from a utf32 string in the form of a c string.
 
constexpr Slice< const char32_t > slice_from (char32_t *cstr, size_t len)
 Creates a slice from a utf32 string and length.
 
constexpr Slice< const char32_t > slice_from (const char32_t *cstr, size_t len)
 Creates a slice from a utf32 string and length.
 
constexpr Slice< const char32_t > slice_from (const char32_t *cstr)
 Creates a slice from a utf32 string in the form of a c string.
 
constexpr Slice< char16_t > mut_slice_from (char16_t *cstr, size_t len)
 Creates a mutable slice from a utf16 string and length.
 
constexpr Slice< const char16_t > slice_from (char16_t *cstr, size_t len)
 Creates a slice from a utf16 string and length.
 
constexpr Slice< const char16_t > slice_from (const char16_t *cstr, size_t len)
 Creates a slice from a utf16 string and length.
 
constexpr Slice< char8_t > mut_slice_from (char8_t *cstr, size_t len)
 Creates a mutable slice from a utf8 string and length.
 
constexpr Slice< const char8_t > slice_from (char8_t *cstr, size_t len)
 Creates a slice from a utf8 string and length.
 
constexpr Slice< const char8_t > slice_from (const char8_t *cstr, size_t len)
 Creates a slice from a utf8 string and length.
 
constexpr Slice< char16_t > mut_slice_from (char16_t *cstr)
 Creates a mutable slice from a utf16 string in the form of a c string.
 
constexpr Slice< const char16_t > slice_from (char16_t *cstr)
 Creates a slice from a utf16 string in the form of a c string.
 
constexpr Slice< const char16_t > slice_from (const char16_t *cstr)
 Creates a slice from a utf16 string in the form of a c string.
 
constexpr Slice< char8_t > mut_slice_from (char8_t *cstr)
 Creates a mutable slice from a utf8 string in the form of a c string.
 
constexpr Slice< const char8_t > slice_from (char8_t *cstr)
 Creates a slice from a utf8 string in the form of a c string.
 
constexpr Slice< const char8_t > slice_from (const char8_t *cstr)
 Creates a slice from a utf8 string in the form of a c string.
 
constexpr Slice< const char > slice_from (char *cstr)
 Creates a slice from a string in the form of a c string.
 
constexpr Slice< const char > slice_from (const char *cstr)
 Creates a slice from a string in the form of a c string.
 
constexpr Slice< const char > slice_from (char *cstr, const size_t len)
 Creates a slice from a string with a length.
 
constexpr Slice< char > mut_slice_from (char *cstr, const size_t len)
 Creates a mutable slice from a string with a length.
 
constexpr Slice< const char > slice_from (const char *cstr, const size_t len)
 Creates a slice from a string with a length.
 
Slice< const char > slice_from (const std::string &str)
 Creates a slice from a std::string.
 
constexpr Slice< const char > slice_from (const std::string_view &sv)
 Creates a slice from a std::string_view.
 
template<typename T>
Slice< std::add_const_t< T > > slice_from (const std::vector< T > &arr)
 Creates a slice from a vector.
 
template<typename T>
Slice< T > mut_slice_from (std::vector< T > &arr)
 Creates a mutable slice from a vector.
 
template<typename T, size_t N>
constexpr Slice< std::add_const_t< T > > slice_from (const std::array< T, N > &arr)
 Creates a slice from an array.
 
template<typename T, size_t N>
constexpr Slice< T > mut_slice_from (std::array< T, N > &arr)
 Creates a mutable slice from an array.
 
Slice< char > mut_slice_from (char *cstr)
 Creates a mutable slice from a c string.
 
Slice< char > mut_slice_from (std::string &str)
 Creates a mutable slice from a string.
 
template<typename Left, typename Right>
std::strong_ordering str_compare (const Left &left, const Right &right)
 Compares two string strings for ordering.
 
template<typename L, typename R>
bool str_equal (const L &left, const R &right)
 Compares two string strings for ordering.
 
template<class... Ts>
 overload (Ts...) -> overload< Ts... >
 
Prng tinymt_init (uint64_t seed) noexcept
 Initializes a PRNG based on the TinyMT variant of Mersenne Twister.
 
Prng lcg_init (uint64_t seed) noexcept
 Initializes a Linear Congruential Generator NOTE: THIS IS NOT A GOOD PRNG (it's essentially rand())
 
Result< Prng, Mt19937_64Errormt19937_64 (Allocator *alloc, uint64_t seed) noexcept
 Initializes a Mersenne Twister 19937-64 algorithm Note: This does require allocated memory.
 

Variables

constexpr char32_t bom = 0xFEFF
 Native representation of Byte Order Mark (BOM)
 
template<std::endian target, typename T = char32_t>
constexpr T endian_bom = target == std::endian::native ? bom : flip_endian<T>(bom)
 
template<std::endian E = std::endian::native>
constexpr auto oppositeEndian = E == std::endian::big ? std::endian::little : std::endian::big
 Returns the opposite endianness of a given endian (default is opposite of the native endian)
 
constexpr auto nullopt = Nullopt{}
 Placeholder value for an empty Optional.
 
template<typename T, typename V>
constexpr bool is_result_with_value = impl::IsResultWithValue<V, T>::value
 Checks if a type is result-like with a success value type.
 
template<typename T>
constexpr bool is_write_through = impl::IsWriteThrough<T>::value
 Checks if a writer type is a write-through writer.
 
template<typename T>
constexpr bool is_result_void = impl::IsResultWithValue<void, T>::value
 Checks if a type is result-like with no success value.
 
template<typename T>
constexpr bool is_addressable = impl::IsAddressable<T>::value
 Boolean check for if something has the trait Addressable.
 
template<typename T>
constexpr bool is_mutable_addressable = impl::IsAddressable<T>::value
 Boolean check for if something has the trait Addressable.
 
template<typename T>
constexpr bool is_ostreamable = impl::IsOstreamable<T>::value
 Boolean check for if something has the trait Iterator.
 
template<typename T>
constexpr bool is_iterator = impl::IsIterator<T>::value
 Boolean check for if something has the trait Iterator.
 
template<typename T>
constexpr bool is_flushable = impl::IsFlushable<T>::value
 Boolean check for if something has the trait Flushable.
 
template<typename T>
constexpr bool is_allocator_deinit = impl::IsAllocatorDeinit<T>::value
 Checks if a type requires an allocator to deinit.
 
template<typename T, typename... Args>
constexpr bool is_initable = impl::IsInitable<T, Args...>::value
 Checks if a type has an init with the param types.
 
template<typename T>
constexpr bool is_formattable = impl::IsFormattable<T>::value
 Checks if a type has a zero-parameter deinit.
 
template<typename T>
constexpr bool is_default_deinit = impl::IsDefaultDeinit<T>::value
 Checks if a type has a zero-parameter deinit.
 

Detailed Description

Core library for C++ with Zig-related functionality.

Typedef Documentation

◆ CharSeq

using mtcore::CharSeq = impl::ShortSeq<char, 4>

Definition at line 135 of file byte_endian.hpp.

◆ Rune

using mtcore::Rune = char32_t

Definition at line 783 of file byte_endian.hpp.

◆ U16Seq

using mtcore::U16Seq = impl::ShortSeq<char16_t, 2>

Definition at line 137 of file byte_endian.hpp.

◆ U8Seq

using mtcore::U8Seq = impl::ShortSeq<char8_t, 4>

Definition at line 136 of file byte_endian.hpp.

Enumeration Type Documentation

◆ RcError

enum class mtcore::RcError
strong

Error for thread-local reference counting.

Enumerator
CANNOT_ACQUIRE 

Definition at line 83 of file rc.hpp.

83 {
85 };
@ CANNOT_ACQUIRE
Definition rc.hpp:84

Function Documentation

◆ overload()

template<class... Ts>
mtcore::overload ( Ts... ) -> overload< Ts... >

◆ str_compare()

template<typename Left, typename Right>
std::strong_ordering mtcore::str_compare ( const Left & left,
const Right & right )

Compares two string strings for ordering.

Supports slices, c strings, and std::strings Note: This only supports char (not utf8, utf16, or utf32)

Template Parameters
LeftLeft type for comparison
RightRight type for comparison
Parameters
leftLeft slice for comparison
rightRight slice for comparison
Returns
ordering of left relative to right

Definition at line 610 of file colls/slice.hpp.

610 {
611 using L = std::decay_t<std::remove_cv_t<Left>>;
612 using R = std::decay_t<std::remove_cv_t<Right>>;
613 static_assert(std::same_as<Slice<char>, L> || std::same_as<Slice<const char>, L> || std::same_as<std::string, L> ||
614 std::same_as<std::string_view, L> || std::same_as<char *, L> || std::same_as<const char *, L>);
615 static_assert(std::same_as<Slice<char>, R> || std::same_as<Slice<const char>, R> || std::same_as<std::string, R> ||
616 std::same_as<std::string_view, R> || std::same_as<char *, R> || std::same_as<const char *, R>);
617
618 Slice<const char> leftSlice;
619 if constexpr (std::is_same_v<Slice<const char>, L>) {
620 leftSlice = left;
621 }
622 else if constexpr (std::is_same_v<Slice<char>, L>) {
623 leftSlice = left.to_const();
624 }
625 else {
626 leftSlice = slice_from(left);
627 }
628
629 Slice<const char> rightSlice;
630 if constexpr (std::is_same_v<Slice<const char>, R>) {
631 rightSlice = right;
632 }
633 else if constexpr (std::is_same_v<Slice<char>, R>) {
634 rightSlice = right.to_const();
635 }
636 else {
637 rightSlice = slice_from(right);
638 }
639
640 return leftSlice <=> rightSlice;
641 }
constexpr Slice< const char32_t > slice_from(char32_t *cstr)
Creates a slice from a utf32 string in the form of a c string.
A Slice which is just a pointer + length Accessing elements through the array operator will do bounds...
constexpr Slice< std::add_const_t< T > > to_const() const noexcept
Converts to a const Slice.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ str_equal()

template<typename L, typename R>
bool mtcore::str_equal ( const L & left,
const R & right )

Compares two string strings for ordering.

Supports slices, c strings, and std::strings Note: This only supports char (not utf8, utf16, or utf32)

Template Parameters
LLeft type for comparison
RRight type for comparison
Parameters
leftLeft slice for comparison
rightRight slice for comparison
Returns
ordering of left relative to right

Definition at line 653 of file colls/slice.hpp.

653 {
654 return str_compare(left, right) == std::strong_ordering::equal;
655 }
std::strong_ordering str_compare(const Left &left, const Right &right)
Compares two string strings for ordering.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ str_to_rune()

Result< Rune, RuneConversionError > mtcore::str_to_rune ( const Slice< const char > & rune)

Characters to a Rune.

Only grabs the first rune. Use a rune iterator for all characters

◆ utf16_to_rune() [1/2]

Result< Rune, RuneConversionError > mtcore::utf16_to_rune ( const Slice< const char16_t > & rune)

UTF-16 to a Rune.

Only grabs the first rune. Use a rune iterator for all characters

◆ utf16_to_rune() [2/2]

Result< Rune, RuneConversionError > mtcore::utf16_to_rune ( const SliceConstU16Native & rune)

UTF-16 to a Rune.

Only grabs the first rune. Use a rune iterator for all characters

◆ utf8_to_rune()

Result< Rune, RuneConversionError > mtcore::utf8_to_rune ( const Slice< const char8_t > & rune)

UTF-8 to a Rune.

Only grabs the first rune. Use a rune iterator for all characters

Variable Documentation

◆ endian_bom

template<std::endian target, typename T = char32_t>
T mtcore::endian_bom = target == std::endian::native ? bom : flip_endian<T>(bom)
constexpr

Definition at line 58 of file byte_endian.hpp.

◆ is_write_through

template<typename T>
bool mtcore::is_write_through = impl::IsWriteThrough<T>::value
constexpr

Checks if a writer type is a write-through writer.

Definition at line 355 of file core/mtcore/traits.hpp.