问题
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