I have the following code that will not compile, but on Friday, and I'm a little worn out.
#include <string> #include <memory> #include <utility> #include <map> template< typename T, typename ...Args > std::unique_ptr< T > make_unique( Args && ...args ) { return std::unique_ptr< T >( new T( std::forward< Args >( args )... ) ); } struct A { }; std::map< std::string, std::unique_ptr< A > > _map = { { "A", make_unique< A >() } }; // <-- ERROR!!
The following compilation no problem
int main() { std::pair< std::string, std::unique_ptr< A > > p { "B", make_unique< A >() }; _map.insert( std::make_pair( "C", make_unique< A >() ) ); }
The error I get (rude, like remote g ++ fluff)
use of deleted function 'constexpr std::pair<...>( const st::pair<...> & ) 'constexp std::pair<...>::pair( const std::pair<...> & ) is implicitly deleted because the default definition would be illegal.
Argghh !! Just read this in the C ++ 11 standard.
When an aggregate is initialized with a list of initializers, as specified in 8.5.4, the elements of the list of initializers are taken as initializers for members of the aggregate, increasing the index or order of members. Each member copies-initializes from the corresponding initialization clause
bummer !!!
Does anyone know if this is simply not possible with initialization lists?
c ++ dictionary unique-ptr
Scaryardvark
source share