문제

I'm trying to initialize a std::vector from a std::list efficiently, but I'm not having any luck.

For example, it'd like to something like this:

void myFunc(std::list<double>::iterator begin, std::list<double>::iterator end)
{
    std::vector <double> data(begin, end);
    // or
    std::vector <double> data;
    data::insert(data.begin(), data.end());
}

However, this is not working since the containers seem to only support their own iterator types? Am I missing something? Is what I am trying to accomplish not that easily possible?

도움이 되었습니까?

해결책

Your first version

std::vector<double> data(begin, end);

is correct.

You second version should be

std::vector<double> data;
data.insert(data.begin(), begin, end);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top