Skip to content

Commit

Permalink
feat: add array specialization for string_traits
Browse files Browse the repository at this point in the history
  • Loading branch information
DNKpp committed Oct 3, 2024
1 parent b5e80cc commit 4ab89bd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
25 changes: 24 additions & 1 deletion include/mimic++/TypeTraits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,22 +675,45 @@ namespace mimicpp
* \{
*/

/**
* \brief Specialization for character pointer types.
* \tparam T Type to check.
*/
template <typename T>
requires std::is_pointer_v<T>
&& is_character_v<std::remove_const_t<std::remove_pointer_t<T>>>
&& is_character_v<std::remove_cv_t<std::remove_pointer_t<T>>>
struct string_traits<T>
{
using char_t = std::remove_const_t<std::remove_pointer_t<T>>;
using string_t = std::basic_string_view<char_t>;
};

/**
* \brief Specialization for character array types.
* \tparam T Type to check.
*/
template <typename T>
requires std::is_array_v<T>
struct string_traits<T>
: public string_traits<std::remove_extent_t<T>*>
{
};

/**
* \brief Specialization for ``std::basic_string`` types.
* \tparam T Type to check.
*/
template <typename Char, typename Traits, typename Allocator>
struct string_traits<std::basic_string<Char, Traits, Allocator>>
{
using char_t = Char;
using string_t = std::basic_string<Char, Traits, Allocator>;
};

/**
* \brief Specialization for ``std::basic_string_view`` types.
* \tparam T Type to check.
*/
template <typename Char, typename Traits>
struct string_traits<std::basic_string_view<Char, Traits>>
{
Expand Down
5 changes: 5 additions & 0 deletions test/unit-tests/TypeTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,11 @@ TEMPLATE_TEST_CASE_SIG(
(true, char32_t*, char32_t, std::u32string_view),
(true, const char32_t*, char32_t, std::u32string_view),

(true, char[], char, std::string_view),
(true, const char[], char, std::string_view),
(true, char[42], char, std::string_view),
(true, const char[42], char, std::string_view),

(true, std::string, char, std::string),
(true, std::wstring, wchar_t, std::wstring),
(true, std::u8string, char8_t, std::u8string),
Expand Down

0 comments on commit 4ab89bd

Please sign in to comment.