diff options
author | George L. Albany <Megacake1234@gmail.com> | 2024-06-18 19:43:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-18 19:43:20 +0200 |
commit | 8b623bf4087aa360842ad31145d4ab6946cee9aa (patch) | |
tree | f15ebc47d6bf370031af28e4bb4814ae30ef46e1 /include/openvic-dataloader/detail/Concepts.hpp | |
parent | 7b521d6023113372cf6b02e562828273c4040f0e (diff) | |
parent | b0c3ba3f91926b0c95625bdbf4aab69269130b13 (diff) |
Merge pull request #46 from OpenVicProject/fix/char-detection
Add runtime encoding detection and conversion
Diffstat (limited to 'include/openvic-dataloader/detail/Concepts.hpp')
-rw-r--r-- | include/openvic-dataloader/detail/Concepts.hpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/include/openvic-dataloader/detail/Concepts.hpp b/include/openvic-dataloader/detail/Concepts.hpp new file mode 100644 index 0000000..79e04a9 --- /dev/null +++ b/include/openvic-dataloader/detail/Concepts.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include <concepts> +#include <cstdint> +#include <functional> +#include <utility> + +namespace ovdl { + struct File; + namespace detail { + enum class buffer_error : std::uint8_t; + } +} + +namespace ovdl::detail { + template<typename T, typename... Ts> + concept any_of = std::disjunction_v<std::is_same<T, Ts>...>; + + template<typename T> + concept HasCstr = + requires(T t) { + { t.c_str() } -> std::same_as<const char*>; + }; + + template<typename T> + concept HasPath = requires(T& t) { + { t.path() } -> std::same_as<const char*>; + }; + + template<typename T, typename Self, typename... Args> + concept LoadCallback = + requires(T&& t, Self&& self, Args&&... args) { + { std::invoke(std::forward<T>(t), std::forward<Self>(self), std::forward<Args>(args)...) } -> std::same_as<ovdl::detail::buffer_error>; + }; + + template<typename T> + concept IsEncoding = requires(T t) { + typename T::char_type; + typename T::int_type; + { T::template is_secondary_char_type<typename T::char_type>() } -> std::same_as<bool>; + { T::eof() } -> std::same_as<typename T::int_type>; + { T::to_int_type(typename T::char_type {}) } -> std::same_as<typename T::int_type>; + }; + + template<typename T, typename R, typename... Args> + concept Invocable_R = std::invocable<T, Args...> && requires(Args&&... args) { + { invoke(forward<Args>(args)...) } -> std::convertible_to<R>; + }; +}
\ No newline at end of file |