ToyGine2 26.2.0
Game Engine for retro consoles
Loading...
Searching...
No Matches
toy Namespace Reference

Root namespace containing all engine modules. More...

Namespaces

namespace  application
 Application-level types and utilities (version, etc.).
namespace  anonymous_namespace{format_pattern.inl}
namespace  geometry
 Geometry types and utilities: sections (intervals), circles, ellipses, and related APIs.
namespace  math
 Mathematical types, constants, and utilities: fixed-point, vectors, point.
namespace  network
 Network types: endpoint, socket error, flags, statistics, type, and related APIs.
namespace  assertion
 Configurable assertion failure handling and optional stack trace.
namespace  render
 Rendering types and utilities: clear flags, pixel formats, and related APIs.
namespace  audio
 Audio types and utilities: volume categories, mixing, and related APIs.
namespace  filesystem
 Filesystem types and utilities: file open modes, paths, and related APIs.
namespace  game
 Game types and utilities: achievement state and related APIs.
namespace  platform

Classes

struct  _divmod10
class  EnableBitwiseOperators
 Primary template: disables generic bitwise operators for T unless specialized. More...
class  CStringView
 Non-owning string view class for C-style strings. More...
class  CallbacksPool
 Fixed-capacity array of function pointers for observer-style notification. More...
struct  FixedStringStorage
class  FixedString
 Template string class with fixed-size character buffer. More...
class  FixedVector
class  FormatString
 Wrapper around a toy::CStringView pattern with consteval validation of placeholders. More...
class  OStringStream
 Output stream that appends formatted values into a toy::StringLike backend. More...
class  StringFixedStorage
 Fixed-size character storage with a tracked length and implicit null terminator at data()[size()]. More...
class  array
 STL class. More...

Concepts

concept  StringLike
 Concept satisfied when T exposes size() as size_t and c_str() as a pointer to null-terminated characters.

Enumerations

enum class  FormatPatternValidationError {
  FormatPatternValidationError::none , FormatPatternValidationError::unmatchedBrace , FormatPatternValidationError::invalidContent , FormatPatternValidationError::mixedPlaceholders ,
  FormatPatternValidationError::argCountMismatch , FormatPatternValidationError::indexOutOfRange
}
 Result of validating a format pattern against an expected argument count. More...
enum class  Platform : uint16_t {
  Windows = 0x1000 , Linux = 0x2000 , macOS = 0x3000 , iOS = 0x3100 ,
  Android = 0x4000 , GBA = 0x5000 , NDS = 0x6000 , N3DS = 0x7000 ,
  Switch = 0x8000
}
 Target operating system or platform identifier. More...
enum class  CpuArchitecture : uint16_t {
  x86 = 0x0014 , x64 = 0x0018 , Arm32 = 0x0024 , Arm64 = 0x0028 ,
  Unknown = 0x0000
}
 CPU or instruction-set architecture identifier. More...

Functions

template<typename T>
constexpr T operator| (T lhs, T rhs) noexcept
 Computes bitwise OR on the underlying integers, then casts back to T.
template<typename T>
constexpr T operator& (T lhs, T rhs) noexcept
 Computes bitwise AND on the underlying integers, then casts back to T.
template<typename T>
constexpr T operator^ (T lhs, T rhs) noexcept
 Computes bitwise XOR on the underlying integers, then casts back to T.
template<typename T>
constexpr T operator~ (T lhs) noexcept
 Computes bitwise NOT of the underlying integer, then casts back to T.
template<typename T>
constexpr T & operator|= (T &lhs, T rhs) noexcept
 Compound OR: lhs becomes lhs | rhs.
template<typename T>
constexpr T & operator&= (T &lhs, T rhs) noexcept
 Compound AND: lhs becomes lhs & rhs.
template<typename T>
constexpr T & operator^= (T &lhs, T rhs) noexcept
 Compound XOR: lhs becomes lhs ^ rhs.
constexpr bool operator== (const CStringView &lhs, const CStringView &rhs)
template<StringLike stringType>
constexpr bool operator== (const CStringView &lhs, const stringType &rhs)
template<StringLike stringType>
constexpr bool operator== (const stringType &lhs, const CStringView &rhs)
constexpr bool operator== (const CStringView &lhs, const char *rhs)
constexpr bool operator== (const char *lhs, const CStringView &rhs)
constexpr strong_ordering operator<=> (const CStringView &lhs, const CStringView &rhs)
template<StringLike stringType>
constexpr strong_ordering operator<=> (const CStringView &lhs, const stringType &rhs)
template<StringLike stringType>
constexpr strong_ordering operator<=> (const stringType &lhs, const CStringView &rhs)
constexpr strong_ordering operator<=> (const CStringView &lhs, const char *rhs)
constexpr strong_ordering operator<=> (const char *lhs, const CStringView &rhs)
constexpr int cstrcmp (const char *lhs, const char *rhs) noexcept
 Compares two C strings lexicographically.
constexpr const char * cstrchr (const char *str, int ch) noexcept
 Finds the first occurrence of a character in a C string.
constexpr const char * cstrpbrk (const char *str, const char *accept) noexcept
 Finds the first occurrence of any character from a set in a C string.
constexpr const char * cstrstr (const char *haystack, const char *needle) noexcept
 Finds the first occurrence of a substring in a C string.
template<size_t allocatedSize1, size_t allocatedSize2>
constexpr FixedString< allocatedSize1 > operator+ (const FixedString< allocatedSize1 > &lhs, const FixedString< allocatedSize2 > &rhs) noexcept
 Concatenation operator for two FixedString objects.
template<size_t allocatedSize, StringLike stringType>
constexpr FixedString< allocatedSize > operator+ (const FixedString< allocatedSize > &lhs, const stringType &rhs) noexcept
 Concatenation operator for FixedString and toy::StringLike object.
template<size_t allocatedSize, StringLike stringType>
constexpr FixedString< allocatedSize > operator+ (const stringType &lhs, const FixedString< allocatedSize > &rhs) noexcept
 Concatenation operator for toy::StringLike object and FixedString.
template<size_t allocatedSize>
constexpr FixedString< allocatedSize > operator+ (const FixedString< allocatedSize > &lhs, const char *rhs) noexcept
 Concatenation operator for FixedString and C-string.
template<size_t allocatedSize>
constexpr FixedString< allocatedSize > operator+ (const char *lhs, const FixedString< allocatedSize > &rhs) noexcept
 Concatenation operator for C-string and FixedString.
template<size_t allocatedSize>
constexpr FixedString< allocatedSize > operator+ (const FixedString< allocatedSize > &lhs, char rhs) noexcept
 Concatenation operator for FixedString and character.
template<size_t allocatedSize>
constexpr FixedString< allocatedSize > operator+ (char lhs, const FixedString< allocatedSize > &rhs) noexcept
 Concatenation operator for character and FixedString.
template<size_t allocatedSize1, size_t allocatedSize2>
constexpr bool operator== (const FixedString< allocatedSize1 > &lhs, const FixedString< allocatedSize2 > &rhs) noexcept
 Equality comparison operator for two FixedString objects.
template<size_t allocatedSize, StringLike stringType>
constexpr bool operator== (const FixedString< allocatedSize > &lhs, const stringType &rhs) noexcept
 Equality comparison operator for FixedString and toy::StringLike object.
template<size_t allocatedSize, StringLike stringType>
constexpr bool operator== (const stringType &lhs, const FixedString< allocatedSize > &rhs) noexcept
 Equality comparison operator for toy::StringLike object and FixedString.
template<size_t allocatedSize>
constexpr bool operator== (const FixedString< allocatedSize > &lhs, const char *rhs) noexcept
 Equality comparison operator for FixedString and C string.
template<size_t allocatedSize>
constexpr bool operator== (const char *lhs, const FixedString< allocatedSize > &rhs) noexcept
 Equality comparison operator for C string and FixedString.
template<size_t allocatedSize1, size_t allocatedSize2>
constexpr strong_ordering operator<=> (const FixedString< allocatedSize1 > &lhs, const FixedString< allocatedSize2 > &rhs) noexcept
 Three-way comparison operator for FixedString objects.
template<size_t allocatedSize, StringLike stringType>
constexpr strong_ordering operator<=> (const FixedString< allocatedSize > &lhs, const stringType &rhs) noexcept
 Three-way comparison operator for FixedString and toy::StringLike object.
template<size_t allocatedSize, StringLike stringType>
constexpr strong_ordering operator<=> (const stringType &lhs, const FixedString< allocatedSize > &rhs) noexcept
 Three-way comparison operator for toy::StringLike object and FixedString.
template<size_t allocatedSize>
constexpr strong_ordering operator<=> (const FixedString< allocatedSize > &lhs, const char *rhs) noexcept
 Three-way comparison operator for FixedString and C string.
template<size_t allocatedSize>
constexpr strong_ordering operator<=> (const char *lhs, const FixedString< allocatedSize > &rhs) noexcept
 Three-way comparison operator for C string and FixedString.
constexpr FormatPatternValidationError validateFormatPattern (const CStringView &string, size_t argCount) noexcept
 Validates auto-indexed {} and positional {N} placeholders for argCount arguments.
constexpr wchar_t * utf8toWChar (wchar_t *dest, size_t destSize, const char *src) noexcept
 Converts a UTF-8 C string to a wide-character string (full source length).
template<StringLike T>
constexpr wchar_t * utf8toWChar (wchar_t *dest, size_t destSize, const T &src) noexcept
 Converts a UTF-8 toy::StringLike object to a wide-character string.
constexpr char * reverseString (char *str, size_t count=0) noexcept
 Reverses a C string in-place.
template<std::signed_integral T>
constexpr char * itoa (char *dest, size_t destSize, T value) noexcept
 Converts a signed integer to its decimal C string representation.
template<std::unsigned_integral T>
constexpr char * utoa (char *dest, size_t destSize, T value, unsigned base=10) noexcept
 Converts an unsigned integer to its C string representation in the given base.
size_t highestBit (uint64_t value) noexcept
 Returns the 0-based index of the highest set bit in value.
uint8_t crc8 (const void *src, size_t size, uint8_t crc=0x00) noexcept
 Computes Dallas/Maxim CRC-8 (polynomial 0x31, reflected 8-bit CRC).
uint16_t crc16 (const void *src, size_t size, uint16_t crc=0x0000) noexcept
 Computes CRC-16-IBM / ARC (polynomial 0x8005, reflected).
uint32_t crc32 (const void *src, size_t size, uint32_t crc=0x00000000) noexcept
 Computes CRC-32 per IEEE 802.3 / Ethernet (polynomial 0x04C11DB7, reflected).
constexpr _divmod10 _divModU10 (uint32_t value) noexcept
 Divides a given 32-bit unsigned integer by 10 and returns the quotient and remainder.
constexpr int32_t _ftoa32Engine (char *buffer, float value, size_t precision) noexcept
 Converts a floating-point number to its string representation in a specified precision.
constexpr int32_t _ftoa64Engine (char *buffer, double value, size_t precision) noexcept
 Converts a 64-bit floating-point number to its string representation with specified precision.
void _floatPostProcess (char *dest, char *srcBuffer, size_t bufferSize, int32_t exp10, size_t precision) noexcept
 Processes a string representation of a floating-point number, adjusting the exponent, and stripping trailing zeros.
wchar_t * utf8toWChar (wchar_t *dest, size_t destSize, const char *src, size_t count) noexcept
 Converts a UTF-8 C string to a wide-character string with a character count limit.
char * wcharToUtf8 (char *dest, size_t destSize, const wchar_t *src) noexcept
 Converts a wide-character C string to UTF-8.
size_t utf8Len (const char *string) noexcept
 Returns the number of Unicode code points in a UTF-8 encoded C string.
char * ftoa (char *dest, size_t destSize, float value, size_t precision=7) noexcept
 Converts a float to its decimal C string representation with specified precision.
char * ftoa (char *dest, size_t destSize, double value, size_t precision=15) noexcept
 Converts a double to its decimal C string representation with specified precision.
void formatNumberString (char *buffer, size_t bufferSize, const char *separator) noexcept
 Inserts a grouping separator into a number C string every three digits from the right.

Variables

static constexpr array< uint8_t, 256 > _crc8Table
 CRC-8 lookup table using Dallas/Maxim polynomial (0x31).
static constexpr array< uint16_t, 256 > _crc16Table
 CRC-16 lookup table using IBM/ARC polynomial (0x8005).
static constexpr array< uint32_t, 256 > _crc32Table
 CRC-32 lookup table using IEEE 802.3 polynomial (0x04C11DB7).
static constexpr array< uint8_t, 256 > _utf8CharSizeTable
 UTF-8 character size lookup table for efficient UTF-8 parsing.
constexpr array< uint32_t, 32 > _exponentTable
 Precomputed exponent lookup table for efficient binary-to-decimal floating-point conversion.
constexpr size_t _decimalDigitsPerGroup = 3
 Number of decimal digits per group when formatNumberString() inserts the caller-supplied separator.
constexpr size_t WCHAR_IN_UTF8_MAX_SIZE = 3
 Maximum UTF-8 byte length for one BMP character.

Detailed Description

Root namespace containing all engine modules.

Enumeration Type Documentation

◆ CpuArchitecture

enum class toy::CpuArchitecture : uint16_t
strong

CPU or instruction-set architecture identifier.

Hex values in distinct ranges (Intel 0x0014-0x0018, ARM 0x0024-0x0028) allow compile-time checks and combination with toy::Platform for platform-and-architecture conditional code.

Key Features

  • Constexpr: All values usable in constexpr contexts.
  • Compile-time detection: Enables if constexpr conditional compilation.
  • Type safety: Enum class prevents implicit conversion.
  • Combination: Hex layout combines with toy::Platform identifiers.

Usage Example

#include "core.hpp"
constexpr CpuArchitecture currentArch = CpuArchitecture::x64;
if constexpr (currentArch == CpuArchitecture::x64) {
// x64-specific code
}
const CpuArchitecture runtimeArch = getCurrentArchitecture();
if constexpr (currentPlatform == Platform::macOS && currentArch == CpuArchitecture::Arm64) {
// Apple Silicon
}
Umbrella header for the engine core module.
CpuArchitecture
CPU or instruction-set architecture identifier.
Definition platform.hpp:129
@ x64
Intel x64 64-bit instruction set architecture (x86-64, AMD64).
Definition platform.hpp:134
@ Arm64
ARM 64-bit instruction set architecture (ARMv8-A AArch64, ARM64).
Definition platform.hpp:140
@ macOS
Apple macOS desktop operating system.
Definition platform.hpp:75
Note
Architecture values can be combined with platform values for combined identification.
See also
Platform, getCurrentArchitecture()
Enumerator
x86 

Intel x86 32-bit instruction set architecture (IA-32).

x64 

Intel x64 64-bit instruction set architecture (x86-64, AMD64).

Arm32 

ARM 32-bit instruction set architecture (ARMv7, ARMv8-A AArch32).

Arm64 

ARM 64-bit instruction set architecture (ARMv8-A AArch64, ARM64).

Unknown 

Unspecified or unknown architecture.

◆ Platform

enum class toy::Platform : uint16_t
strong

Target operating system or platform identifier.

Hex values in distinct ranges (desktop 0x1000-0x3000, mobile 0x3100-0x4000, consoles 0x5000-0x8000) allow compile-time if constexpr and combination with toy::CpuArchitecture.

Key Features

  • Constexpr: All values usable in constexpr contexts.
  • Compile-time detection: Enables if constexpr conditional compilation.
  • Type safety: Enum class prevents implicit conversion.
  • Combination: Hex layout allows combining with toy::CpuArchitecture.

Usage Example

#include "core.hpp"
constexpr Platform currentPlatform = Platform::macOS;
if constexpr (currentPlatform == Platform::macOS) {
// macOS-specific code
}
const Platform runtimePlatform = getCurrentPlatform();
if (runtimePlatform == Platform::Linux) { // Linux-specific logic
}
Platform
Target operating system or platform identifier.
Definition platform.hpp:67
@ Linux
GNU/Linux operating system and Linux-based distributions.
Definition platform.hpp:72
Note
iOS (0x3100) shares the Apple range with macOS (0x3000).
See also
CpuArchitecture, getCurrentPlatform()
Enumerator
Windows 

Microsoft Windows Desktop operating system (Windows XP, Vista, 7, 8, 8.1, 10, 11, etc.).

Linux 

GNU/Linux operating system and Linux-based distributions.

macOS 

Apple macOS desktop operating system.

iOS 

Apple iOS mobile operating system.

Android 

Google Android mobile operating system.

GBA 

Nintendo Game Boy Advance handheld gaming console.

NDS 

Nintendo DS dual-screen handheld gaming console.

N3DS 

Nintendo 3DS handheld gaming console with stereoscopic 3D display.

Switch 

Nintendo Switch hybrid gaming console.

Function Documentation

◆ _divModU10()

_divmod10 toy::_divModU10 ( uint32_t value)
constexprnoexcept

Divides a given 32-bit unsigned integer by 10 and returns the quotient and remainder.

The function approximates division by 10 using a sequence of shift-and-add operations to compute the quotient, then derives the remainder and corrects it if needed. It returns both quotient and remainder.

Parameters
valueThe 32-bit unsigned integer to divide by 10.
Returns
A struct containing the quotient and remainder of the division.

◆ _floatPostProcess()

void toy::_floatPostProcess ( char * dest,
char * srcBuffer,
size_t bufferSize,
int32_t exp10,
size_t precision )
noexcept

Processes a string representation of a floating-point number, adjusting the exponent, and stripping trailing zeros.

This function processes a string representation of a floating-point number, adjusting the exponent according to the given precision, and stripping trailing zeros. The function also handles the case of negative zero.

Parameters
destThe destination buffer where the processed string is stored.
srcBufferThe source buffer containing the string representation of a floating-point number.
bufferSizeThe size of the source buffer.
exp10The exponent of the floating-point number in the given precision.
precisionThe number of decimal places to include in the representation.
Note
The function assumes that the destination buffer is large enough to hold the processed string. The buffer will contain the string representation in the form "+d.dd...e±dd" for normalized numbers.

◆ _ftoa32Engine()

int32_t toy::_ftoa32Engine ( char * buffer,
float value,
size_t precision )
constexprnoexcept

Converts a floating-point number to its string representation in a specified precision.

The output is always sign-prefixed ('+' or '-') and normalized as "+0.<digits>" or "-0.<digits>".

This function converts a given floating-point number into its string representation, storing the result in the provided destination buffer. The function rounds the result to the given precision and stores the exponent in the return value.

Parameters
valueThe floating-point number to be converted.
bufferThe destination buffer where the converted string is stored.
precisionThe precision (digits after the decimal point). For IEEE-754 f32, practical precision is ~7–9 digits.
Returns
The exponent of the converted number in the given precision. Returns 0xFF for zero, subnormals (unsupported), NaN, and INF.
Note
The function assumes that the destination buffer is large enough to hold the converted string. The function does not support subnormals.

◆ _ftoa64Engine()

int32_t toy::_ftoa64Engine ( char * buffer,
double value,
size_t precision )
constexprnoexcept

Converts a 64-bit floating-point number to its string representation with specified precision.

The output is always sign-prefixed ('+' or '-') and normalized as "+0.<digits>" or "-0.<digits>".

This function converts a given 64-bit floating-point number into its string representation, storing the result in the provided buffer. The conversion includes handling special cases such as subnormals, NaN, and infinity. The output is formatted according to the specified precision.

Parameters
bufferThe destination buffer where the converted string is stored.
valueThe 64-bit floating-point number to be converted.
precisionThe number of decimal places to include in the representation.
Returns
The exponent of the converted number in the given precision. Returns 0x7FF for zero, subnormals (unsupported), NaN, and INF.
Note
The function assumes that the buffer is large enough to hold the converted string. The buffer will contain the string representation in the form "+d.dd...e±dd" for normalized numbers.

◆ crc16()

uint16_t toy::crc16 ( const void * src,
size_t size,
uint16_t crc = 0x0000 )
nodiscardnoexcept

Computes CRC-16-IBM / ARC (polynomial 0x8005, reflected).

Processes bytes from low to high address. The crc argument carries state for chained updates: first chunk uses the default initial value, subsequent chunks pass the previous result as crc.

Parameters
srcPointer to the first byte; must not be null (asserted in debug).
sizeByte length of the range.
crcRunning CRC; default initial value 0x0000.
Returns
Updated CRC-16 value.
Precondition
src is not null. size is the length of readable memory at src.
Note
If size is 0, the return value equals the initial crc argument (no input bytes).
Polynomial is CRC-16-IBM / ARC; confirm against Modbus, ARC, or other specs that name this variant.

◆ crc32()

uint32_t toy::crc32 ( const void * src,
size_t size,
uint32_t crc = 0x00000000 )
nodiscardnoexcept

Computes CRC-32 per IEEE 802.3 / Ethernet (polynomial 0x04C11DB7, reflected).

Processes bytes from low to high address. The crc argument carries state for chained updates: first chunk uses the default initial value, subsequent chunks pass the previous result as crc.

Parameters
srcPointer to the first byte; must not be null (asserted in debug).
sizeByte length of the range.
crcRunning CRC; default initial value 0x00000000.
Returns
Updated CRC-32 value.
Precondition
src is not null. size is the length of readable memory at src.
Note
If size is 0, the return value equals the initial crc argument (no input bytes).
Result matches common IEEE 802.3 / Ethernet / PKZIP polynomial; parameterization (init, xorout) may differ by protocol—use known test vectors for integration.

◆ crc8()

uint8_t toy::crc8 ( const void * src,
size_t size,
uint8_t crc = 0x00 )
nodiscardnoexcept

Computes Dallas/Maxim CRC-8 (polynomial 0x31, reflected 8-bit CRC).

Processes bytes from low to high address. The crc argument carries state for chained updates: first chunk uses the default initial value, subsequent chunks pass the previous result as crc.

Parameters
srcPointer to the first byte; must not be null (asserted in debug).
sizeByte length of the range.
crcRunning CRC; default initial value 0x00.
Returns
Updated CRC-8 value.
Precondition
src is not null. size is the length of readable memory at src.
Note
If size is 0, the return value equals the initial crc argument (no input bytes).
Polynomial matches Dallas/Maxim style CRC-8 (0x31 reflected); compare vectors with your protocol’s CRC catalogue entry.

◆ cstrchr()

const char * toy::cstrchr ( const char * str,
int ch )
nodiscardconstexprnoexcept

Finds the first occurrence of a character in a C string.

This function searches for the first occurrence of the character ch within the string str. The search is performed character by character from the beginning of the string and returns a pointer to the first occurrence, or nullptr if the character is not found. This function is designed to be constexpr-compatible and provides the same behavior as std::strchr but can be evaluated at compile time.

Parameters
strThe C string to search in.
chThe character to search for.
Returns
A pointer to the first occurrence of ch in str, or nullptr if not found.
Precondition
The str pointer must not be null.
Note
The search is case-sensitive.
The function searches from the beginning of str and returns the first match.
This function is constexpr-compatible and can be used in compile-time contexts.
See also
std::strchr

