See this answer for how to insert into stdmap without making copies of the map value.
std::map emplace without copying value
Continueing from that answer - suppose my Foo
type looks something like this:
struct Foo {
const int& intref_;
std::mutex mutex_;
}
Then initialized using aggregate-initialization like this
Foo{7}
or
Foo{7, std::mutex()}
Would it be somehow possible to be emplaced into the map with type ?:
std::map<size_t, Foo> mymap;
I know I could just write a constructor for Foo
- but can it be done with aggregate initialization instead ?
Link to compiler explorer:
Relevant c++ references:
https://en.cppreference.com/w/cpp/container/map/try_emplace
https://en.cppreference.com/w/cpp/language/aggregate_initialization