fork download
  1. #include <valarray>
  2. using namespace std;
  3.  
  4. void foo(valarray<int>& va)
  5. {
  6. // You can't return by value to a non-const lvalue reference, it either
  7. // has to be a const lvalue reference or a (C++11) rvalue reference. In your
  8. // case it needs to be an r-value reference. Note that what's returned by
  9. // the operator is an object that has reference semantics, not a reference!
  10. //slice_array<int>& sa = va[slice(0,3,2)];
  11. slice_array<int>&& sa = va[slice(0,3,2)];
  12. sa = 98;
  13. }
  14.  
  15. int main()
  16. {
  17. valarray<int> valary(21);
  18. for(size_t i=0; i<valary.size(); ++i)
  19. {
  20. valary[i] = i;
  21. }
  22. foo(valary);
  23. }
Success #stdin #stdout 0s 3268KB
stdin
Standard input is empty
stdout
Standard output is empty