AlliedModders (
-   Coding MM:S Plugins & SM Extensions (
-   -   How to copy ke::HashMap? (

DJ Tsunami 06-30-2017 06:12

How to copy ke::HashMap?
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?

Fyren 07-07-2017 07:02

Re: How to copy ke::HashMap?
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.

DJ Tsunami 07-10-2017 04:18

Re: How to copy ke::HashMap?
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(); // 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));

BAILOPAN 07-16-2017 00:21

Re: How to copy ke::HashMap?
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:


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.

All times are GMT -4. The time now is 19:51.

Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.