Not all platforms we're targeting support C++11 yet :(

As a work around, we provide map and vector implementations in v8-util.h
that can be used with persistent values.

best
-jochen


On Mon, Jul 14, 2014 at 4:24 PM, Pavel Medvedev <[email protected]> wrote:

> 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
>
> --
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to