Skip to content

Add rvalue overload for xcontainer::storage #2401

@AntoinePrv

Description

@AntoinePrv

Motivation

It can make sense for users to move the data/storage out of an xcontainer (for instance statically reshape an xt::xtensor<T, N> to an xt::xtensor<T, 1>).

Right now, we can do

xtensor<T,  1> new_tensor{std::move(old_tensor.storage()),  {old_tensor.size()}, {1}};

But, as suggested by @JohanMabille, we cannot do

xtensor<T, 1> new_tensor(std::move(old_tensor).storage(), ...);

Or

xtensor<T, 2> some_func(....);
xtensor<T, 1> new_tensor(some_func().storage(), ...);

Proposed Implementation

Add one of the following overload to xcontainer:
- a/ storage_type&& storage() noexcept&&;
- b/ storage_type storage() noexcept&&;

I can send a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions