How do I simplify this templated vector initializer loop using lambdas or STL transform?

Posted by Neil G on Stack Overflow See other posts from Stack Overflow or by Neil G
Published on 2010-04-16T20:51:22Z Indexed on 2010/04/16 21:03 UTC
Read the original article Hit count: 171

Filed under:
|
|
|
|

How do I simplify this templated vector initializer loop using lambdas or some kind of STL transform?

template<typename T>
template<typename... Args>
void InitToRandomValues(vector<T>* retval, int n, RNG& rng, Args const&... args) {
    retval->resize(n);
    for (auto it = retval->begin(); it != retval->end(); ++it) {
        typename T::CPDDist cpd(rng, args...);
        *it = T(cpd);
    }
}

© Stack Overflow or respective owner

Related posts about c++0x

Related posts about c++