Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate has_data and has_data_v #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading