This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Another quirk?


Compile the following code, once with -DCONST=const and once without
the define.  The first will succeed, the second doesn't.

I know why this happens.  With the const valarray references to the
original array can be kept and no copies have to be made.  In fact,
when I introduce an intermediate variable of type valarray<int> and
use the result of the slice operation to initialize it and then use
sum() with the new variable everything works fine, too.

The question is: is this really the intended behavior?  I seems like
the conversion from std::slice_array<Tp> to std::valarray<Tp> should
happen implicitly and thus allowing the original code to work.

Comments?  I'll file a bug in case my expectation is correct.

#include <valarray>
#include <iostream>

#ifndef CONST
#define CONST
#endif

int main() {
  static const int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  constexpr size_t narr = sizeof(arr) / sizeof(arr[0]);
  CONST std::valarray<int> va(arr, narr);
  std::cout << va[std::slice(0, 3, 4)].sum() << std::endl;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]