Re: some combination of std::distance/std::max_element ( ? )
Isn't that shorter and easier to read??
Carl, given.
# include <iostream>
# include <string>
# include <vector>
using namespace std;
template <class For1, class For2, class Out>
Out max_of_zones(For1 data_begin,For1 data_end,
For2 z_begin,For2 z_end, Out out)
{
// beginning and end of current range
For1 begin = data_begin;
For2 end ( begin) ;
for( ; z_begin !=z_end; begin = end, ++out, ++z_begin )
{
std::advance(end,*z_begin);
*out = *std::max_element(begin,end);
}
return out;
}
int main()
{
std::vector<int> sizes(3,3);
std::vector<double> data;
// place the six values in data.
std::vector<double> max_of_zone;
max_of_zones(data.begin(),data.end(),sizes.begin(),sizes.end(),
std::ostream_iterator<double>(std::cout,","));
}
There's an issue with this line. 'For2 end ( begin) ;'. For1 and
For2 are different types. I'm trying to figure out the workaround to
get this to compile but I'm going around in circles. template/iterator
knowledge is foundational :)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]