c++11 - g++4.9.2 and rvalue reference maps -
so, have following code:
#include <map> #include <string> #include <iostream> struct mockmapitem { std::string property; mockmapitem(const std::string& value) : property(value) { std::cout << "constructed mockmapitem string!" << std::endl; } }; typedef typename std::map<std::string, const mockmapitem&& > itemmap; int main() { mockmapitem map_item("some string value"); itemmap themap; themap.emplace("something", std::move(map_item)); }
for ease of access, have put here:
http://coliru.stacked-crooked.com/a/7e80bc37d904510d
and here:
now comes fun:
the coliru site compiles , runs it.
the ideone 1 gives following error:
compilation error time: 0 memory: 0 signal:0 prog.cpp:14:60: error: template argument 2 invalid typedef typename std::map<std::string, const mockmapitem&& > itemmap; ^ prog.cpp:14:60: error: template argument 4 invalid prog.cpp:14:62: error: 'itemmap' in namespace 'std' not name type typedef typename std::map<std::string, const mockmapitem&& > itemmap;
but can compile code, although using g++4.8.4 (and clang 3.4)...
and i'm wondering 1 right, , more why?
23.2.1 says container's value_type
must erasable container, , 23.2.4 says maps , multimaps requirements apply key_type
, mapped_type
.
a reference type not erasable container, because cannot form pointer reference type , cannot destroy using allocator_traits::destroy
(because allocators support non-const object types, , reference type not object type).
so const mockmapitem&&
type fails meet requirements use in containers, , has undefined behaviour.
edit: in c++11 requirement in 23.2.1 value_type
destructible, , reference type is destructible. maybe well-formed in c++11, not c++14. hmm.
Comments
Post a Comment