-
Notifications
You must be signed in to change notification settings - Fork 409
Adding concept to a part of the code #2842
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
Adding concept to a part of the code #2842
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When all the enable_if have been replaced, I think we can start removing most of the metafunction used in the concept definitinos, and defined the concept with specific C++20 syntax:
template <class E>
concept has_simd_interface = requires(R e, size_t i)
{
e.load_simd(i);
e.store_simd(i, E::vaue_type());
};
That should be done in a dedicated PR.
@@ -64,7 +56,7 @@ namespace xt | |||
explicit uvector(size_type count, const allocator_type& alloc = allocator_type()); | |||
uvector(size_type count, const_reference value, const allocator_type& alloc = allocator_type()); | |||
|
|||
template <class InputIt, class = detail::require_input_iter<InputIt>> | |||
template <input_iterator_concept InputIt> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use std::input_iterator instead ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed in commit 4809115
|
||
|
||
template<class E> | ||
concept is_xscalar_concept = is_xscalar<std::decay_t<E>>::value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking: xscalar_concept
would be more consistent with the other names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed in last commit #4809115
#2839 must be merged for the CI |
Git pre-commit tends to switch |
f60fdd8
to
39ceaa7
Compare
@alexandrehoffmann @JohanMabille Great work! Concept are a great match for this library! When looking into views I found that the concepts of linear assignment and data interface ( |
31819cf
to
f959b36
Compare
Ok so, as for now, clang doesn't allow to implement methods outside of the class scope if said method uses concepts. template <class CT, class... S>
template <class T>
requires(has_data_interface_concept<T> and strided_view_concept<CT, S...>)
auto xview<CT, S...>::linear_begin() -> linear_iterator
{
return m_e.storage().begin() + data_offset();
} does not compile with clang but template <class CT, class... S>
class xview
{
[...]
template <class T = xexpression_type>
requires has_data_interface_concept<T> and strided_view_concept<CT, S...>
const_linear_iterator linear_begin() const { return m_e.storage().begin() + data_offset(); }
[...]
}; does. To me the two options are |
Does the trailing requires syntax work ? I.e. something like template <class CT, class... S>
template <class T>
auto xview<CT, S...>::linear_begin() -> linear_iterator
requires(has_data_interface_concept<T> and strided_view_concept<CT, S...>)
{
return m_e.storage().begin() + data_offset();
} |
Unfortunately is does not, at least on my side:
A possible solution would be to forward declare and then fully declare within the class e.g. : template <class CT, class... S>
class xview
{
/////////// declaration zone
[...]
template <class T = xexpression_type>
requires has_data_interface_concept<T> and strided_view_concept<CT, S...>
const_linear_iterator linear_begin() const;
[...]
/////////// definition zone
template <class T = xexpression_type>
requires has_data_interface_concept<T> and strided_view_concept<CT, S...>
const_linear_iterator linear_begin() const { return m_e.storage().begin() + data_offset(); }
}; |
I think it's a good compromise. |
So using the trailing requires works for most compilers but not clang-17 and 18 |
Awesome, thanks! |
Checklist
Description
This PR C++20's concept and C++17's
if constexpr
to a moderatly large chunk ofxtensor
.