◆ cstrcmp()

int toy::cstrcmp ( const char * lhs,
const char * rhs )
nodiscardconstexprnoexcept

Compares two C strings lexicographically.

This function performs a lexicographic comparison between two C strings. The comparison is performed character by character using the character's numeric value. This function is designed to be constexpr-compatible and provides the same behavior as std::strcmp but can be evaluated at compile time.

Parameters
lhsThe left-hand side C string to compare.
rhsThe right-hand side C string to compare.
Returns
A negative value if lhs is lexicographically less than rhs, zero if they are equal, or a positive value if lhs is lexicographically greater than rhs.
Precondition
The lhs pointer must not be null.
The rhs pointer must not be null.
Note
The comparison is case-sensitive.
The comparison stops at the first character that differs between the strings.
If one string is a prefix of another, the shorter string is considered lexicographically smaller.
Return values are -1, 0, or 1 (differs from std::strcmp which returns arithmetic difference).
This function is constexpr-compatible and can be used in compile-time contexts.
See also
std::strcmp

◆ cstrpbrk()

const char * toy::cstrpbrk ( const char * str,
const char * accept )
nodiscardconstexprnoexcept

Finds the first occurrence of any character from a set in a C string.

This function searches for the first occurrence of any character from the accept string within the str string. The search is performed character by character from the beginning and returns a pointer to the first character found that matches any character in the accept set, or nullptr if no character from the accept set is found. This function is designed to be constexpr-compatible and provides the same behavior as std::strpbrk but can be evaluated at compile time.

Parameters
strThe C string to search in.
acceptThe C string containing the set of characters to search for.
Returns
A pointer to the first character in str that matches any character in accept, or nullptr if no character from the accept set is found.
Precondition
The str pointer must not be null.
The accept pointer must not be null.
The str must be C string.
The accept must be C string.
Note
The search is case-sensitive.
The function searches from the beginning of str and returns the first match.
This function is constexpr-compatible and can be used in compile-time contexts.
See also
std::strpbrk

◆ cstrstr()

const char * toy::cstrstr ( const char * haystack,
const char * needle )
nodiscardconstexprnoexcept

Finds the first occurrence of a substring in a C string.

This function searches for the first occurrence of the needle string within the haystack string. The search is performed character by character from the beginning and returns a pointer to the beginning of the first occurrence, or nullptr if the substring is not found. This function is designed to be constexpr-compatible and provides the same behavior as std::strstr but can be evaluated at compile time.

Parameters
haystackThe C string to search in.
needleThe C string to search for.
Returns
A pointer to the first occurrence of needle in haystack, or nullptr if not found. If needle is an empty string, returns haystack.
Precondition
The haystack pointer must not be null.
The needle pointer must not be null.
Note
The search is case-sensitive.
If needle is an empty string, the function returns haystack immediately.
The function searches from the beginning of haystack and returns the first match.
This function is constexpr-compatible and can be used in compile-time contexts.
See also
std::strstr

◆ formatNumberString()

void toy::formatNumberString ( char * buffer,
size_t bufferSize,
const char * separator )
noexcept

Inserts a grouping separator into a number C string every three digits from the right.

Modifies buffer in-place. Typically used to improve readability of large numbers (e.g. "1,234,567"). Does not validate that the buffer content is purely numeric.

Parameters
bufferDestination buffer for the formatted C string.
bufferSizeSize of buffer in characters.
separatorC string used as grouping separator (e.g. ",", " ", ".").
Precondition
buffer is not null; bufferSize > 0; separator is not null; length of separator is at most 8 (asserted in debug).

◆ ftoa() [1/2]

char * toy::ftoa ( char * dest,
size_t destSize,
double value,
size_t precision = 15 )
noexcept

Converts a double to its decimal C string representation with specified precision.

Writes the decimal representation of value into dest, null-terminated. Handles infinity and NaN; subnormals are not supported. Practical precision limit is about 15–17 fractional digits for double.

Parameters
destDestination buffer for the result.
destSizeSize of dest in characters.
valueThe double value to convert.
precisionNumber of digits after the decimal point (default 15).
Returns
Pointer to dest.
Precondition
dest is not null; destSize is sufficient for the output (including sign, digits, decimal point, and terminator).

◆ ftoa() [2/2]

char * toy::ftoa ( char * dest,
size_t destSize,
float value,
size_t precision = 7 )
noexcept

Converts a float to its decimal C string representation with specified precision.

Writes the decimal representation of value into dest, null-terminated. Handles infinity and NaN; subnormals are not supported. Practical precision limit is about 7–9 fractional digits for float.

Parameters
destDestination buffer for the result.
destSizeSize of dest in characters.
valueThe float value to convert.
precisionNumber of digits after the decimal point (default 7).
Returns
Pointer to dest.
Precondition
dest is not null; destSize is sufficient for the output (including sign, digits, decimal point, and terminator).

◆ highestBit()

size_t toy::highestBit ( uint64_t value)
inlinenodiscardnoexcept

Returns the 0-based index of the highest set bit in value.

Intended for log2-style queries and bit-scan operations. Implementation uses platform intrinsics where available.

Parameters
valueNon-zero 64-bit unsigned value.
Returns
Index of the highest set bit in the range [0, 63] (bit 0 is the least significant).
Precondition
value is non-zero (asserted in debug).

◆ itoa()

template<std::signed_integral T>
char * toy::itoa ( char * dest,
size_t destSize,
T value )
constexprnoexcept

Converts a signed integer to its decimal C string representation.

Writes the decimal representation of value into dest, null-terminated. Negative values are prefixed with a minus sign.

Template Parameters
TSigned integer type; must satisfy std::signed_integral (e.g. int8_t, int32_t, int64_t).
Parameters
destDestination buffer for the result.
destSizeSize of dest in characters.
valueValue to convert.
Returns
Pointer to dest.
Precondition
dest is not null and destSize is sufficient (e.g. at least 5 for int8_t, 22 for int64_t worst case).

◆ operator&()

template<typename T>
T toy::operator& ( T lhs,
T rhs )
nodiscardconstexprnoexcept

Computes bitwise AND on the underlying integers, then casts back to T.

Template Parameters
TScoped enum for which toy::EnableBitwiseOperators is specialized with enable == true.
Parameters
lhsFirst operand.
rhsSecond operand.
Returns
static_cast<T>(std::to_underlying(lhs) & std::to_underlying(rhs)).

◆ operator&=()

template<typename T>
T & toy::operator&= ( T & lhs,
T rhs )
constexprnoexcept

Compound AND: lhs becomes lhs & rhs.

Template Parameters
TScoped enum for which toy::EnableBitwiseOperators is specialized with enable == true.
Parameters
lhsReference to the left-hand value (updated).
rhsRight-hand operand.
Returns
Reference to lhs.

◆ operator+() [1/7]

template<size_t allocatedSize>
FixedString< allocatedSize > toy::operator+ ( char lhs,
const FixedString< allocatedSize > & rhs )
nodiscardconstexprnoexcept

Concatenation operator for character and FixedString.

This operator creates a new FixedString object by concatenating a single character with a FixedString. The result will contain the character from the left-hand side followed by the characters from the right-hand side.

Parameters
lhsThe character to prepend to the FixedString.
rhsThe right-hand side FixedString object.
Returns
A new FixedString object containing the concatenated result.
Note
Result size is sum of both input sizes, must not exceed allocated size.

◆ operator+() [2/7]

template<size_t allocatedSize>
FixedString< allocatedSize > toy::operator+ ( const char * lhs,
const FixedString< allocatedSize > & rhs )
nodiscardconstexprnoexcept

Concatenation operator for C-string and FixedString.

This operator creates a new FixedString object by concatenating a C-string with a FixedString. The result will contain the characters from the left-hand side followed by the characters from the right-hand side.

Template Parameters
allocatedSizeThe size of the FixedString's internal buffer.
Parameters
lhsThe left-hand side C-string.
rhsThe right-hand side FixedString object.
Precondition
The lhs C-string must not be null.
Returns
A new FixedString object containing the concatenated result.
Note
Result size is sum of both input sizes, must not exceed allocated size.

◆ operator+() [3/7]

template<size_t allocatedSize>
FixedString< allocatedSize > toy::operator+ ( const FixedString< allocatedSize > & lhs,
char rhs )
nodiscardconstexprnoexcept

Concatenation operator for FixedString and character.

This operator creates a new FixedString object by concatenating a FixedString with a single character. The result will contain the characters from the left-hand side followed by the character from the right-hand side.

Parameters
lhsThe left-hand side FixedString object.
rhsThe right-hand side character.
Returns
A new FixedString object containing the concatenated result.
Note
Result size is sum of both input sizes, must not exceed allocated size.

◆ operator+() [4/7]

template<size_t allocatedSize>
FixedString< allocatedSize > toy::operator+ ( const FixedString< allocatedSize > & lhs,
const char * rhs )
nodiscardconstexprnoexcept

Concatenation operator for FixedString and C-string.

This operator creates a new FixedString object by concatenating a FixedString with a C-string. The result will contain the characters from the left-hand side followed by the characters from the right-hand side.

Template Parameters
allocatedSizeThe size of the FixedString's internal buffer.
Parameters
lhsThe left-hand side FixedString object.
rhsThe right-hand side C-string.
Returns
A new FixedString object containing the concatenated result.
Precondition
The rhs C-string must not be null.
Note
Result size is sum of both input sizes, must not exceed allocated size.

◆ operator+() [5/7]

template<size_t allocatedSize, StringLike stringType>
FixedString< allocatedSize > toy::operator+ ( const FixedString< allocatedSize > & lhs,
const stringType & rhs )
nodiscardconstexprnoexcept

Concatenation operator for FixedString and toy::StringLike object.

This operator creates a new FixedString object by concatenating a FixedString with any toy::StringLike object. The result will contain the characters from the left-hand side followed by the characters from the right-hand side.

Template Parameters
allocatedSizeThe size of the FixedString's internal buffer.
stringTypeThe type of the toy::StringLike object. Must satisfy the toy::StringLike concept.
Parameters
lhsThe left-hand side FixedString object.
rhsThe right-hand side toy::StringLike object.
Returns
A new FixedString object containing the concatenated result.
Note
Result size is sum of both input sizes, must not exceed allocated size.

◆ operator+() [6/7]

template<size_t allocatedSize1, size_t allocatedSize2>
FixedString< allocatedSize1 > toy::operator+ ( const FixedString< allocatedSize1 > & lhs,
const FixedString< allocatedSize2 > & rhs )
nodiscardconstexprnoexcept

Concatenation operator for two FixedString objects.

This operator creates a new FixedString object by concatenating the contents of two FixedString objects. The result will contain the characters from the left-hand side followed by the characters from the right-hand side.

Template Parameters
allocatedSize1The size of the first FixedString's internal buffer.
allocatedSize2The size of the second FixedString's internal buffer.
Parameters
lhsThe left-hand side FixedString object.
rhsThe right-hand side FixedString object.
Returns
A new FixedString object containing the concatenated result.
Note
Result size is sum of both input sizes, must not exceed allocated size.

◆ operator+() [7/7]

template<size_t allocatedSize, StringLike stringType>
FixedString< allocatedSize > toy::operator+ ( const stringType & lhs,
const FixedString< allocatedSize > & rhs )
nodiscardconstexprnoexcept

Concatenation operator for toy::StringLike object and FixedString.

This operator creates a new FixedString object by concatenating any toy::StringLike object with a FixedString. The result will contain the characters from the left-hand side followed by the characters from the right-hand side.

Template Parameters
stringTypeThe type of the toy::StringLike object. Must satisfy the toy::StringLike concept.
allocatedSizeThe size of the FixedString's internal buffer.
Parameters
lhsThe left-hand side toy::StringLike object.
rhsThe right-hand side FixedString object.
Returns
A new FixedString object containing the concatenated result.
Note
Result size is sum of both input sizes, must not exceed allocated size.

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

strong_ordering toy::operator<=> ( const char * lhs,
const CStringView & rhs )
constexprnoexcept

This operator provides a three-way comparison between a C string and a CStringView object. It returns a strong_ordering value that indicates the relationship between the strings.

Parameters
lhsThe C string to compare.
rhsThe CStringView object to compare.
Returns
strong_ordering::less if lhs is lexicographically less than rhs, strong_ordering::equal if they are equal, or strong_ordering::greater if lhs is lexicographically greater than rhs.
Precondition
The lhs pointer must not be null.
Note
The comparison is case-sensitive.
The comparison is performed lexicographically character by character.
Empty strings are considered equal.
See also
operator==(const char *, const CStringView &)

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

template<size_t allocatedSize>
strong_ordering toy::operator<=> ( const char * lhs,
const FixedString< allocatedSize > & rhs )
nodiscardconstexprnoexcept

Three-way comparison operator for C string and FixedString.

This operator provides a three-way comparison between a C string and a FixedString object. It returns a strong_ordering value that indicates the relationship between the strings.

Template Parameters
allocatedSizeThe size of the FixedString's internal buffer.
Parameters
lhsThe C string to compare.
rhsThe FixedString object to compare.
Returns
strong_ordering::less if lhs is lexicographically less than rhs, strong_ordering::equal if they are equal, or strong_ordering::greater if lhs is lexicographically greater than rhs.
Precondition
The lhs pointer must not be null.
Note
The comparison is case-sensitive.
The comparison is performed lexicographically character by character.
Empty strings are considered equal.
See also
operator==(const char *, const FixedString<allocatedSize> &)

◆ operator<=>() [3/10]

strong_ordering toy::operator<=> ( const CStringView & lhs,
const char * rhs )
constexprnoexcept

This operator provides a three-way comparison between a CStringView object and a C string. It returns a strong_ordering value that indicates the relationship between the strings.

Parameters
lhsThe CStringView object to compare.
rhsThe C string to compare.
Returns
strong_ordering::less if lhs is lexicographically less than rhs, strong_ordering::equal if they are equal, or strong_ordering::greater if lhs is lexicographically greater than rhs.
Precondition
The rhs pointer must not be null.
Note
The comparison is case-sensitive.
The comparison is performed lexicographically character by character.
Empty strings are considered equal.
See also
operator==(const CStringView &, const char *)

◆ operator<=>() [4/10]

strong_ordering toy::operator<=> ( const CStringView & lhs,
const CStringView & rhs )
constexprnoexcept

This operator provides a three-way comparison between two CStringView objects. It returns a strong_ordering value that indicates the relationship between the string views.

Parameters
lhsThe left-hand side CStringView object to compare.
rhsThe right-hand side CStringView object to compare.
Returns
strong_ordering::less if lhs is lexicographically less than rhs, strong_ordering::equal if they are equal, or strong_ordering::greater if lhs is lexicographically greater than rhs.
Note
The comparison is case-sensitive.
The comparison is performed lexicographically character by character.
Empty string views are considered equal.
See also
operator==(const CStringView &, const CStringView &)

◆ operator<=>() [5/10]

template<StringLike stringType>
strong_ordering toy::operator<=> ( const CStringView & lhs,
const stringType & rhs )
constexprnoexcept

This operator provides a three-way comparison between a CStringView object and a toy::StringLike object. It returns a strong_ordering value that indicates the relationship between the strings.

