Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2465 Discussions

concurrent_unordered_map<int, unique_ptr<int>> insert works, but emplace not

Derek_L_
Beginner
416 Views

for test code below, 'insert' works, but emplace not. 

#include <memory>

#include <tbb/concurrent_unordered_map.h>

struct A {
    A(int i): i_(i) {}

    int i_;
};

int main() {
    tbb::concurrent_unordered_map<int, std::unique_ptr<A>> m;

    m.insert(std::make_pair(1, std::make_unique<A>(2)));
    m.emplace(2, std::make_unique<A>(2));
}

think it's due to insernal_insert uses pnode->my_element directly in 

    template<typename... Args>
    std::pair<iterator, bool> emplace(Args&&... args) {
        nodeptr_t pnode = my_solist.create_node_v(tbb::internal::forward<Args>(args)...);
        const sokey_t hashed_element_key = (sokey_t) my_hash_compare(get_key(pnode->my_element));
        const sokey_t order_key = split_order_key_regular(hashed_element_key);
        pnode->init(order_key);

        return internal_insert(pnode->my_element, pnode);
    }

 

0 Kudos
0 Replies
Reply