breese / trial.protocol

Network wire protocols
11 stars 4 forks source link

Can `dynamic::variable::map_type::erase` accept `string_view`? #20

Open vinipsmaker2 opened 6 years ago

vinipsmaker2 commented 6 years ago

This is not the same as #19. #19 is a bug. This is a feature request.

The following code fails:

auto a = obj.value<trial::dynamic::variable::map_type>();
a.erase(boost::string_view{});

I have to allocate a std::string to erase the proper element. It'd be nice if it worked with string_view directly.

breese commented 6 years ago

a is an std:map so you have to ask the C++ standardization body.

vinipsmaker commented 6 years ago

I see. Gonna close the issue then. Once #19 is solved, I'll have a solution for that.

breese commented 6 years ago

I could add a key::erase_if() algorithm, like the new std::erase_if algorithm.

That could also address the concern in #19.

vinipsmaker commented 6 years ago

That could also address the concern in #19.

erase would stop once the key is found. erase_if would iterate until the very end. Also, erase on a map could use binary search, which is ruled out for erase_if.

erase_if is an useful algorithm, but it's not close enough to erase(key).

And the limitation of not being able to use string_view can be avoided in more elegant ways. The string_view limitation isn't present in the C++14 std::map::find algorithm which can be used to get an acceptable value to the erase function.

breese commented 6 years ago

Agreed. It makes sense to add both erase and erase_if.