Skip to content

Is the reference returned by operator[] to restrictive? #43

@krzikalla

Description

@krzikalla

By disallowing a binding of simd<>::reference to an lvalue the code below (ref. https://godbolt.org/z/7qW8bffe5) becomes clumsy:

#include <iostream>
#include <experimental/simd>

namespace stdx = std::experimental;

void foo(auto&& x)
{
    std::forward<decltype(x)>(x) = .2;
    //x = .3;
}

int main()
{
  stdx::simd<double> x = 0;
  x[0] = .1;
  foo(x[1]);
  for (int i = 0; i < x.size(); ++i) std::cout << x[i] << ' ';
}

The x = .3 clause doesn't compile, since the assignment is declared as reference::operator=(...) && and x is an lvalue. Why is the operator= restricted to rvalues?
Is it known, that the above code becomes clumsy by this restriction?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions