Boost logo

Boost :

From: rwgk (rwgk_at_[hidden])
Date: 2002-03-08 16:50:23


--- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> Passing the function to the vector constructor solves the
> problem - and leaves the vector initialized so that its
> other methods work after construction, as is the case now.

That sounds ideal (and I believe is very similar to what
David is advocating), but I am having difficulties to see
how it can be implemented in an easy-to-use way (and in a
way that does not interfere with the existing interface,
using a mechanism that can be understood and implemented by
programmers with less than 5+ years of full-time C++
development experience).
Here is a moderately difficult challenge ("use push_back()" does
not count as an answer):

void foo(std::vector<double> const& a1, std::vector<double> const& a2)
{
  std::vector<double> r(a1.size(), uninitialized_flag());
  for(std::size_t i=0;i<r.size();i++) {
    r[i] = std::pow(a1[i], a2[i]);
  }
}

How would you do that?
Can you image something like:

std::vector<double> r(vector_bind(pow, a1, a2));

(Recall my question from last month: how would you select the most
appropriate overload for pow?)

Thanks,
        Ralf


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk