std::unordered_map of UniquePersistent to UniquePersistent

38 views
Skip to first unread message

Francisco Tolmasky

unread,
Apr 19, 2015, 6:52:51 PM4/19/15
to v8-u...@googlegroups.com
Apologies as I am still not fully versed with Persistent<T,M>. I am trying to make an unordered_map of values to values (kind of like js's Map (but I can't use that)).

So ideally something like: unordered_map<Peristent<v8::Value>, Persistent<v8::Value> >. The source however specifically refers to UniquePersistent (now Global)
for this:

 * C++11 embedders can use STL containers with UniquePersistent values,
 * but pre-C++11 does not support the required move semantic and hence
 * may want these container classes.

So I guess my first questions is what map<UniquePersistent, UniquePersistent> gets me instead of map<Persistent, Persistent>. Separately, 
I went ahead and started implementing this (required me to write hasher and equal for unordered_map), and get this error:

struct v8_value_hash
{
    size_t operator()(const UniquePersistent<v8::Value> & aPersistentKey) { ... }
}

struct v8_value_equal_to
{
    bool operator()(const UniquePersistent<v8::Value> & lhsPersistentKey, const UniquePersistent<v8::Value> & rhsPersistentKey) const { ... }
}

And I get:

error: 
      the parameter for this explicitly-defaulted copy constructor is const, but a member or base requires it to be non-const
    pair(const pair& __p) = default;
    ^

Thanks!

Pavel Medvedev

unread,
Apr 20, 2015, 9:27:10 AM4/20/15
to v8-u...@googlegroups.com
Hi Francisco,


I have resolved the issue by using my own class derived from v8::UniquePersisistent with explicitly defined move constructor and assignment operator.

As I understand, there were improvements to C++11 support in recent V8 versions from that time, so maybe this issue has already been resolved.

Cheers,
Pavel
Reply all
Reply to author
Forward
0 new messages