MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
Collections and Data Structures

Collection of data structures and collections. More...

Namespaces

namespace  mtcore
 Core library for C++ with Zig-related functionality.
 
namespace  mtcore::slices
 Additional algorithms that can be performed on slices, such as comparisons, searching, etc.
 
namespace  mtcore::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)\).
 

Classes

struct  mtcore::ArrayList< T >
 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  mtcore::Bitset
 Represents a bitset with dynamically allocated memory (using an mtcore allocator) Allows operating on an arbitrary number of bits. More...
 
struct  mtcore::Bitset2D
 Represents a bitset with dynamically allocated memory (using an mtcore allocator) Allows operating on an arbitrary number of bits. More...
 
struct  mtcore::BitsetFixed< NumBits >
 Represents a bitset with dynamically allocated memory (using an mtcore allocator) Allows operating on an arbitrary number of bits. More...
 
struct  mtcore::Handle
 Handle to an item in the list. More...
 
struct  mtcore::GenList< T >
 Represents a generational list where removed items are marked and recycled. More...
 
struct  mtcore::PtrIter< T >
 Iterator that gives pointers to elements of a collection. More...
 
struct  mtcore::ConstPtrIter< T >
 Iterator that gives const pointers to elements of a collection. More...
 
struct  mtcore::ValIter< T >
 Iterator that gives copies of elements of a collection. More...
 
struct  mtcore::Optional< T >
 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  mtcore::Optional< T * >
 Represents a pointer that may or may not be null. More...
 
struct  mtcore::Nullopt
 Placeholder value for any empty Optional (similar to std::nullopt) More...
 
struct  mtcore::Queue< T >
 FIFO Queue (First In, First Out) Dynamically allocated, can be resized. More...
 
struct  mtcore::FixedQueue< T, Capacity >
 Statically allocated FIFO queue with fixed maximum capacity. More...
 
struct  mtcore::RingBuffer< T >
 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  mtcore::FixedRingBuffer< T, Capacity >
 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  mtcore::SegmentedList< T >
 Segmented list where each segment contains multiple nodes Allows growing the list without having to invalidate all previous memory addresses. More...
 
struct  mtcore::Slice< T >
 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...
 

Functions

template<typename T>
PtrIter< T > mtcore::iter::ptr (T &r)
 Generic pointer iterator that uses the operator[] and incrementing indexes to iterate over a collection Returns pointers to elements inside the collection (can be modified)
 
