Adding concept to a part of the code#2842
Conversation
JohanMabille
left a comment
There was a problem hiding this comment.
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.
| 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> |
|
|
||
|
|
||
| template<class E> | ||
| concept is_xscalar_concept = is_xscalar<std::decay_t<E>>::value; |
There was a problem hiding this comment.
Nitpicking: xscalar_concept would be more consistent with the other names.
|
#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 constexprto a moderatly large chunk ofxtensor.