Template Parameters
stringTypeThe type of the toy::StringLike object. Must satisfy the toy::StringLike concept.
Parameters
lhsThe CStringView object to compare.
rhsThe toy::StringLike object to compare.
Returns
strong_ordering::less if lhs is lexicographically less than rhs, strong_ordering::equal if they are equal, or strong_ordering::greater if lhs is lexicographically greater than rhs.
Note
The comparison is case-sensitive.
The comparison is performed lexicographically character by character.
Empty strings are considered equal.
See also
operator==(const CStringView &, const stringType &)

◆ operator<=>() [6/10]

template<size_t allocatedSize>
strong_ordering toy::operator<=> ( const FixedString< allocatedSize > & lhs,
const char * rhs )
nodiscardconstexprnoexcept

Three-way comparison operator for FixedString and C string.

This operator provides a three-way comparison between a FixedString object and a C string. It returns a strong_ordering value that indicates the relationship between the strings.

Template Parameters
allocatedSizeThe size of the FixedString's internal buffer.
Parameters
lhsThe FixedString object to compare.
rhsThe C string to compare.
Returns
strong_ordering::less if lhs is lexicographically less than rhs, strong_ordering::equal if they are equal, or strong_ordering::greater if lhs is lexicographically greater than rhs.
Precondition
The rhs pointer must not be null.
Note
The comparison is case-sensitive.
The comparison is performed lexicographically character by character.
Empty strings are considered equal.
See also
operator==(const FixedString<allocatedSize> &, const char *)

◆ operator<=>() [7/10]

template<size_t allocatedSize, StringLike stringType>
strong_ordering toy::operator<=> ( const FixedString< allocatedSize > & lhs,
const stringType & rhs )
nodiscardconstexprnoexcept

Three-way comparison operator for FixedString and toy::StringLike object.

This operator provides a three-way comparison between a FixedString object and a toy::StringLike object. It returns a strong_ordering value that indicates the relationship between the strings.

Template Parameters
allocatedSizeThe size of the FixedString's internal buffer.
stringTypeThe type of the toy::StringLike object. Must satisfy the toy::StringLike concept.
Parameters
lhsThe FixedString object to compare.
rhsThe toy::StringLike object to compare.
Returns
strong_ordering::less if lhs is lexicographically less than rhs, strong_ordering::equal if they are equal, or strong_ordering::greater if lhs is lexicographically greater than rhs.
Note
The comparison is case-sensitive.
The comparison is performed lexicographically character by character.
Empty strings are considered equal.
See also
operator==(const FixedString<allocatedSize> &, const stringType &)

◆ operator<=>() [8/10]

template<size_t allocatedSize1, size_t allocatedSize2>
strong_ordering toy::operator<=> ( const FixedString< allocatedSize1 > & lhs,
const FixedString< allocatedSize2 > & rhs )
nodiscardconstexprnoexcept

Three-way comparison operator for FixedString objects.

This operator provides a three-way comparison between two FixedString objects. It returns a strong_ordering value that indicates the relationship between the strings.

Template Parameters
allocatedSize1The size of the first FixedString's internal buffer.
allocatedSize2The size of the second FixedString's internal buffer.
Parameters
lhsThe left-hand side FixedString object to compare.
rhsThe right-hand side FixedString object to compare.
Returns
strong_ordering::less if lhs is lexicographically less than rhs, strong_ordering::equal if they are equal, or strong_ordering::greater if lhs is lexicographically greater than rhs.
Note
The comparison is case-sensitive.
The comparison is performed lexicographically character by character.
Empty strings are considered equal.
See also
operator==(const FixedString<allocatedSize1> &, const FixedString<allocatedSize2> &)

◆ operator<=>() [9/10]

template<StringLike stringType>
strong_ordering toy::operator<=> ( const stringType & lhs,
const CStringView & rhs )
constexprnoexcept

This operator provides a three-way comparison between a toy::StringLike object and a CStringView object. It returns a strong_ordering value that indicates the relationship between the strings.

Template Parameters
stringTypeThe type of the toy::StringLike object. Must satisfy the toy::StringLike concept.
Parameters
lhsThe toy::StringLike object to compare.
rhsThe CStringView object to compare.
Returns
strong_ordering::less if lhs is lexicographically less than rhs, strong_ordering::equal if they are equal, or strong_ordering::greater if lhs is lexicographically greater than rhs.
Note
The comparison is case-sensitive.
The comparison is performed lexicographically character by character.
Empty strings are considered equal.
See also
operator==(const stringType &, const CStringView &)

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

template<size_t allocatedSize, StringLike stringType>
strong_ordering toy::operator<=> ( const stringType & lhs,
const FixedString< allocatedSize > & rhs )
nodiscardconstexprnoexcept

Three-way comparison operator for toy::StringLike object and FixedString.

This operator provides a three-way comparison between a toy::StringLike object and a FixedString object. It returns a strong_ordering value that indicates the relationship between the strings.

Template Parameters
stringTypeThe type of the toy::StringLike object. Must satisfy the toy::StringLike concept.
allocatedSizeThe size of the FixedString's internal buffer.
Parameters
lhsThe toy::StringLike object to compare.
rhsThe FixedString object to compare.
Returns
strong_ordering::less if lhs is lexicographically less than rhs, strong_ordering::equal if they are equal, or strong_ordering::greater if lhs is lexicographically greater than rhs.
Note
The comparison is case-sensitive.
The comparison is performed lexicographically character by character.
Empty strings are considered equal.
See also
operator==(const stringType &, const FixedString<allocatedSize> &)

◆ operator==() [1/10]

bool toy::operator== ( const char * lhs,
const CStringView & rhs )
constexprnoexcept

This operator compares a C string with a CStringView object for equality.

Parameters
lhsThe C string.
rhsThe CStringView object.
Returns
true if both strings have the same content, false otherwise.
Precondition
The lhs pointer must not be null.
Note
The comparison is case-sensitive.
Empty strings are considered equal.
See also
operator<=>(const char *, const CStringView &)

◆ operator==() [2/10]

template<size_t allocatedSize>
bool toy::operator== ( const char * lhs,
const FixedString< allocatedSize > & rhs )
nodiscardconstexprnoexcept

Equality comparison operator for C string and FixedString.

This operator compares a C string with a FixedString object for equality.

Template Parameters
allocatedSizeThe size of the FixedString's internal buffer.
Parameters
lhsThe C string.
rhsThe FixedString object.
Returns
true if both strings have the same content, false otherwise.
Precondition
The lhs pointer must not be null.
Note
The comparison is case-sensitive.
Empty strings are considered equal.
See also
operator<=>(const char *, const FixedString<allocatedSize> &)

◆ operator==() [3/10]

bool toy::operator== ( const CStringView & lhs,
const char * rhs )
constexprnoexcept

This operator compares a CStringView object with a C string for equality.

Parameters
lhsThe CStringView object.
rhsThe C string.
Returns
true if both strings have the same content, false otherwise.
Precondition
The rhs pointer must not be null.
Note
The comparison is case-sensitive.
Empty strings are considered equal.
See also
operator<=>(const CStringView &, const char *)

◆ operator==() [4/10]

bool toy::operator== ( const CStringView & lhs,
const CStringView & rhs )
constexprnoexcept

This operator compares two CStringView objects for equality. The comparison is performed character by character.

Parameters
lhsThe left-hand side CStringView object.
rhsThe right-hand side CStringView object.
Returns
true if both strings view have the same content, false otherwise.
Note
The comparison is case-sensitive.
Empty string views are considered equal.
See also
operator<=>(const CStringView &, const CStringView &)

◆ operator==() [5/10]

template<StringLike stringType>
bool toy::operator== ( const CStringView & lhs,
const stringType & rhs )
constexprnoexcept

