J
Jason Heyes
Look at my code:
void modify_element(BigType &x)
{
/* not shown */
}
BigType modify_element_copy(BigType x)
{
modify_element(x);
return x;
}
void modify_container(std::vector<BigType> &v)
{
std::transform(v.begin(), v.end(), v.begin(), modify_element_copy);
}
Can I replace the call to std::tranform with a call to std::for_each? My
documentation says that for_each must not modify the elements. Here is
modify_container using std::for_each rather than std::transform:
void modify_container(std::vector<BigType> &v)
{
std::for_each(v.begin(), v.end(), modify_element);
}
Any help is appreciated.
void modify_element(BigType &x)
{
/* not shown */
}
BigType modify_element_copy(BigType x)
{
modify_element(x);
return x;
}
void modify_container(std::vector<BigType> &v)
{
std::transform(v.begin(), v.end(), v.begin(), modify_element_copy);
}
Can I replace the call to std::tranform with a call to std::for_each? My
documentation says that for_each must not modify the elements. Here is
modify_container using std::for_each rather than std::transform:
void modify_container(std::vector<BigType> &v)
{
std::for_each(v.begin(), v.end(), modify_element);
}
Any help is appreciated.