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

Remove Impl::enable_if_type #3863

Merged
merged 6 commits into from
Mar 24, 2021

Conversation

dalg24
Copy link
Member

@dalg24 dalg24 commented Mar 19, 2021

Rational: You are probably wondering: "What is enable_if_type anyway?" Well we were not using it much, I could not find it in any other packages in Trilinos, and part of its functionality is superseded by std::void_t. I opted for removal and ended up rewriting FunctorPolicyExecutionSpace.

I know some of us would like to go further and add the detection idiom but let's not address this here.

@dalg24 dalg24 requested review from dhollman and nliber March 19, 2021 20:30
Copy link
Contributor

@nliber nliber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@dalg24 dalg24 force-pushed the replace_enable_if_type_by_void_t branch from e6c2ff4 to faf8538 Compare March 22, 2021 15:55
@dalg24
Copy link
Member Author

dalg24 commented Mar 22, 2021

Squashed the fixup commits and rebased. No changes.

Copy link
Contributor

@masterleinad masterleinad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable.

Copy link

@dhollman dhollman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine as is, but there are a few changes. I do actually think enable_if_type is a more descriptive name than void_t. (Both do the same thing, so one way this pull request could have gone is to just rename enable_if_type to use void_t). I think maybe enable_if_valid_type is a better name, or something like check_for_type_in_sfinae_safe_context is probably even better. I don't know that this is super important (I don't know that it's as bad as it looks as is), but it's slightly more reasonable and modern so I approve,

Comment on lines +75 to +81
#if defined(__cpp_lib_void_t)
// since C++17
using std::void_t;
#else
template <class...>
using void_t = void;
#endif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not confident this works on all of the compilers we support (particularly Intel 17)

Comment on lines +75 to +103
template <class T, class = void>
struct is_detected_execution_space : std::false_type {
using type = not_a_type;
};

template <class T>
struct is_detected_execution_space<T, void_t<typename T::execution_space>>
: std::true_type {
using type = typename T::execution_space;
};

template <class T>
using detected_execution_space_t =
typename is_detected_execution_space<T>::type;

template <class T, class = void>
struct is_detected_device_type : std::false_type {
using type = not_a_type;
};

template <class T>
struct is_detected_device_type<T, void_t<typename T::device_type>>
: std::true_type {
using type = typename T::device_type;
};

template <class T>
using detected_device_type_t = typename is_detected_device_type<T>::type;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just put is_detected in directly instead of making special versions of each of these?

Comment on lines +68 to +73
struct not_a_type {
not_a_type() = delete;
~not_a_type() = delete;
not_a_type(not_a_type const&) = delete;
void operator=(not_a_type const&) = delete;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking and super minor: In detection idiom, this is usually named nonesuch. By convention in metaprogramming (for whatever reason), not_a_type (or nat sometimes) is usually just an undefined type or completely empty at the least.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can rename when we add the detection idiom

@dhollman
Copy link

As an alternative, I propose renaming and slightly modifying enable_if_type to be something like:

template <class...>
using sfinae_safe_context_to_check_for_valid_type = void;

@dalg24 dalg24 merged commit 35ac318 into kokkos:develop Mar 24, 2021
@dalg24 dalg24 deleted the replace_enable_if_type_by_void_t branch March 24, 2021 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants