This question already has an answer here:
- C++ push_back vs Insert vs emplace 3 answers
 
I am creating a vector in different thread. After that I want to pass it to the method Data::insert() that saves this vector in another vector. What is the optimal way to do that?
template<typename DATA_TYPE>
class Data
{
public:
    Data();
    void insert(vector<DATA_TYPE>& d)
    {
        if (d.empty())
            throw range_error("Data::insert(): Vector is empty!");
        lock_guard<mutex> l(data_mutex_);
        // Add d to the vector data_
    }
private:
    vector<vector<DATA_TYPE>> data_;
    mutex data_mutex_;
};
Aucun commentaire:
Enregistrer un commentaire