-, , , std::for_each. , :
vector<int> values;
struct match_functor
{
vector<int> value_array;
int match_value;
match_functor(int value): match_value(value) {}
void operator() (int input_value)
{
if(match_value == input_value)
value_array.push_back(input_value);
}
};
match_functor matches(1);
std::for_each(values.begin(), values.end(), matches);
matches.value_array[INDEX].
, , , - -:
struct match_functor
{
vector<int> index_array;
int match_value;
int index;
match_functor(int value): match_value(value), index(0) {}
void operator() (int input_value)
{
if(match_value == input_value)
index_array.push_back(index);
index++;
}
};
match_functor matches(1);
matches = std::for_each(values.begin(), values.end(), matches);
matches.index_array[INDEX] orignal, 1, .