Skip to content

Commit

Permalink
Merge pull request #176 from justusc/justusc/consolidate-has-data
Browse files Browse the repository at this point in the history
Consolidate has_data and has_data_v
  • Loading branch information
evaleev authored Sep 22, 2024
2 parents b3e4506 + a531387 commit f3d7010
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 f3d7010

Please sign in to comment.