Hello,
Is anybody storing UniquePersistent values in standard associative containers? When I tried to store UniquePersistent values in a std::unordered_map, I got an error with GCC:
#include <unordered_map>
#include <v8.h>
void add(v8::Isolate* isolate, int key, v8::Handle<v8::Value> value)
{
std::unordered_map<int, v8::UniquePersistent<v8::Value>> map;
v8::UniquePersistent<v8::Value> pvalue(isolate, value);
map.insert(std::make_pair(key, std::move(pvalue)));
}
When I add move constructor and assignment, it works:
// Moveable unique persistent
template<typename T>
struct MoveablePersistent : public v8::UniquePersistent<T>
{
typedef v8::UniquePersistent<T> base_class;
MoveablePersistent()
: base_class()
{
}
template<typename S>
MoveablePersistent(v8::Isolate* isolate, v8::Handle<S> const& handle)
: base_class(isolate, handle)
{
}
template<typename S>
MoveablePersistent(v8::Isolate* isolate, v8::PersistentBase<S> const& handle)
: base_class(isolate, handle)
{
}
MoveablePersistent(MoveablePersistent&& src)
: base_class(src.Pass())
{
}
MoveablePersistent& operator=(MoveablePersistent&& src)
{
if (&src != this)
{
base_class::operator=(src.Pass());
}
return *this;
}
};
void add(v8::Isolate* isolate, int key, v8::Handle<v8::Value> value)
{
std::unordered_map<int, MoveablePersistent<v8::Value>> map;
MoveablePersistent<v8::Value> pvalue(isolate, value);
map.insert(std::make_pair(key, std::move(pvalue)));
}
Is it possible to add move semanics support for UniquePresistent values in C++11 mode?
Cheers, Pavel