Raised This Month: $7 Target: $400
 1% 

How to copy ke::HashMap?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 06-30-2017 , 06:12   How to copy ke::HashMap?
Reply With Quote #1

Since ke::HashMap has an implicitly deleted copy constructor and copy assignment operator, do I have to iterate over the map to copy it, or is there an easier way? And if the map is a member of another object, I guess I would have to write a copy constructor / assignment operator for that object and copy the map there?
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 07-07-2017 , 07:02   Re: How to copy ke::HashMap?
Reply With Quote #2

Whoops, didn't see this before. It does appear you will have to copy it yourself. If you're willing, see if dvander will take a patch to implement them.
Fyren is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 07-10-2017 , 04:18   Re: How to copy ke::HashMap?
Reply With Quote #3

Thanks! Copy constructors were omitted from AMTL by design, but there's a PR for move constructors which would probably solve my issues. Unfortunately it has errors.

The issue I have with writing my own copy constructor is that its parameter is const, but ke::HashMap doesn't have a const iterator:
PHP Code:
    HTTPResponse(const struct HTTPResponse &other)
    {
        for (
HTTPHeaderMap::iterator iter other.headers.iter(); !iter.empty(); iter.next()) // member function 'iter' not viable: 'this' argument has type 'const HTTPHeaderMap' (aka 'const StringHashMap<ke::AString>'), but function is not marked const
        
{
            
headers.replace(iter->key.chars(), ke::Move(iter->value));
        }
    } 
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by DJ Tsunami; 07-10-2017 at 04:19.
DJ Tsunami is offline
BAILOPAN
Join Date: Jan 2004
Old 07-16-2017 , 00:21   Re: How to copy ke::HashMap?
Reply With Quote #4

If you file some issues I can make sure the move-ctor bug is fixed, as well as the const iterator.

I've been thinking about lifting the copy-constructor restriction in AMTL. It'd require an opt-in parameter:

Code:
ke::Vector v2(v1, ke::ExplicitCopy());
Unfortunately that wouldn't fix a separate issue, which is that you can't capture these things by-value in lambdas, which is really annoying. Sometimes you know the contents is small enough to copy and you don't care about the performance.
__________________
egg
BAILOPAN is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:49.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode