Construct-in-place an unmoveable object in a map

后端 未结 3 1074
清酒与你
清酒与你 2021-01-18 14:36

I\'m trying to construct an object in a map that contains an atomic, so it can neither be copied nor moved AFAICT.

My reading of C++ reference is that map empl

3条回答
  •  天命终不由人
    2021-01-18 15:17

    May be the following solution will be better, since atomic is not copyable:

    class Z {
      std::atomic i;
    };
    
    std::unordered_map> map;
    
    void test(void) {
      map.emplace(0, std::make_shared()); // OK
    }
    

提交回复
热议问题