Opened 11 years ago

Last modified 10 years ago

#6793 assigned Feature Requests

Support construction from range

Reported by: Olaf van der Spek <olafvdspek@…> Owned by: Marshall Clow
Milestone: To Be Determined Component: array
Version: Boost 1.49.0 Severity: Problem
Keywords: Cc:

Description

Could you support construction from a range and from an iterator pair? I don't know what to do when the input doesn't match the array size. If it's smaller you could default construct the rest of the array. If it's larger, you could truncate, std::terminate() or throw. Or just consider it undefined behaviour.

Change History (3)

comment:1 by Olaf van der Spek <olafvdspek@…>, 11 years ago

Just read that constructors are not an option. How about make_array() instead?

comment:2 by Marshall Clow, 10 years ago

Status: newassigned

It seems to me that make_array would require either (a) returning the array by value (copying or depending on RVO), or passing in the destination array by reference (which means you have to construct it beforehand.

In either case, I don't see a compelling need, when compared to:

boost::array<T, N> arr;
std::copy ( iter1, iter2, arr.begin ());

Can you show me an example where make_array would be a significant improvement? Thanks!

comment:3 by Olaf van der Spek <olafvdspek@…>, 10 years ago

That requires temp vars for both input and output.

string g() { return "Olaf"; }
void f(array<char, 20> const&);

f(make_array(g())); // desired

{
  string s = g();
  array<char, 20> a;
  std::copy(s.begin(), s.end(), a.begin());
  f(a);
}

IMO the one liner looks much better than the 6 liner and the 6 liner can't even do size checking.

Note: See TracTickets for help on using tickets.