template<typename T>
ValIter< T > mtcore::iter::val (const T &r)
 Generic value iterator that uses the operator[] and incrementing indexes to iterate over a collection Does copies when iterating`.
 
template<typename T>
ConstPtrIter< T > mtcore::iter::const_ptr (const T &r)
 Generic constant pointer iterator that uses the operator[] and incrementing indexes to iterate over a collection Returns constant pointers to elements inside the collection (cannot be modified) Useful for reads while avoiding copies.
 
constexpr Slice< char32_t > mtcore::mut_slice_from (char32_t *cstr, size_t len)
 Creates a mutable slice from a utf32 string and length.
 
constexpr Slice< char32_t > mtcore::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 > mtcore::slice_from (char32_t *cstr)
 Creates a slice from a utf32 string in the form of a c string.
 
constexpr Slice< const char32_t > mtcore::slice_from (char32_t *cstr, size_t len)
 Creates a slice from a utf32 string and length.
 
constexpr Slice< const char32_t > mtcore::slice_from (const char32_t *cstr, size_t len)
 Creates a slice from a utf32 string and length.
 
constexpr Slice< const char32_t > mtcore::slice_from (const char32_t *cstr)
 Creates a slice from a utf32 string in the form of a c string.
 
constexpr Slice< char16_t > mtcore::mut_slice_from (char16_t *cstr, size_t len)
 Creates a mutable slice from a utf16 string and length.
 
constexpr Slice< const char16_t > mtcore::slice_from (char16_t *cstr, size_t len)
 Creates a slice from a utf16 string and length.
 
constexpr Slice< const char16_t > mtcore::slice_from (const char16_t *cstr, size_t len)
 Creates a slice from a utf16 string and length.
 
constexpr Slice< char8_t > mtcore::mut_slice_from (char8_t *cstr, size_t len)
 Creates a mutable slice from a utf8 string and length.
 
constexpr Slice< const char8_t > mtcore::slice_from (char8_t *cstr, size_t len)
 Creates a slice from a utf8 string and length.
 
constexpr Slice< const char8_t > mtcore::slice_from (const char8_t *cstr, size_t len)
 Creates a slice from a utf8 string and length.
 
constexpr Slice< char16_t > mtcore::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 > mtcore::slice_from (char16_t *cstr)
 Creates a slice from a utf16 string in the form of a c string.
 
constexpr Slice< const char16_t > mtcore::slice_from (const char16_t *cstr)
 Creates a slice from a utf16 string in the form of a c string.
 
constexpr Slice< char8_t > mtcore::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 > mtcore::slice_from (char8_t *cstr)
 Creates a slice from a utf8 string in the form of a c string.
 
constexpr Slice< const char8_t > mtcore::slice_from (const char8_t *cstr)
 Creates a slice from a utf8 string in the form of a c string.
 
constexpr Slice< const char > mtcore::slice_from (char *cstr)
 Creates a slice from a string in the form of a c string.
 
constexpr Slice< const char > mtcore::slice_from (const char *cstr)
 Creates a slice from a string in the form of a c string.
 
constexpr Slice< const char > mtcore::slice_from (char *cstr, const size_t len)
 Creates a slice from a string with a length.
 
constexpr Slice< char > mtcore::mut_slice_from (char *cstr, const size_t len)
 Creates a mutable slice from a string with a length.
 
constexpr Slice< const char > mtcore::slice_from (const char *cstr, const size_t len)
 Creates a slice from a string with a length.
 
Slice< const char > mtcore::slice_from (const std::string &str)
 Creates a slice from a std::string.
 
constexpr Slice< const char > mtcore::slice_from (const std::string_view &sv)
 Creates a slice from a std::string_view.
 
template<typename T>
Slice< std::add_const_t< T > > mtcore::slice_from (const std::vector< T > &arr)
 Creates a slice from a vector.
 
template<typename T>
Slice< T > mtcore::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 > > mtcore::slice_from (const std::array< T, N > &arr)
 Creates a slice from an array.
 
template<typename T, size_t N>
constexpr Slice< T > mtcore::mut_slice_from (std::array< T, N > &arr)
 Creates a mutable slice from an array.
 
Slice< char > mtcore::mut_slice_from (char *cstr)
 Creates a mutable slice from a c string.
 
Slice< char > mtcore::mut_slice_from (std::string &str)
 Creates a mutable slice from a string.
 
template<typename T>
bool mtcore::slices::starts_with (const Slice< T > &needle, const Slice< T > &haystack)
 Checks whether a slice (the haystack) starts with elements in another slice in the same order (the needle) - \(O(N)\) Uses the equality operator of the underlying type E.g.
 
template<typename T>
bool mtcore::slices::starts_with (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Checks whether a slice (the haystack) starts with a specific element (the needle) - \(O(N)\) Uses the equality operator of the underlying type E.g.
 
template<typename T>
bool mtcore::slices::contains (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Checks whether a slice (the haystack) contains an element (the needle) Uses the equality operator of the underlying type E.g.
 
template<typename T>
bool mtcore::slices::contains (const Slice< T > &needle, const Slice< T > &haystack)
 Checks whether a slice (the haystack) contains elements in another slice in the same order (the needle) - \(O(N^2)\) Uses the equality operator of the underlying type E.g.
 
template<typename T>
mtcore::Optional< size_t > mtcore::slices::first_index_not_proceeded_by (const std::remove_const_t< T > &prefix, const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
mtcore::Optional< size_t > mtcore::slices::first_index_not_proceeded_by (const std::remove_const_t< T > &prefix, const Slice< T > &needle, const Slice< T > &haystack)
 Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
mtcore::Optional< size_t > mtcore::slices::first_index (const Slice< T > &needle, const Slice< T > &haystack)
 Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
mtcore::Optional< size_t > mtcore::slices::first_index_not (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
mtcore::Optional< size_t > mtcore::slices::first_index (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
mtcore::Optional< size_t > mtcore::slices::last_index (const Slice< T > &needle, const Slice< T > &haystack)
 Gets the last index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
mtcore::Optional< size_t > mtcore::slices::last_index (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Gets the last index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.
 
template<typename T>
SearchIndexes< T, Slice< T > > mtcore::slices::indexes_of (const Slice< T > &needle, const Slice< T > &haystack)
 Returns an iterator of all indexes of occurrences of a needle in a haystack If the needle isn't present, will return an empty iterator.
 
template<typename T>
SearchIndexes< T, std::remove_const_t< T > > mtcore::slices::indexes_of (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Returns an iterator of all indexes of occurrences of a needle in a haystack If the needle isn't present, will return an empty iterator.
 
template<typename T>
SplitIter< T, Slice< T > > mtcore::slices::split (const Slice< T > &needle, const Slice< T > &haystack)
 Splits a slice into smaller sub slices.
 
template<typename T>
SplitIter< T, std::remove_const_t< T > > mtcore::slices::split (const std::remove_const_t< T > &needle, const Slice< T > &haystack)
 Splits a slice into smaller sub slices.
 

Variables

constexpr auto mtcore::nullopt = Nullopt{}
 Placeholder value for an empty Optional.
 

Detailed Description

Collection of data structures and collections.

Function Documentation

◆ const_ptr()

template<typename T>
ConstPtrIter< T > mtcore::iter::const_ptr ( const T & r)

Generic constant pointer iterator that uses the operator[] and incrementing indexes to iterate over a collection Returns constant pointers to elements inside the collection (cannot be modified) Useful for reads while avoiding copies.

Template Parameters
TCollection type to iterate over
Parameters
rCollection to iterate over
Returns
A pointer iterator over a collection

Definition at line 128 of file iter.hpp.

128 {
129 return {r};
130 }
Here is the caller graph for this function:

◆ contains() [1/2]

template<typename T>
bool mtcore::slices::contains ( const Slice< T > & needle,
const Slice< T > & haystack )

Checks whether a slice (the haystack) contains elements in another slice in the same order (the needle) - \(O(N^2)\) Uses the equality operator of the underlying type E.g.

"hello" contains "ll", so this would return true E.g. "hello" does not contain with "wo", so this would return false

Template Parameters
TElement stored in slice
Parameters
needleNeedle to check for
haystackHaystack to search in

Definition at line 120 of file slice_algo.hpp.

120 {
121 if (needle.empty()) {
122 mtcore_warn_trace("Empty needle provided!");
123 return false;
124 }
125 if (needle.size() > haystack.size()) {
126 return false;
127 }
128 ensure(needle.size() <= haystack.size(), "BAD SIZE COMP");
129 for (size_t i = 0; i < haystack.size() - needle.size() + 1; ++i) {
130 if (needle[0] == haystack[i]) {
131 bool looking = true;
132 for (size_t ni = 1; looking && ni < needle.size(); ++ni) {
133 if (needle[ni] != haystack[i + ni]) {
134 looking = false;
135 }
136 }
137 if (looking) {
138 return true;
139 }
140 }
141 }
142 return false;
143 }
#define mtcore_warn_trace(...)
Prints a warning message in debug builds Does nothing in release builds`.
#define ensure(check,...)
Ensures that a check holds true, aborts the program if not true Will print error if the condition is ...
constexpr size_t size() const noexcept
Gets the size of a Slice.
constexpr bool empty() const noexcept
Checks if a Slice is empty.
Here is the call graph for this function:

◆ contains() [2/2]

template<typename T>
bool mtcore::slices::contains ( const std::remove_const_t< T > & needle,
const Slice< T > & haystack )

Checks whether a slice (the haystack) contains an element (the needle) Uses the equality operator of the underlying type E.g.

"hello" contains 'l', so this would return true E.g. "hello" does not contain with 'w', so this would return false

Template Parameters
TElement stored in slice
Parameters
needleNeedle to check for
haystackHaystack to search in

Definition at line 98 of file slice_algo.hpp.

98 {
99 if (haystack.empty()) {
100 return false;
101 }
102 for (size_t i = 0; i < haystack.size(); ++i) {
103 if (needle == haystack[i]) {
104 return true;
105 }
106 }
107 return false;
108 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ first_index() [1/2]

template<typename T>
mtcore::Optional< size_t > mtcore::slices::first_index ( const Slice< T > & needle,
const Slice< T > & haystack )

Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.

Template Parameters
TElement stored in slice
Parameters
needleNeedle to check for
haystackHaystack to search in

Definition at line 228 of file slice_algo.hpp.

228 {
229 if (needle.empty()) {
230 mtcore_warn_trace("Empty needle provided!");
231 return nullopt;
232 }
233 if (needle.size() > haystack.size()) {
234 return nullopt;
235 }
236 ensure(needle.size() <= haystack.size(), "BAD SIZE COMP");
237 for (size_t i = 0; i < haystack.size() - needle.size() + 1; ++i) {
238 if (needle[0] == haystack[i]) {
239 bool looking = true;
240 for (size_t ni = 1; looking && ni < needle.size(); ++ni) {
241 if (needle[ni] != haystack[i + ni]) {
242 looking = false;
243 }
244 }
245 if (looking) {
246 return i;
247 }
248 }
249 }
250 return nullopt;
251 }
constexpr auto nullopt
Placeholder value for an empty Optional.
Definition optional.hpp:409
Here is the call graph for this function:
Here is the caller graph for this function:

◆ first_index() [2/2]

template<typename T>
mtcore::Optional< size_t > mtcore::slices::first_index ( const std::remove_const_t< T > & needle,
const Slice< T > & haystack )

Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.

Template Parameters
TElement stored in slice
Parameters
needleNeedle to check for
haystackHaystack to search in

Definition at line 285 of file slice_algo.hpp.

285 {
286 if (haystack.empty()) {
287 return nullopt;
288 }
289 for (size_t i = 0; i < haystack.size(); ++i) {
290 if (needle == haystack[i]) {
291 return i;
292 }
293 }
294 return nullopt;
295 }
Here is the call graph for this function:

◆ first_index_not()

template<typename T>
mtcore::Optional< size_t > mtcore::slices::first_index_not ( const std::remove_const_t< T > & needle,
const Slice< T > & haystack )

Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.

Template Parameters
TElement stored in slice
Parameters
needleNeedle to check for
haystackHaystack to search in

Definition at line 262 of file slice_algo.hpp.

262 {
263 if (haystack.empty()) {
264 return nullopt;
265 }
266
267 size_t i = 0;
268 for (; i < haystack.size() && needle == haystack[i]; ++i) {}
269
270 if (i >= haystack.size()) {
271 return nullopt;
272 }
273 return i;
274 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ first_index_not_proceeded_by() [1/2]

template<typename T>
mtcore::Optional< size_t > mtcore::slices::first_index_not_proceeded_by ( const std::remove_const_t< T > & prefix,
const Slice< T > & needle,
const Slice< T > & haystack )

Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.

Template Parameters
TElement stored in slice
Parameters
needleNeedle to check for
haystackHaystack to search in

Definition at line 185 of file slice_algo.hpp.

186 {
187 if (needle.empty()) {
188 mtcore_warn_trace("Empty needle provided!");
189 return nullopt;
190 }
191 if (needle.size() > haystack.size()) {
192 return nullopt;
193 }
194 ensure(needle.size() <= haystack.size(), "BAD SIZE COMP");
195 bool skip = false;
196 for (size_t i = 0; i < haystack.size() - needle.size() + 1; ++i) {
197 if (skip) {
198 skip = false;
199 continue;
200 }
201 if (haystack[i] == prefix) {
202 skip = true;
203 }
204 else if (needle[0] == haystack[i]) {
205 bool looking = true;
206 for (size_t ni = 1; looking && ni < needle.size(); ++ni) {
207 if (needle[ni] != haystack[i + ni]) {
208 looking = false;
209 }
210 }
211 if (looking) {
212 return i;
213 }
214 }
215 }
216 return nullopt;
217 }
Here is the call graph for this function:

◆ first_index_not_proceeded_by() [2/2]

template<typename T>
mtcore::Optional< size_t > mtcore::slices::first_index_not_proceeded_by ( const std::remove_const_t< T > & prefix,
const std::remove_const_t< T > & needle,
const Slice< T > & haystack )

Gets the first index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.

Template Parameters
TElement stored in slice
Parameters
needleNeedle to check for
haystackHaystack to search in

Definition at line 154 of file slice_algo.hpp.

156 {
157 if (haystack.empty()) {
158 return nullopt;
159 }
160 bool skip = false;
161 for (size_t i = 0; i < haystack.size(); ++i) {
162 if (skip) {
163 skip = false;
164 continue;
165 }
166 if (haystack[i] == prefix) {
167 skip = true;
168 }
169 else if (needle == haystack[i]) {
170 return i;
171 }
172 }
173 return nullopt;
174 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ indexes_of() [1/2]

template<typename T>
SearchIndexes< T, Slice< T > > mtcore::slices::indexes_of ( const Slice< T > & needle,
const Slice< T > & haystack )

Returns an iterator of all indexes of occurrences of a needle in a haystack If the needle isn't present, will return an empty iterator.

Template Parameters
TElements to iterate
Parameters
needleNeedle to search for
haystackHaystack to search ;

Definition at line 385 of file slice_algo.hpp.

385 {
386 return {needle, haystack};
387 }

◆ indexes_of() [2/2]

template<typename T>
SearchIndexes< T, std::remove_const_t< T > > mtcore::slices::indexes_of ( const std::remove_const_t< T > & needle,
const Slice< T > & haystack )

Returns an iterator of all indexes of occurrences of a needle in a haystack If the needle isn't present, will return an empty iterator.

Template Parameters
TElements to iterate
Parameters
needleNeedle to search for
haystackHaystack to search ;

Definition at line 398 of file slice_algo.hpp.

398 {
399 return {needle, haystack};
400 }

◆ last_index() [1/2]

template<typename T>
mtcore::Optional< size_t > mtcore::slices::last_index ( const Slice< T > & needle,
const Slice< T > & haystack )

Gets the last index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.

Template Parameters
TElement stored in slice
Parameters
needleNeedle to check for
haystackHaystack to search in

Definition at line 306 of file slice_algo.hpp.

306 {
307 if (needle.empty()) {
308 mtcore_warn_trace("Empty needle provided!");
309 return nullopt;
310 }
311 if (needle.size() > haystack.size()) {
312 return nullopt;
313 }
314 ensure(needle.size() <= haystack.size(), "BAD SIZE COMP");
315 for (size_t indx = haystack.size() - needle.size() + 1; indx > 0; --indx) {
316 const auto i = indx - 1;
317 if (needle[0] == haystack[i]) {
318 bool looking = true;
319 for (size_t ni = 1; looking && ni < needle.size(); ++ni) {
320 if (needle[ni] != haystack[i + ni]) {
321 looking = false;
322 }
323 }
324 if (looking) {
325 return i;
326 }
327 }
328 }
329 return nullopt;
330 }
Here is the call graph for this function:

◆ last_index() [2/2]

template<typename T>
mtcore::Optional< size_t > mtcore::slices::last_index ( const std::remove_const_t< T > & needle,
const Slice< T > & haystack )

Gets the last index that a needle appears in the haystack, or nullopt if the needle does not appear - \(O(N^2)\) Uses the equality operator of the underlying type.

Template Parameters
TElement stored in slice
Parameters
needleNeedle to check for
haystackHaystack to search in

Definition at line 341 of file slice_algo.hpp.

341 {
342 if (haystack.empty()) {
343 return nullopt;
344 }
345 for (size_t indx = haystack.size(); indx > 0; --indx) {
346 const auto i = indx - 1;
347 if (needle == haystack[i]) {
348 return i;
349 }
350 }
351 return nullopt;
352 }
Here is the call graph for this function:

◆ mut_slice_from() [1/11]

Slice< char > mtcore::mut_slice_from ( char * cstr)
inlinenodiscard

Creates a mutable slice from a c string.

Parameters
cstrC string (must be NULL terminated)

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

584 {
585 if (!cstr) {
586 return Slice<char>{cstr, 0};
587 }
588 size_t len = 0;
589 for (; cstr[len]; ++len) {}
590 return Slice<char>{cstr, len};
591 }
A Slice which is just a pointer + length Accessing elements through the array operator will do bounds...

◆ mut_slice_from() [2/11]

Slice< char > mtcore::mut_slice_from ( char * cstr,
const size_t len )
nodiscardconstexpr

Creates a mutable slice from a string with a length.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

510{ return Slice<char>{cstr, len}; }

◆ mut_slice_from() [3/11]

Slice< char16_t > mtcore::mut_slice_from ( char16_t * cstr)
nodiscardconstexpr

Creates a mutable slice from a utf16 string in the form of a c string.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

389 {
390 if (!cstr) {
391 return Slice<char16_t>{(cstr), 0};
392 }
393 size_t len = 0;
394 for (; cstr[len]; ++len) {}
395 return Slice<char16_t>{(cstr), len};
396 }

◆ mut_slice_from() [4/11]

Slice< char16_t > mtcore::mut_slice_from ( char16_t * cstr,
size_t len )
nodiscardconstexpr

Creates a mutable slice from a utf16 string and length.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

337 {
338 return Slice<char16_t>{cstr, len};
339 }

◆ mut_slice_from() [5/11]

Slice< char32_t > mtcore::mut_slice_from ( char32_t * cstr)
nodiscardconstexpr

Creates a mutable slice from a utf32 string in the form of a c string.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

277 {
278 if (!cstr) {
279 return Slice<char32_t>{(cstr), 0};
280 }
281 size_t len = 0;
282 for (; cstr[len]; ++len) {}
283 return Slice<char32_t>{(cstr), len};
284 }

◆ mut_slice_from() [6/11]

Slice< char32_t > mtcore::mut_slice_from ( char32_t * cstr,
size_t len )
nodiscardconstexpr

Creates a mutable slice from a utf32 string and length.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

268 {
269 return Slice<char32_t>{(cstr), len};
270 }
Here is the caller graph for this function:

◆ mut_slice_from() [7/11]

Slice< char8_t > mtcore::mut_slice_from ( char8_t * cstr)
nodiscardconstexpr

Creates a mutable slice from a utf8 string in the form of a c string.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

431 {
432 if (!cstr) {
433 return Slice<char8_t>{(cstr), 0};
434 }
435 size_t len = 0;
436 for (; cstr[len]; ++len) {}
437 return Slice<char8_t>{(cstr), len};
438 }

◆ mut_slice_from() [8/11]

Slice< char8_t > mtcore::mut_slice_from ( char8_t * cstr,
size_t len )
nodiscardconstexpr

Creates a mutable slice from a utf8 string and length.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

364{ return Slice<char8_t>{cstr, len}; }

◆ mut_slice_from() [9/11]

template<typename T, size_t N>
Slice< T > mtcore::mut_slice_from ( std::array< T, N > & arr)
nodiscardconstexpr

Creates a mutable slice from an array.

Parameters
arrarray to create slice from

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

575 {
576 return Slice<T>{arr.data(), arr.size()};
577 }

◆ mut_slice_from() [10/11]

Slice< char > mtcore::mut_slice_from ( std::string & str)
inlinenodiscard

Creates a mutable slice from a string.

Parameters
strString

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

598{ return Slice<char>{str.data(), str.size()}; }

◆ mut_slice_from() [11/11]

template<typename T>
Slice< T > mtcore::mut_slice_from ( std::vector< T > & arr)
nodiscard

Creates a mutable slice from a vector.

Parameters
arrvector to create slice from

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

555 {
556 return Slice<T>{arr.data(), arr.size()};
557 }

◆ ptr()

template<typename T>
PtrIter< T > mtcore::iter::ptr ( T & r)

Generic pointer iterator that uses the operator[] and incrementing indexes to iterate over a collection Returns pointers to elements inside the collection (can be modified)

Template Parameters
TCollection type to iterate over
Parameters
rCollection to iterate over
Returns
A pointer iterator over a collection

Definition at line 101 of file iter.hpp.

101 {
102 return {r};
103 }
Here is the caller graph for this function:

◆ slice_from() [1/20]

Slice< const char > mtcore::slice_from ( char * cstr)
nodiscardconstexpr

Creates a slice from a string in the form of a c string.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

473 {
474 if (!cstr) {
475 return Slice<const char>{static_cast<const char *>(cstr), 0};
476 }
477 size_t len = 0;
478 for (; cstr[len]; ++len) {}
479 return Slice<const char>{static_cast<const char *>(cstr), len};
480 }

◆ slice_from() [2/20]

Slice< const char > mtcore::slice_from ( char * cstr,
const size_t len )
nodiscardconstexpr

Creates a slice from a string with a length.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

501 {
502 return Slice<const char>{static_cast<const char *>(cstr), len};
503 }

◆ slice_from() [3/20]

Slice< const char16_t > mtcore::slice_from ( char16_t * cstr)
nodiscardconstexpr

Creates a slice from a utf16 string in the form of a c string.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

403 {
404 if (!cstr) {
405 return Slice<const char16_t>{static_cast<const char16_t *>(cstr), 0};
406 }
407 size_t len = 0;
408 for (; cstr[len]; ++len) {}
409 return Slice<const char16_t>{static_cast<const char16_t *>(cstr), len};
410 }

◆ slice_from() [4/20]

Slice< const char16_t > mtcore::slice_from ( char16_t * cstr,
size_t len )
nodiscardconstexpr

Creates a slice from a utf16 string and length.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

346 {
347 return Slice<const char16_t>{static_cast<const char16_t *>(cstr), len};
348 }

◆ slice_from() [5/20]

Slice< const char32_t > mtcore::slice_from ( char32_t * cstr)
nodiscardconstexpr

Creates a slice from a utf32 string in the form of a c string.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

291 {
292 if (!cstr) {
293 return Slice<const char32_t>{static_cast<const char32_t *>(cstr), 0};
294 }
295 size_t len = 0;
296 for (; cstr[len]; ++len) {}
297 return Slice<const char32_t>{static_cast<const char32_t *>(cstr), len};
298 }
Here is the caller graph for this function:

◆ slice_from() [6/20]

Slice< const char32_t > mtcore::slice_from ( char32_t * cstr,
size_t len )
nodiscardconstexpr

Creates a slice from a utf32 string and length.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

305 {
306 return Slice<const char32_t>{static_cast<const char32_t *>(cstr), len};
307 }

◆ slice_from() [7/20]

Slice< const char8_t > mtcore::slice_from ( char8_t * cstr)
nodiscardconstexpr

Creates a slice from a utf8 string in the form of a c string.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

445 {
446 if (!cstr) {
447 return Slice<const char8_t>{static_cast<const char8_t *>(cstr), 0};
448 }
449 size_t len = 0;
450 for (; cstr[len]; ++len) {}
451 return Slice<const char8_t>{static_cast<const char8_t *>(cstr), len};
452 }

◆ slice_from() [8/20]

Slice< const char8_t > mtcore::slice_from ( char8_t * cstr,
size_t len )
nodiscardconstexpr

Creates a slice from a utf8 string and length.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

371 {
372 return Slice<const char8_t>{static_cast<const char8_t *>(cstr), len};
373 }

◆ slice_from() [9/20]

Slice< const char > mtcore::slice_from ( const char * cstr)
nodiscardconstexpr

Creates a slice from a string in the form of a c string.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

487 {
488 if (!cstr) {
489 return Slice<const char>{cstr, 0};
490 }
491 size_t len = 0;
492 for (; cstr[len]; ++len) {}
493 return Slice<const char>{cstr, len};
494 }

◆ slice_from() [10/20]

Slice< const char > mtcore::slice_from ( const char * cstr,
const size_t len )
nodiscardconstexpr

Creates a slice from a string with a length.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

517 {
518 return Slice<const char>{cstr, len};
519 }

◆ slice_from() [11/20]

Slice< const char16_t > mtcore::slice_from ( const char16_t * cstr)
nodiscardconstexpr

Creates a slice from a utf16 string in the form of a c string.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

417 {
418 if (!cstr) {
419 return Slice<const char16_t>{cstr, 0};
420 }
421 size_t len = 0;
422 for (; cstr[len]; ++len) {}
423 return Slice<const char16_t>{cstr, len};
424 }

◆ slice_from() [12/20]

Slice< const char16_t > mtcore::slice_from ( const char16_t * cstr,
size_t len )
nodiscardconstexpr

Creates a slice from a utf16 string and length.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

355 {
356 return Slice<const char16_t>{cstr, len};
357 }

◆ slice_from() [13/20]

Slice< const char32_t > mtcore::slice_from ( const char32_t * cstr)
nodiscardconstexpr

Creates a slice from a utf32 string in the form of a c string.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

323 {
324 if (!cstr) {
325 return Slice<const char32_t>{cstr, 0};
326 }
327 size_t len = 0;
328 for (; cstr[len]; ++len) {}
329 return Slice<const char32_t>{cstr, len};
330 }

◆ slice_from() [14/20]

Slice< const char32_t > mtcore::slice_from ( const char32_t * cstr,
size_t len )
nodiscardconstexpr

Creates a slice from a utf32 string and length.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

314 {
315 return Slice<const char32_t>{cstr, len};
316 }

◆ slice_from() [15/20]

Slice< const char8_t > mtcore::slice_from ( const char8_t * cstr)
nodiscardconstexpr

Creates a slice from a utf8 string in the form of a c string.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

459 {
460 if (!cstr) {
461 return Slice<const char8_t>{cstr, 0};
462 }
463 size_t len = 0;
464 for (; cstr[len]; ++len) {}
465 return Slice<const char8_t>{cstr, len};
466 }

◆ slice_from() [16/20]

Slice< const char8_t > mtcore::slice_from ( const char8_t * cstr,
size_t len )
nodiscardconstexpr

Creates a slice from a utf8 string and length.

Parameters
cstrC string to create slice from (must be NULL terminated)

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

380 {
381 return Slice<const char8_t>{cstr, len};
382 }

◆ slice_from() [17/20]

template<typename T, size_t N>
Slice< std::add_const_t< T > > mtcore::slice_from ( const std::array< T, N > & arr)
nodiscardconstexpr

Creates a slice from an array.

Parameters
arrarray to create slice from

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

565 {
566 return Slice<std::add_const_t<T>>{static_cast<std::add_pointer_t<std::add_const_t<T>>>(arr.data()), arr.size()};
567 }

◆ slice_from() [18/20]

Slice< const char > mtcore::slice_from ( const std::string & str)
inlinenodiscard

Creates a slice from a std::string.

Parameters
strstring to create slice from

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

526 {
527 return Slice<const char>{str.c_str(), str.size()};
528 }

◆ slice_from() [19/20]

Slice< const char > mtcore::slice_from ( const std::string_view & sv)
nodiscardconstexpr

Creates a slice from a std::string_view.

Parameters
svstring to create slice from

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

535 {
536 return Slice<const char>{&sv[0], sv.size()};
537 }

◆ slice_from() [20/20]

template<typename T>
Slice< std::add_const_t< T > > mtcore::slice_from ( const std::vector< T > & arr)
nodiscard

Creates a slice from a vector.

Parameters
arrarray to create slice from

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

545 {
546 return Slice<std::add_const<T>>{static_cast<std::add_pointer_t<std::add_const_t<T>>>(arr.data()), arr.size()};
547 }

◆ split() [1/2]

template<typename T>
SplitIter< T, Slice< T > > mtcore::slices::split ( const Slice< T > & needle,
const Slice< T > & haystack )

Splits a slice into smaller sub slices.

Returns an iterator that iterates over each sub slice. Does NOT return the needle separating each sub slice (so some sub slices may be empty if the needle is sequential)

Template Parameters
TElements to iterate
Parameters
needleNeedle to search for
haystackHaystack to search ;

Definition at line 474 of file slice_algo.hpp.

474 {
475 return {needle, haystack};
476 }

◆ split() [2/2]

template<typename T>
SplitIter< T, std::remove_const_t< T > > mtcore::slices::split ( const std::remove_const_t< T > & needle,
const Slice< T > & haystack )

Splits a slice into smaller sub slices.

Returns an iterator that iterates over each sub slice. Does NOT return the needle separating each sub slice (so some sub slices may be empty if the needle is sequential)

Template Parameters
TElements to iterate
Parameters
needleNeedle to search for
haystackHaystack to search ;

Definition at line 487 of file slice_algo.hpp.

487 {
488 return {needle, haystack};
489 }

◆ starts_with() [1/2]

template<typename T>
bool mtcore::slices::starts_with ( const Slice< T > & needle,
const Slice< T > & haystack )

Checks whether a slice (the haystack) starts with elements in another slice in the same order (the needle) - \(O(N)\) Uses the equality operator of the underlying type E.g.

"hello" starts with "he", so this would return true E.g. "hello" does not start with "ll", so this would return false

Template Parameters
TElement stored in slice
Parameters
needleNeedle to check for
haystackHaystack to search in

Definition at line 40 of file slice_algo.hpp.

40 {
41 if (needle.empty()) {
42 mtcore_warn_trace("Empty needle provided!");
43 return false;
44 }
45 if (needle.size() > haystack.size()) {
46 return false;
47 }
48 ensure(needle.size() <= haystack.size(), "BAD SIZE COMP");
49 for (size_t i = 0; i < needle.size(); ++i) {
50 if (needle[i] != haystack[i]) {
51 return false;
52 }
53 }
54 return true;
55 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ starts_with() [2/2]

template<typename T>
bool mtcore::slices::starts_with ( const std::remove_const_t< T > & needle,
const Slice< T > & haystack )

Checks whether a slice (the haystack) starts with a specific element (the needle) - \(O(N)\) Uses the equality operator of the underlying type E.g.

"hello" starts with 'h', so this would return true E.g. "hello" does not start with 'l', so this would return false

Template Parameters
TElement stored in slice
Parameters
needleNeedle to check for
haystackHaystack to search in

Definition at line 80 of file slice_algo.hpp.

80 {
81 if (haystack.empty()) {
82 return false;
83 }
84 return haystack[0] == needle;
85 }
Here is the call graph for this function:

◆ val()

template<typename T>
ValIter< T > mtcore::iter::val ( const T & r)

Generic value iterator that uses the operator[] and incrementing indexes to iterate over a collection Does copies when iterating`.

Template Parameters
TCollection type to iterate over
Parameters
rCollection to iterate over
Returns
A value iterator over a collection

Definition at line 114 of file iter.hpp.

114 {
115 return {r};
116 }
Here is the caller graph for this function:

Variable Documentation

◆ nullopt

auto mtcore::nullopt = Nullopt{}
constexpr

Placeholder value for an empty Optional.

Definition at line 409 of file optional.hpp.

409{};