This operator compares a CStringView object with a toy::StringLike object for equality.

Template Parameters
stringTypeThe type of the toy::StringLike object. Must satisfy the toy::StringLike concept.
Parameters
lhsThe CStringView object.
rhsThe toy::StringLike object.
Returns
true if both strings have the same content, false otherwise.
Note
The comparison is case-sensitive.
Empty strings are considered equal.
See also
operator<=>(const CStringView &, const stringType &)

◆ operator==() [6/10]

template<size_t allocatedSize>
bool toy::operator== ( const FixedString< allocatedSize > & lhs,
const char * rhs )
nodiscardconstexprnoexcept

Equality comparison operator for FixedString and C string.

This operator compares a FixedString object with a C string for equality.

Template Parameters
allocatedSizeThe size of the FixedString's internal buffer.
Parameters
lhsThe FixedString object.
rhsThe C string.
Returns
true if both strings have the same content, false otherwise.
Precondition
The rhs pointer must not be null.
Note
The comparison is case-sensitive.
Empty strings are considered equal.
See also
operator<=>(const FixedString<allocatedSize> &, const char *)

◆ operator==() [7/10]

template<size_t allocatedSize, StringLike stringType>
bool toy::operator== ( const FixedString< allocatedSize > & lhs,
const stringType & rhs )
nodiscardconstexprnoexcept

Equality comparison operator for FixedString and toy::StringLike object.

This operator compares a FixedString object with a toy::StringLike object for equality.

Template Parameters
allocatedSizeThe size of the FixedString's internal buffer.
stringTypeThe type of the toy::StringLike object. Must satisfy the toy::StringLike concept.
Parameters
lhsThe FixedString object.
rhsThe toy::StringLike object.
Returns
true if both strings have the same content, false otherwise.
Note
The comparison is case-sensitive.
Empty strings are considered equal.
See also
operator<=>(const FixedString<allocatedSize> &, const stringType &)

◆ operator==() [8/10]

template<size_t allocatedSize1, size_t allocatedSize2>
bool toy::operator== ( const FixedString< allocatedSize1 > & lhs,
const FixedString< allocatedSize2 > & rhs )
nodiscardconstexprnoexcept

Equality comparison operator for two FixedString objects.

This operator compares two FixedString objects for equality. The comparison is performed character by character.

Template Parameters
allocatedSize1The size of the first FixedString's internal buffer.
allocatedSize2The size of the second FixedString's internal buffer.
Parameters
lhsThe left-hand side FixedString object.
rhsThe right-hand side FixedString object.
Returns
true if both strings have the same content, false otherwise.
Note
The comparison is case-sensitive.
Empty strings are considered equal.
See also
operator<=>(const FixedString<allocatedSize1> &, const FixedString<allocatedSize2> &)

◆ operator==() [9/10]

template<StringLike stringType>
bool toy::operator== ( const stringType & lhs,
const CStringView & rhs )
constexprnoexcept

This operator compares a toy::StringLike object with a CStringView object for equality.

Template Parameters
stringTypeThe type of the toy::StringLike object. Must satisfy the toy::StringLike concept.
Parameters
lhsThe toy::StringLike object.
rhsThe CStringView object.
Returns
true if both strings have the same content, false otherwise.
Note
The comparison is case-sensitive.
Empty strings are considered equal.
See also
operator<=>(const stringType &, const CStringView &)

◆ operator==() [10/10]

template<size_t allocatedSize, StringLike stringType>
bool toy::operator== ( const stringType & lhs,
const FixedString< allocatedSize > & rhs )
nodiscardconstexprnoexcept

Equality comparison operator for toy::StringLike object and FixedString.

This operator compares a toy::StringLike object with a FixedString object for equality.

Template Parameters
stringTypeThe type of the toy::StringLike object. Must satisfy the toy::StringLike concept.
allocatedSizeThe size of the FixedString's internal buffer.
Parameters
lhsThe toy::StringLike object.
rhsThe FixedString object.
Returns
true if both strings have the same content, false otherwise.
Note
The comparison is case-sensitive.
Empty strings are considered equal.
See also
operator<=>(const stringType &, const FixedString<allocatedSize> &)

◆ operator^()

template<typename T>
T toy::operator^ ( T lhs,
T rhs )
nodiscardconstexprnoexcept

Computes bitwise XOR on the underlying integers, then casts back to T.

Template Parameters
TScoped enum for which toy::EnableBitwiseOperators is specialized with enable == true.
Parameters
lhsFirst operand.
rhsSecond operand.
Returns
static_cast<T>(std::to_underlying(lhs) ^ std::to_underlying(rhs)).

◆ operator^=()

template<typename T>
T & toy::operator^= ( T & lhs,
T rhs )
constexprnoexcept

Compound XOR: lhs becomes lhs ^ rhs.

Template Parameters
TScoped enum for which toy::EnableBitwiseOperators is specialized with enable == true.
Parameters
lhsReference to the left-hand value (updated).
rhsRight-hand operand.
Returns
Reference to lhs.

◆ operator|()

template<typename T>
T toy::operator| ( T lhs,
T rhs )
nodiscardconstexprnoexcept

Computes bitwise OR on the underlying integers, then casts back to T.

Template Parameters
TScoped enum for which toy::EnableBitwiseOperators is specialized with enable == true.
Parameters
lhsFirst operand.
rhsSecond operand.
Returns
static_cast<T>(std::to_underlying(lhs) | std::to_underlying(rhs)).

◆ operator|=()

template<typename T>
T & toy::operator|= ( T & lhs,
T rhs )
constexprnoexcept

Compound OR: lhs becomes lhs | rhs.

Template Parameters
TScoped enum for which toy::EnableBitwiseOperators is specialized with enable == true.
Parameters
lhsReference to the left-hand value (updated).
rhsRight-hand operand.
Returns
Reference to lhs.

◆ operator~()

template<typename T>
T toy::operator~ ( T lhs)
nodiscardconstexprnoexcept

Computes bitwise NOT of the underlying integer, then casts back to T.

Template Parameters
TScoped enum for which toy::EnableBitwiseOperators is specialized with enable == true.
Parameters
lhsOperand.
Returns
static_cast<T>(~std::to_underlying(lhs)).
Note
Inverts every bit of the underlying representation; meaning as a flag set depends on width and signedness.

◆ utoa()

template<std::unsigned_integral T>
char * toy::utoa ( char * dest,
size_t destSize,
T value,
unsigned base = 10 )
constexprnoexcept

Converts an unsigned integer to its C string representation in the given base.

Writes the representation of value in base base into dest, null-terminated. Digits above 9 use uppercase letters A–Z.

Template Parameters
TUnsigned integer type; must satisfy std::unsigned_integral (e.g. uint8_t, uint32_t, uint64_t).
Parameters
destDestination buffer for the result.
destSizeSize of dest in characters.
valueValue to convert.
baseNumerical base (default: 10). Supported range 2–36.
Returns
Pointer to dest.
Precondition
dest is not null; destSize is sufficient for the output; base is between 2 and 36.

Variable Documentation

◆ _crc16Table

array<uint16_t, 256> toy::_crc16Table
staticconstexpr
Initial value:
{{
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1,
0xC481, 0x0440, 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40,
0xC901, 0x09C0, 0x0880, 0xC841, 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 0x1E00, 0xDEC1,
0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1,
0xF281, 0x3240, 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, 0x3C00, 0xFCC1, 0xFD81, 0x3D40,
0xFF01, 0x3FC0, 0x3E80, 0xFE41, 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, 0x2800, 0xE8C1,
0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0,
0x2080, 0xE041, 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, 0x6600, 0xA6C1, 0xA781, 0x6740,
0xA501, 0x65C0, 0x6480, 0xA441, 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, 0xAA01, 0x6AC0,
0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1,
0xB681, 0x7640, 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, 0x5000, 0x90C1, 0x9181, 0x5140,
0x9301, 0x53C0, 0x5280, 0x9241, 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, 0x9C01, 0x5CC0,
0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0,
0x4C80, 0x8C41, 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341,
0x4100, 0x81C1, 0x8081, 0x4040,
}}

