Skip to content

Commit

Permalink
Consolidate has_data and has_data_v
Browse files Browse the repository at this point in the history
There are two separate implementations for `has_data` and `has_data_v` that do the same thing. This change combines those implementations.
  • Loading branch information
justusc committed Apr 16, 2024
1 parent 20167a3 commit a531387
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
14 changes: 0 additions & 14 deletions btas/tensor_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@

namespace btas {

/// test T has data() member
/// this will be used to detect whether or not the storage is consecutive
template<class T>
class has_data {
/// true case
template<class U>
static auto __test(U* p) -> decltype(p->data(), std::true_type());
/// false case
template<class>
static std::false_type __test(...);
public:
static constexpr const bool value = std::is_same<std::true_type, decltype(__test<T>(0))>::value;
};

/// test T has range_type
template<class T>
class has_range_type {
Expand Down
20 changes: 16 additions & 4 deletions btas/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,22 @@ namespace btas {
template <typename T>
constexpr inline bool has_squarebraket_v = has_squarebraket<T>::value;

template <typename S, typename Enabler = void>
constexpr static bool has_data_v = false;
template <typename S>
constexpr static bool has_data_v<S, std::void_t<decltype(std::declval<S&>().data())>> = true;
/// test T has data() member
/// this will be used to detect whether or not the storage is consecutive
template<class T>
class has_data {
/// true case
template<class U>
static auto __test(U* p) -> decltype(p->data(), std::true_type());
/// false case
template<class>
static std::false_type __test(...);
public:
static constexpr const bool value = std::is_same<std::true_type, decltype(__test<T>(0))>::value;
};

template <typename T>
inline constexpr bool has_data_v = has_data<T>::value;

template <typename S, typename Enabler = void>
constexpr static bool has_size_v = false;
Expand Down

0 comments on commit a531387

Please sign in to comment.