19#ifndef MTCORE_TRAITS_HPP
20#define MTCORE_TRAITS_HPP
46 struct VoidWriterImpl;
56 concept Ostreamable =
requires(
const T &c, std::ostream &os) {
66 { c.size() } -> std::convertible_to<size_t>;
67 { c.at(0) } -> std::convertible_to<const typename T::Elem &>;
68 { c[0] } -> std::convertible_to<const typename T::Elem &>;
78 { t.size() } -> std::convertible_to<size_t>;
79 { t.at(0) } -> std::same_as<typename T::Elem &>;
80 { t[0] } -> std::same_as<typename T::Elem &>;
90 { t.next() } -> std::same_as<Optional<typename T::IterElem>>;
93 template<
typename T,
typename... Args>
94 concept Initable =
requires(T &t, Args... args) {
114 std::begin(t) != std::end(t);
115 ++std::declval<decltype(std::begin(t)) &>();
135 concept ResultVoid =
requires() {
136 { T::from_success() } -> std::same_as<T>;
140 concept ResultValue =
141 requires(T &t,
const T &c,
const typename T::Value &v, std::remove_const_t<typename T::Value> &vo) {
142 { T::from_success(v) } -> std::same_as<T>;
143 { c.copy_if_present(vo) } -> std::same_as<bool>;
144 { t.move_if_present(vo) } -> std::same_as<bool>;
145 { c.value() } -> std::same_as<typename T::Value>;
155 concept ResultLike =
requires(T &t,
const T &c,
typename T::ErrVal e) {
156 { T::from_error(e) } -> std::same_as<T>;
157 { t == c } -> std::same_as<bool>;
158 { c != t } -> std::same_as<bool>;
159 { c.is_error() } -> std::same_as<bool>;
160 { c.is_success() } -> std::same_as<bool>;
161 { c.error() } -> std::same_as<typename T::ErrVal>;
162 } && (impl::ResultVoid<T> || impl::ResultValue<T>);
169 template<
typename T,
typename V>
171 ((impl::ResultVoid<T> && std::same_as<V, void>) || (impl::ResultValue<T> && std::same_as<typename T::Value, V>) ) &&
191 { T::ErrType::OUT_OF_ROOM };
200 { ct.bytes_written() } -> std::same_as<size_t>;
229 { T::IsWriteThrough };
241 template<WriterImpl T>
254 { T::ErrType::END_OF_FILE };
255 { T::ErrType::ALLOCATION_FAILED };
256 { T::ErrType::SIZE_EXCEEDED };
282 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
char> &&
283 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
i8> &&
284 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
i16> &&
285 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
i32> &&
286 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
i64> &&
287 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
u8> &&
288 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
u16> &&
289 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
u32> &&
290 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
u64> &&
291 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
f32> &&
292 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
f64> &&
293 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
f80> &&
294 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
char8_t> &&
295 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
char16_t> &&
296 !std::same_as<std::remove_cvref_t<std::remove_pointer_t<std::remove_cvref_t<std::decay_t<T>>>>,
char32_t>;
299 template<
typename V,
typename T>
300 struct IsResultWithValue;
301 template<
typename V, ResultLikeWithValue<V> T>
302 struct IsResultWithValue<V, T> : std::true_type {};
303 template<
typename V,
typename T>
304 struct IsResultWithValue : std::false_type {};
306 template<
typename... Args>
308 template<
typename... Args,
Initable<Args...> T>
309 struct IsInitable<T, Args...> : std::true_type {};
310 template<
typename... Args>
311 struct IsInitable : std::false_type {};
314#define MTCORE_TRAIT_ISA(Concept) \
316 template<typename T> \
317 struct Is##Concept; \
318 template<Concept T> \
319 struct Is##Concept<T> : std::true_type {}; \
320 template<typename T> \
321 struct Is##Concept : std::false_type {}; \
348 template<
typename T,
typename V>
412 template<
typename T,
typename... Args>
The Addressable trait for types Something that implements this trait allows addressing items by index...
Represents a type that has a deinit which takes an allocator (usually does memory cleanup)
Represents a type that has a default (no allocator) deinit method.
Represents a type that can be "flushed" (e.g.
The Iterable trait for types Something that implements this trait can give an iterator to iterate ove...
The Addressable trait for types Something that implements this trait allows addressing items by index...
The Addressable trait for types Something that implements this trait allows addressing items by index...
The Ostreamable trait for types Something that implements this trait allows ostream operations.
Represents an implementation of a reader (basically checks if the type can be wrapped with Reader<>)
Represents a type that fulfills the "result" contract while having a success value of a specific type...
Represents a type that fulfills the "result" contract while having no success value Does NOT check th...
Represents a type that fulfills the "result" contract.
Detect if something is C++ standard iterable.
Checks if a writer type is a write-through writer.
Represents an implementation of a writer that we can get how many bytes were written.
Represents an implementation of a writer that we can reset.
Represents an implementation of a writer that we can get the output.
Represents an implementation of a writer (basically checks if the type can be wrapped with Writer<>)
constexpr bool is_ostreamable
Boolean check for if something has the trait Iterator.
constexpr bool is_flushable
Boolean check for if something has the trait Flushable.
constexpr bool is_initable
Checks if a type has an init with the param types.
constexpr bool is_iterator
Boolean check for if something has the trait Iterator.
constexpr bool is_formattable
Checks if a type has a zero-parameter deinit.
constexpr bool is_addressable
Boolean check for if something has the trait Addressable.
constexpr bool is_allocator_deinit
Checks if a type requires an allocator to deinit.
constexpr bool is_result_with_value
Checks if a type is result-like with a success value type.
constexpr bool is_mutable_addressable
Boolean check for if something has the trait Addressable.
constexpr bool is_result_void
Checks if a type is result-like with no success value.
constexpr bool is_default_deinit
Checks if a type has a zero-parameter deinit.
uint64_t u64
Alias for 64-bit unsigned ints.
int32_t i32
Alias for 32-bit ints.
float f32
Alias for 32-bit floats.
int64_t i64
Alias for 64-bit ints.
uint8_t u8
Alias for 8-bit unsigned ints.
double f64
Alias for 64-bit floats.
long double f80
Alias for 80-bit floats.
uint16_t u16
Alias for 16-bit unsigned ints.
int16_t i16
Alias for 16-bit ints.
int8_t i8
Alias for 8-bit ints.
uint32_t u32
Alias for 32-bit unsigned ints.
Core library for C++ with Zig-related functionality.
constexpr bool is_write_through
Checks if a writer type is a write-through writer.
Represents a memory allocator Exact behavior depends on the underlying VTable used Should use the a_*...
Represents a value that may or may not exist (an "Optional" value) Similar concept to std::optional,...
A Slice which is just a pointer + length Accessing elements through the array operator will do bounds...
A writer that writes data to some sort of stream or buffer Note: the data elements written should be ...