Namespace c4

Description

this is a work in progress

Memory resource providers

Policy classes which provide a memory resource for use in an allocator.

MemResprovides a per-allocator memory resource
MemResGlobalthe allocators using this will default to the global memory resource

Allocators

Lightweight classes that act as handles to specific memory resources and provide typeful memory.

AllocatorAn allocator is simply a proxy to a memory resource.
SmallAllocator

template <class T>
using allocator = Allocator< T, MemResGlobal >

An allocator making use of the global memory resource.

template <class T>
using allocator_mr = Allocator< T, MemRes >

An allocator with a per-instance memory resource

template <class T, size_t N = 16, size_t Alignment = alignof(T)>
using small_allocator = SmallAllocator< T, N, Alignment, MemResGlobal >

template <class T, size_t N = 16, size_t Alignment = alignof(T)>
using small_allocator_mr = SmallAllocator< T, N, Alignment, MemRes >

Hash utils

See
http://aras-p.info/blog/2016/08/02/Hash-Functions-all-the-way-down/

template <size_t Bits>
using fnv1a_t = typename detail::fnv1a< Bits >::type

hash_bytes overload

Raw memory allocation

aallocc-style allocation
afreeAligned free
areallocAligned reallocation

using aalloc_pfn = void *(*)(size_t size, size_t alignment)

allocation setup facilities.

Function pointer type for aligned allocation

See
set_aalloc()

using afree_pfn = void(*)(void *ptr)

Function pointer type for aligned deallocation

See
set_afree()

using arealloc_pfn = void *(*)(void *ptr, size_t oldsz, size_t newsz, size_t alignment)

Function pointer type for aligned reallocation

See
set_arealloc()
set_aallocallocation function pointer setters/getters
set_afreeSet the global aligned deallocation function.
set_areallocSet the global aligned reallocation function.
get_aallocGet the global aligned reallocation function.
get_afreeGet the global aligned deallocation function.
get_areallocGet the global aligned reallocation function.

Memory resources

get_memory_resource_mallocreturns a malloc-based memory resource
MemoryResourcec++-style allocation
get_memory_resourceget the current global memory resource
set_memory_resourceset the global memory resource
MemoryResourceMallocA c4::aalloc-based memory resource
MemoryResourceLinearprovides a linear memory resource
MemoryResourceStackprovides a stack-type malloc-based memory resource.
MemoryResourceLinearArrprovides a linear array-based memory resource.
MemoryResourceCountsa MemoryResource which latches onto another MemoryResource and counts allocations and sizes.
ScopedMemoryResourceRAII class which binds a memory resource with a scope duration.
ScopedMemoryResourceCountsRAII class which counts allocations and frees inside a scope

Intrinsic types

using cbyte = const char

a constant byte

using byte = char

a mutable byte

using i8 = int8_t

using i16 = int16_t

using i32 = int32_t

using i64 = int64_t

using u8 = uint8_t

using u16 = uint16_t

using u32 = uint32_t

using u64 = uint64_t

using f32 = float

using f64 = double

using ssize_t = typename std::make_signed< size_t >::type

Utility types

aggregate_tsome tag types
with_capacity_ta tag type for specifying the initial capacity of allocatable contiguous storage
varargs_ta tag type for disambiguating template parameter packs in variadic template overloads
cref_uses_valwhether a value should be used in place of a const-reference in argument passing.

template <class T>
using fastcref = typename std::conditional< c4::cref_uses_val< T >::value, T, T const & >::type

Whether to use pass-by-value or pass-by-const-reference in a function argument or return type.

EmptyStructJust what its name says
EmptyStructVirtualJust what its name says
inheritfrom
min_remainderUtilities to make a class obey size restrictions (eg, min size or size multiple of)
mult_remainderhow many bytes must be added to size such that the result is a multiple of multipleof?
Paddedforce the following class to be tightly packed
Padded< T, 0 >When the padding argument is 0, we cannot declare the char[] array.

template <class T, size_t Min>
using MinSized = Padded< T, min_remainder(sizeof(T), Min)>

make T have a size which is at least Min bytes

template <class T, size_t Mult>
using MultSized = Padded< T, mult_remainder(sizeof(T), Mult)>

make T have a size which is a multiple of Mult bytes

template <class T, size_t Min, size_t Mult>
using MinMultSized = MultSized< MinSized< T, Min >, Mult >

make T have a size which is simultaneously: -bigger or equal than Min -a multiple of Mult

template <class T>
using UbufSized = MinMultSized< T, 64, 16 >

make T be suitable for use as a uniform buffer. (at least with DirectX).

Type traits utilities

is_instance_of_tplhttp://stackoverflow.com/questions/10821380/is-t-an-instance-of-a-template-in-c
is_instance_of_tpl< X, X< Y... > >

Backport implementation of some Modern C++ utilities

integer_sequenceindex_sequence and friends are available only for C++14 and later

template <size_t... _Ip>
using index_sequence = integer_sequence< size_t, _Ip... >

C++11 implementation of index sequence

See
https://en.cppreference.com/w/cpp/utility/integer_sequence
See
taken from clang: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?revision=211563&view=markup#l687

template <class _Tp, _Tp _Np>
using make_integer_sequence = typename __detail::__make_integer_sequence< _Tp, _Np >::type

C++11 implementation of index sequence

See
https://en.cppreference.com/w/cpp/utility/integer_sequence
See
taken from clang: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?revision=211563&view=markup#l687

template <size_t _Np>
using make_index_sequence = make_integer_sequence< size_t, _Np >

C++11 implementation of index sequence

See
https://en.cppreference.com/w/cpp/utility/integer_sequence
See
taken from clang: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?revision=211563&view=markup#l687

template <class... _Tp>
using index_sequence_for = make_index_sequence< sizeof...(_Tp)>

C++11 implementation of index sequence

See
https://en.cppreference.com/w/cpp/utility/integer_sequence
See
taken from clang: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?revision=211563&view=markup#l687

Other Types

base64_validcheck that the given buffer is a valid base64 encoding
base64_encodebase64-encode binary data.
base64_decodedecode the base64 encoding in the given buffer
fmtformatting truthy types as booleans
to_chars overloadwrite a variable in base64 format
to_chars overloadbool implementation
to_chars overloadsingle-char implementation
to_chars overloadcsubstr implementation
to_chars overloadsubstr
to_chars overloadwrite a variable in raw binary format, using memcpy
to_chars overloadwrite a variable as an alphabetic boolean, ie as either true or false
to_chars overloadformat an integral_ signed type
to_chars overloadformat an integral_ signed type, pad with zeroes
to_chars overloadformat an integral_ unsigned type
to_chars overloadformat an integral_ unsigned type, pad with zeroes
to_chars overloadcopy an std::string to a writeable string view
from_chars overloadread a variable in base64 format
from_chars overloadextract a single character from a substring
from_chars overloadread a variable in raw binary format, using memcpy
from_chars overloadcopy a string view to an existing std::string
bm2stream overloadwrite a bitmask to a stream, formatted as a string
bm2str overloadconvert a bitmask to string
bm2str overloadcleanup!
str2bm overloadconvert a string to a bitmask
blob_

using cblob = blob_< cbyte >

an immutable binary blob

using blob = blob_< byte >

a mutable binary blob

Mentioned in:

Getting Started / c4::span and c4::blob

C4_MUST_BE_TRIVIAL_COPY overload
isspace overload
char_traits
char_traits< char >
char_traits< wchar_t >
num_needed_charsget the number of C characters needed to store a number of bytes
RealFormat_e
to_c_fmt
is_fixed_lengthin some platforms, int,unsigned int are not any of int8_t...int64_t and long,unsigned long are not any of uint8_t...uint64_t
atox overloadgeneric versions
xtoa overloadgeneric versions
xtoa overloadfor pointers
write_dec overloadwrite an integer to a string in decimal format
write_dec overloadsame as c4::write_dec(), but pad with zeroes on the left such that the resulting string is num_digits wide
write_hex overloadwrite an integer to a string in hexadecimal format
write_hex overloadsame as c4::write_hex(), but pad with zeroes on the left such that the resulting string is num_digits wide
write_oct overloadwrite an integer to a string in octal format
write_oct overloadsame as c4::write_oct(), but pad with zeroes on the left such that the resulting string is num_digits wide
write_bin overloadwrite an integer to a string in binary format
write_bin overloadsame as c4::write_bin(), but pad with zeroes on the left such that the resulting string is num_digits wide
read_decread a decimal integer from a string
read_hexread an hexadecimal integer from a string
read_binread a binary integer from a string
read_octread an octal integer from a string
itoa overloadconvert an integral signed decimal to a string
itoa overloadconvert an integral signed integer to a string, using a specific radix
itoa overloadsame as c4::itoa(), but pad with zeroes on the left such that the resulting string is num_digits wide
utoa overloadconvert an integral unsigned decimal to a string
utoa overloadconvert an integral unsigned integer to a string, using a specific radix
utoa overloadsame as c4::utoa(), but pad with zeroes on the left such that the resulting string is num_digits wide
atoiConvert a trimmed string to a signed integral value
atoi_firstSelect the next range of characters in the string that can be parsed as a signed integral value, and convert it using atoi()
atouConvert a trimmed string to an unsigned integral value
atou_firstSelect the next range of characters in the string that can be parsed as an unsigned integral value, and convert it using atou()
ftoaConvert a single-precision real number to string
dtoaConvert a double-precision real number to string
atofConvert a string to a single precision real number
atodConvert a string to a double precision real number
atof_firstConvert a string to a single precision real number
atod_firstConvert a string to a double precision real number
from_chars_first overloadread a variable in raw binary format, using memcpy
to_chars_subcall to_chars() and return a substr consisting of the written portion of the input buffer
construct overloaddefault-construct an object, trivial version
construct overloaddefault-construct an object, non-trivial version
construct_n overloaddefault-construct n objects, trivial version
construct_n overloaddefault-construct n objects, non-trivial version
copy_construct overloadcopy-construct
copy_construct_n overload
copy_assign overloadcopy-assign
copy_assign_n overload
move_construct overloadmove-construct
move_construct_n overload
move_assign overloadmove-assign
move_assign_n overload
destroy overloaddestroy
destroy_n overload
make_room overloadmakes room at the beginning of buf, which has a current size of n
make_room overloadmakes room at the beginning of buf, which has a current size of bufsz
make_room overloadmake room to the right of pos
make_room overloadmake room to the right of pos, copying to the beginning of a different buffer
destroy_room overloaddestroy room at the beginning of buf, which has a current size of n
destroy_room overloaddestroy room to the right of pos, copying to a different buffer

template <typename Enum>
using is_scoped_enum = std::integral_constant< bool, std::is_enum< Enum >::value &&!std::is_convertible< Enum, int >::value >

taken from http://stackoverflow.com/questions/15586163/c11-type-trait-to-differentiate-between-enum-class-and-regular-enum

EnumOffsetType
EnumSymbolsA simple (proxy) container for the value-name pairs of an enum type
esymsreturn an EnumSymbols object for the enum type T
eoffs_clsreturn the offset for an enum symbol class
eoffs_pfxreturn the offset for an enum symbol prefix
eoffs
str2eget the enum value corresponding to a c-string
e2strget the c-string corresponding to an enum value
e2stroffslike e2str(), but add an offset.

error_flags s_error_flags = ON_ERROR_DEFAULTS

error_callback_type s_error_callback = nullptr

is_debugger_attached
ErrorFlags_e

using error_flags = uint32_t

set_error_flags
get_error_flags

using error_callback_type = void(*)(const char *msg, size_t msg_size)

set_error_callbackSet the function which is called when an error occurs.
get_error_callback
ScopedErrorSettingsRAII class controling the error settings inside a scope.
handle_error
handle_warning
srcloc
catserialize the arguments, concatenating them to the given fixed-size buffer
cat_sublike c4::cat() but return a substr instead of a size
uncatdeserialize the arguments from the given buffer.
catsepserialize the arguments, concatenating them to the given fixed-size buffer, using a separator between each argument
catsep_sublike c4::catsep() but return a substr instead of a size
uncatsepdeserialize the arguments from the given buffer, using a separator.
formatusing a format string, serialize the arguments into the given fixed-size buffer
format_sublike c4::format() but return a substr instead of a size
unformatusing a format string, deserialize the arguments from the given buffer.
append_ta tag type for marking append to container

constexpr const append_t append = {}

a tag variable

