Summary: | Reducing copies of nestByValue() | ||
---|---|---|---|
Product: | Eigen | Reporter: | Gael Guennebaud <gael.guennebaud> |
Component: | Core - expression templates | Assignee: | Nobody <eigen.nobody> |
Status: | NEW --- | ||
Severity: | Optimization | CC: | chtz, gael.guennebaud, jacob.benoit.1 |
Priority: | Normal | ||
Version: | unspecified | ||
Hardware: | All | ||
OS: | All | ||
Whiteboard: |
Description
Gael Guennebaud
2019-01-17 22:04:06 UTC
With the aforementioned changes we could even get rid of explicit nestByValue() by introducing them implicitly when detecting a rvalue ref of type T for which T usually prefers to be nested by reference. The user would still have to turn named local temporaries into a xvalue using move(). To this end we could define two helpers (not tested): template<typename T> using nest_by_value_t = typename conditional<prefer_nesting_by_ref<T>::value,NestByValue<T>,T>::type; template<typename T, typename = enable_if<prefer_nesting_by_ref<T>::value> > auto nest_by_value(T&& x) { return NestByValue<T>(std::move(x)); } template<typename T, typename = enable_if<!prefer_nesting_by_ref<T>::value> > T&& nest_by_value(T&& x) { return std::move(x); } Then, for instance, in operator+: auto DenseBase<Derived>::operator+(DenseStorage<Other> &&other) && { return CwiseBinaryOp<scalar_sum_op<...>, const nest_by_value_t<Derived>, const nest_by_value_t<Other> >( nest_by_value(std::move(derived())), nest_by_value(std::move(other.derived())) ); } -- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1663. |