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

protected xcontainer::derived_cast #627

Merged
merged 1 commit into from Feb 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 24 additions & 15 deletions include/xtensor/xcontainer.hpp
Expand Up @@ -311,6 +311,12 @@ namespace xt
container_iterator data_xend(layout_type l) noexcept;
const_container_iterator data_xend(layout_type l) const noexcept;

protected:

derived_type& derived_cast() & noexcept;
const derived_type& derived_cast() const & noexcept;
derived_type derived_cast() && noexcept;

private:

friend class xiterable<D>;
Expand All @@ -325,9 +331,6 @@ namespace xt
inner_shape_type& mutable_shape();
inner_strides_type& mutable_strides();
inner_backstrides_type& mutable_backstrides();

derived_type& derived_cast();
const derived_type& derived_cast() const;
};

#undef DL
Expand Down Expand Up @@ -434,18 +437,6 @@ namespace xt
return derived_cast().backstrides_impl();
}

template <class D>
inline auto xcontainer<D>::derived_cast() -> derived_type&
{
return *static_cast<derived_type*>(this);
}

template <class D>
inline auto xcontainer<D>::derived_cast() const -> const derived_type&
{
return *static_cast<const derived_type*>(this);
}

/**
* @name Size and shape
*/
Expand Down Expand Up @@ -1096,6 +1087,24 @@ namespace xt
return data_xend_impl(data().end(), l);
}

template <class D>
inline auto xcontainer<D>::derived_cast() & noexcept -> derived_type&
{
return *static_cast<derived_type*>(this);
}

template <class D>
inline auto xcontainer<D>::derived_cast() const & noexcept -> const derived_type&
{
return *static_cast<const derived_type*>(this);
}

template <class D>
inline auto xcontainer<D>::derived_cast() && noexcept -> derived_type
{
return *static_cast<derived_type*>(this);
}

template <class D>
inline auto xcontainer<D>::data_element(size_type i) -> reference
{
Expand Down