Skip to content

Adding concept to a part of the code (part 2) #2846

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

alexandrehoffmann
Copy link
Contributor

Checklist

  • [ X] The title and commit message(s) are descriptive.
  • [ X] Small commits made to fix your PR have been squashed to avoid history pollution.
  • [ X] Tests have been added for new features or bug fixes.
  • API of new functions and classes are documented.

Description

This PR C++20's concept and C++17's if constexpr to a moderatly large chunk of xtensor.

Alexandre Hoffmann added 2 commits April 15, 2025 13:58
inline std::enable_if_t<!std::is_pointer<T>::value, T> xaxis_iterator<CT>::get_storage_init(CTA&& e) const
{
return e;
if constexpr (std::is_pointer<T>::value)
Copy link
Member

Choose a reason for hiding this comment

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

Nitpicking: std::is_pointer_v<T>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no stl concept for pointer, maybe I can create one for the xtl and use it.

{
return e;
if constexpr (std::is_pointer<T>::value)
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

operator xrange<S>() const noexcept;
template <class S>
operator xrange<S>() const noexcept
requires std::convertible_to<S, T>;
Copy link
Member

Choose a reason for hiding this comment

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

You can shorten the declaration with:

template <std::convertible_to<T> S>
operator xrange<S>() const noexcept;

Here S will be passed as the first argument of the concept used in the type constraint.

xrange<S> convert() const noexcept;
template <class S>
xrange<S> convert() const noexcept
requires std::convertible_to<S, T>;
Copy link
Member

Choose a reason for hiding this comment

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

Same remark here.

operator xstepped_range<S>() const noexcept;
template <class S>
operator xstepped_range<S>() const noexcept
requires std::convertible_to<S, T>;
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

inline xdrop_slice<T>::operator xdrop_slice<S>() const noexcept
requires std::convertible_to<S, T>
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

inline xdrop_slice<S> xdrop_slice<T>::convert() const noexcept
requires std::convertible_to<S, T>
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@@ -180,6 +180,9 @@ namespace xt
using simd_value_type = xt_simd::simd_type<value_type>;
using bool_load_type = typename base_type::bool_load_type;

static constexpr bool providedSimdInterface = has_simd_interface<xexpression_type>::value
Copy link
Member

Choose a reason for hiding this comment

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

This should be snake_case ;)

XTENSOR_ASSERT(std::count(shape.cbegin(), shape.cend(), -1) <= 1);
auto iter = std::find(shape.begin(), shape.end(), -1);
if (iter != std::end(shape))
if constexpr (std::is_signed<get_value_type_t<typename std::decay<S>::type>>::value)
Copy link
Member

Choose a reason for hiding this comment

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

You can use std::is_signed_v

@@ -133,6 +133,9 @@ namespace xt
static constexpr bool contiguous_layout = static_layout != layout_type::dynamic
&& xexpression_type::contiguous_layout;

static constexpr bool
providedDataInterface = detail::provides_data_interface<xexpression_type, storage_type>::value;
Copy link
Member

Choose a reason for hiding this comment

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

This should be snake_case ;)

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.

2 participants