From 18ae278e27b9d7b4a068a0dd88c046d5b7cb618b Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Tue, 31 Aug 2021 11:23:33 +0200 Subject: [PATCH] MISC: Add the string trait --- src/Lib/Utils.hh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Lib/Utils.hh b/src/Lib/Utils.hh index 9c223677..66d6507c 100644 --- a/src/Lib/Utils.hh +++ b/src/Lib/Utils.hh @@ -26,6 +26,7 @@ // Use chrono instead of std::chrono... namespace chrono = std::chrono; +using chrono::duration_cast; // Prety define for OpenMP's parallel for loop with indentation not fucked up // by clang-format. @@ -58,8 +59,23 @@ concept PropertyConstViewable = requires(T element) // clang-format on }; +// Concept with a better name for inheritence between types template <class T, class U> concept Derived = std::is_base_of<U, T>::value; + +// Concept for string things +template <typename T> +concept StringType = requires(T str) +{ + // clang-format off + typename T::iterator; // Can iterate + typename T::value_type; // The `Char` + { str.size() } -> std::convertible_to<std::size_t>; + { str.begin() } -> std::same_as<typename T::iterator>; + { str.end() } -> std::same_as<typename T::iterator>; + { str[0] } -> std::same_as<typename T::value_type>; + // clang-format on +}; } namespace Vivy::Utils -- GitLab