See
c4::catrs()
catrs overloadlike c4::cat(), but receives a container, and resizes it as needed to contain the result
catrs overloadlike c4::cat(), but creates and returns a new container sized as needed to contain the result.
catrs overloadlike c4::cat(), but receives a container, and appends to it instead of overwriting it
catseprslike catsep(), but receives a container, and appends the arguments, resizing the container as needed to contain the result
formatrs overloadlike c4::format(), but receives a container, and resizes it as needed to contain the result
formatrs overloadlike c4::format(), but create a new container with the result.
formatrs overloadlike format(), but receives a container, and appends the arguments, resizing the container as needed to contain the result
get_memory_resource_stack
AllocationCounts
mem_zero overloadset the given memory to zero
mem_overlapsreturns true if the memory overlaps
mem_repeatFills 'dest' with the first 'pattern_size' bytes at 'pattern', 'num_times'.
is_aligned
lsbleast significant bit
lsb11TMP version of lsb(); this needs to be implemented with template meta-programming because C++11 cannot use a constexpr function with local variables
msbmost significant bit
msb11TMP version of msb(); this needs to be implemented with template meta-programming because C++11 cannot use a constexpr function with local variables
contiguous_maskreturn a mask with all bits set [first_bit,last_bit[; this function is constexpr-14 because of the local variables
contiguous_mask11TMP version of contiguous_mask(); this needs to be implemented with template meta-programming because C++11 cannot use a constexpr function with local variables

template <class First, class Second>
using tight_pair = detail::tight_pair< First, Second, detail::tpc_which_case< First, Second >()>

span_crtpa crtp base for implementing span classes
operator== overloadcomparisons between substrings std::vector<char>/std::vector<const char>
operator!= overload
operator< overload
operator<= overload
operator> overload
operator>= overload
spanA non-owning span of elements contiguously stored in memory.

template <class T, class I = C4_SIZE_TYPE>
using cspan = span< const T, I >

spanrsA non-owning span resizeable up to a capacity

template <class T, class I = C4_SIZE_TYPE>
using cspanrs = spanrs< const T, I >

spanrslA non-owning span which always retains the capacity of the original range it was taken from (though it may loose its original size)

template <class T, class I = C4_SIZE_TYPE>
using cspanrsl = spanrsl< const T, I >

to_substr overloadget a writeable view to an existing std::string
to_substr overloadget a substr (writeable string view) of an existing std::vector<char>
to_substr overloadBecause of a C++ limitation, substr cannot provide simultaneous overloads for constructing from a char[N] and a char*; the latter will always be chosen by the compiler
to_substr overloadneutral version for use in generic code
to_csubstr overloadget a readonly view to an existing std::string
to_csubstr overloadget a csubstr (read-only string) view of an existing std::vector<char>
to_csubstr overloadget a csubstr (read-only string view) of an existing std::vector<const char>
to_csubstr overloadBecause of a C++ limitation, substr cannot provide simultaneous overloads for constructing from a char[N] and a char*; the latter will always be chosen by the compiler
to_csubstr overloadneutral version for use in generic code
basic_substringa non-owning string-view, consisting of a character pointer and a length.

typedef C4CORE_EXPORT basic_substring< const char > csubstr

ConstantSUBSTRing: a non-owning read-only string view

See
to_substr()
See
to_csubstr()
Mentioned in:

Getting Started / Writeable string views: c4::substr and c4::csubstr

typedef C4CORE_EXPORT basic_substring< char > substr

SUBSTRing: a non-owning read-write string view

See
to_substr()
See
to_csubstr()
Mentioned in:

Getting Started / Writeable string views: c4::substr and c4::csubstr

operator<<@define C4_SUBSTR_NO_OSTREAM_LSHIFT doctest does not deal well with template operator<<
is_narrower_size
szconv overloadwhen SizeOut is wider than SizeIn, assignment can occur without reservations
szconv overloadwhen SizeOut is narrower than SizeIn, narrowing will occur, so we check for overflow

using time_type = C4_TIME_TYPE

currtimea general-use time stamp in microseconds (usecs)
exetimeexecution time, in microsecs
busy_waitdo a spin loop for at least the given time
Timeconverts automatically from/to microseconds.
nsecs
usecs
msecs
secs
mins
hours
type_name overloadcompile-time type name
type_name overloadcompile-time type name This is an overloaded member function, provided for convenience

constexpr const aggregate_t aggregate {}

See
aggregate_t

constexpr const with_capacity_t with_capacity {}

See
with_capacity_t

constexpr const varargs_t varargs {}

See
with_capacity_t

Source

Line 24 in src/c4/allocator.hpp.






Add Discussion as Guest

Log in