CRC-16 lookup table using IBM/ARC polynomial (0x8005).

This lookup table contains precomputed CRC-16 values for all possible byte values (0-255). The table is generated using the IBM/ARC polynomial (x¹⁶ + x¹⁵ + x² + 1, 0x8005). Using this table allows for O(1) CRC calculation per byte instead of O(16) bit-by-bit calculation.

◆ _crc32Table

array<uint32_t, 256> toy::_crc32Table
staticconstexpr

CRC-32 lookup table using IEEE 802.3 polynomial (0x04C11DB7).

This lookup table contains precomputed CRC-32 values for all possible byte values (0-255). The table is generated using the IEEE 802.3 polynomial (x³² + x²⁶ + x²³ + x²² + x¹⁶ + x¹² + x¹¹ + x¹⁰ + x⁸ + x⁷ + x⁵ + x⁴ + x² + x + 1, 0x04C11DB7). Using this table allows for O(1) CRC calculation per byte instead of O(32) bit-by-bit calculation.

◆ _crc8Table

array<uint8_t, 256> toy::_crc8Table
staticconstexpr
Initial value:
{{
0x00, 0x5E, 0xBC, 0xE2, 0x61, 0x3F, 0xDD, 0x83, 0xC2, 0x9C, 0x7E, 0x20, 0xA3, 0xFD, 0x1F, 0x41, 0x9D, 0xC3, 0x21,
0x7F, 0xFC, 0xA2, 0x40, 0x1E, 0x5F, 0x01, 0xE3, 0xBD, 0x3E, 0x60, 0x82, 0xDC, 0x23, 0x7D, 0x9F, 0xC1, 0x42, 0x1C,
0xFE, 0xA0, 0xE1, 0xBF, 0x5D, 0x03, 0x80, 0xDE, 0x3C, 0x62, 0xBE, 0xE0, 0x02, 0x5C, 0xDF, 0x81, 0x63, 0x3D, 0x7C,
0x22, 0xC0, 0x9E, 0x1D, 0x43, 0xA1, 0xFF, 0x46, 0x18, 0xFA, 0xA4, 0x27, 0x79, 0x9B, 0xC5, 0x84, 0xDA, 0x38, 0x66,
0xE5, 0xBB, 0x59, 0x07, 0xDB, 0x85, 0x67, 0x39, 0xBA, 0xE4, 0x06, 0x58, 0x19, 0x47, 0xA5, 0xFB, 0x78, 0x26, 0xC4,
0x9A, 0x65, 0x3B, 0xD9, 0x87, 0x04, 0x5A, 0xB8, 0xE6, 0xA7, 0xF9, 0x1B, 0x45, 0xC6, 0x98, 0x7A, 0x24, 0xF8, 0xA6,
0x44, 0x1A, 0x99, 0xC7, 0x25, 0x7B, 0x3A, 0x64, 0x86, 0xD8, 0x5B, 0x05, 0xE7, 0xB9, 0x8C, 0xD2, 0x30, 0x6E, 0xED,
0xB3, 0x51, 0x0F, 0x4E, 0x10, 0xF2, 0xAC, 0x2F, 0x71, 0x93, 0xCD, 0x11, 0x4F, 0xAD, 0xF3, 0x70, 0x2E, 0xCC, 0x92,
0xD3, 0x8D, 0x6F, 0x31, 0xB2, 0xEC, 0x0E, 0x50, 0xAF, 0xF1, 0x13, 0x4D, 0xCE, 0x90, 0x72, 0x2C, 0x6D, 0x33, 0xD1,
0x8F, 0x0C, 0x52, 0xB0, 0xEE, 0x32, 0x6C, 0x8E, 0xD0, 0x53, 0x0D, 0xEF, 0xB1, 0xF0, 0xAE, 0x4C, 0x12, 0x91, 0xCF,
0x2D, 0x73, 0xCA, 0x94, 0x76, 0x28, 0xAB, 0xF5, 0x17, 0x49, 0x08, 0x56, 0xB4, 0xEA, 0x69, 0x37, 0xD5, 0x8B, 0x57,
0x09, 0xEB, 0xB5, 0x36, 0x68, 0x8A, 0xD4, 0x95, 0xCB, 0x29, 0x77, 0xF4, 0xAA, 0x48, 0x16, 0xE9, 0xB7, 0x55, 0x0B,
0x88, 0xD6, 0x34, 0x6A, 0x2B, 0x75, 0x97, 0xC9, 0x4A, 0x14, 0xF6, 0xA8, 0x74, 0x2A, 0xC8, 0x96, 0x15, 0x4B, 0xA9,
0xF7, 0xB6, 0xE8, 0x0A, 0x54, 0xD7, 0x89, 0x6B, 0x35,
}}

CRC-8 lookup table using Dallas/Maxim polynomial (0x31).

This lookup table contains precomputed CRC-8 values for all possible byte values (0-255). The table is generated using the Dallas/Maxim polynomial (x⁸ + x⁵ + x⁴ + 1, 0x31). Using this table allows for O(1) CRC calculation per byte instead of O(8) bit-by-bit calculation.

◆ _decimalDigitsPerGroup

size_t toy::_decimalDigitsPerGroup = 3
constexpr

Number of decimal digits per group when formatNumberString() inserts the caller-supplied separator.

Fixed at three so grouping matches common thousands-style splitting from the right.

◆ _exponentTable

array<uint32_t, 32> toy::_exponentTable
constexpr
Initial value:
{{
0xF0BDC21A, 0x3DA137D5, 0x9DC5ADA8, 0x2863C1F5, 0x6765C793, 0x1A784379, 0x43C33C19, 0xAD78EBC5,
0x2C68AF0B, 0x71AFD498, 0x1D1A94A2, 0x4A817C80, 0xBEBC2000, 0x30D40000, 0x7D000000, 0x20000000,
0x51EB851E, 0xD1B71758, 0x35AFE535, 0x89705F41, 0x232F3302, 0x5A126E1A, 0xE69594BE, 0x3B07929F,
0x971DA050, 0x26AF8533, 0x63090312, 0xFD87B5F2, 0x40E75996, 0xA6274BBD, 0x2A890926, 0x6CE3EE76,
}}

Precomputed exponent lookup table for efficient binary-to-decimal floating-point conversion.

This lookup table contains 32 precomputed values used to convert IEEE-754 binary floating-point exponents to decimal exponents during float-to-string conversion. The table maps groups of 8 binary exponent values to precomputed multipliers that approximate the conversion from binary to decimal representation.

Note
The table is indexed by exponent / 8, where exponent is the 8-bit IEEE-754 exponent field (0-255). Each entry is a 32-bit fixed-point multiplier used to compute the decimal mantissa efficiently.
This table enables O(1) lookup instead of expensive runtime power-of-10 calculations, significantly improving the performance of floating-point number formatting.

◆ _utf8CharSizeTable

array<uint8_t, 256> toy::_utf8CharSizeTable
staticconstexpr
Initial value:
{{
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x07, 0x08,
}}

UTF-8 character size lookup table for efficient UTF-8 parsing.

This lookup table contains precomputed UTF-8 character sizes for all possible byte values (0-255). The table maps each byte to the number of bytes required to represent a complete UTF-8 character sequence. Using this table allows for O(1) UTF-8 character size determination instead of O(n) bit-by-bit analysis.

Note
Values: 0x01 = 1-byte ASCII character, 0x02-0x04 = multi-byte UTF-8 sequence, 0x00 = invalid/incomplete.