Skip to content

Commit

Permalink
type_traits: Separate type traits helpers into a new header file
Browse files Browse the repository at this point in the history
This commit adds cista/type_traits.h and move is_char_array_helper and
is_string_helper into that new header file.
  • Loading branch information
khng300 committed Oct 16, 2023
1 parent e5a58c7 commit 4bb13ed
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
Binary file not shown.
Binary file not shown.
7 changes: 1 addition & 6 deletions include/cista/containers/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string_view>

#include "cista/containers/ptr.h"
#include "cista/type_traits.h"

namespace cista {

Expand Down Expand Up @@ -421,9 +422,6 @@ struct basic_string_view : public generic_string<Ptr> {
}
};

template <typename Ptr>
struct is_string_helper : std::false_type {};

template <typename Ptr>
struct is_string_helper<generic_string<Ptr>> : std::true_type {};

Expand All @@ -433,9 +431,6 @@ struct is_string_helper<basic_string<Ptr>> : std::true_type {};
template <typename Ptr>
struct is_string_helper<basic_string_view<Ptr>> : std::true_type {};

template <class T>
constexpr bool is_string_v = is_string_helper<std::remove_cv_t<T>>::value;

namespace raw {
using generic_string = generic_string<ptr<char const>>;
using string = basic_string<ptr<char const>>;
Expand Down
13 changes: 1 addition & 12 deletions include/cista/hashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "cista/hash.h"
#include "cista/is_iterable.h"
#include "cista/reflection/for_each_field.h"
#include "cista/type_traits.h"

namespace cista {

Expand Down Expand Up @@ -50,18 +51,6 @@ template <typename A, typename B>
constexpr bool is_hash_equivalent_v =
is_hash_equivalent_helper<std::remove_cv_t<A>, std::remove_cv_t<B>>::value;

template <typename T, typename = void>
struct is_char_array_helper : std::false_type {};

template <std::size_t N>
struct is_char_array_helper<char const[N]> : std::true_type {};

template <std::size_t N>
struct is_char_array_helper<char[N]> : std::true_type {};

template <typename T>
constexpr bool is_char_array_v = is_char_array_helper<T>::value;

template <typename T>
constexpr bool is_string_like_v =
is_string_v<std::remove_cv_t<T>> || is_char_array_v<T> ||
Expand Down
25 changes: 25 additions & 0 deletions include/cista/type_traits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <type_traits>

namespace cista {

template <typename T, typename = void>
struct is_char_array_helper : std::false_type {};

template <std::size_t N>
struct is_char_array_helper<char const[N]> : std::true_type {};

template <std::size_t N>
struct is_char_array_helper<char[N]> : std::true_type {};

template <typename T>
constexpr bool is_char_array_v = is_char_array_helper<T>::value;

template <typename Ptr>
struct is_string_helper : std::false_type {};

template <class T>
constexpr bool is_string_v = is_string_helper<std::remove_cv_t<T>>::value;

} // namespace cista

0 comments on commit 4bb13ed

Please sign in to comment.