Map of lists of move-only type won't compile

落爺英雄遲暮 提交于 2020-01-05 02:36:10

问题


I am trying to use a std::map< Key, std::list< std::unique_ptr< T > > > .

Am I missing some fundamental reason why this is not possible ?

I've reduced the code giving the error to the following:

// A simple move-only type
struct moveonly
{
  moveonly(moveonly const&) = delete;
  moveonly& operator= (moveonly const&) = delete;

  moveonly() = default;
  moveonly(moveonly&&) = default;
  moveonly& operator= (moveonly&&) = default;

  ~moveonly() noexcept {}
};

typedef std::list< moveonly > list_t;
typedef std::pair< int, list_t > pair_t;

// Even just trying to default construct such a pair fails
pair_t pr;

I'm using MSVC November CTP. The error is "attempting to reference a deleted function" for the copy constructor of moveonly. This is being instantiated in the copy constructor of std::list. I have no idea why std::list's copy constructor would be getting instantiated, when all I've done is attempt to default construct the pair.

来源:https://stackoverflow.com/questions/26160396/map-of-lists-of-move-only-type-wont-compile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!