Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Member function insert with hint. #131

Closed
slavenf opened this issue Sep 22, 2021 · 4 comments
Closed

Member function insert with hint. #131

slavenf opened this issue Sep 22, 2021 · 4 comments
Assignees

Comments

@slavenf
Copy link

slavenf commented Sep 22, 2021

Hello.
Could you add overloaded member function insert with hint to be compatible with all standard container?

iterator insert(const_iterator hint, const value_type& value);
iterator insert(const_iterator hint, value_type&& value);

For example, these overloads are very usefule in generic code that is using std::insert_iterator or std::inserter.
Once again, thank you for this great library.

@martinus martinus self-assigned this Sep 22, 2021
@dixlorenz
Copy link

Voting this up. I just stumbled about this problem; it used to be in the library, but got removed at one point and when I updated to the current version my code wouldn't compile any more.

@slavenf
Copy link
Author

slavenf commented Dec 10, 2021

@dixlorenz There is workaround before martinus write better function. Openrobin_hood.h. Somewhere near line 1869 is this:

std::pair<iterator, bool> insert(const value_type& keyval) {
    ROBIN_HOOD_TRACE(this)
    return emplace(keyval);
}

std::pair<iterator, bool> insert(value_type&& keyval) {
    return emplace(std::move(keyval));
}

You can add these two functions:

iterator insert(const_iterator /*hint*/, const value_type& keyval)
{
    return insert(keyval).first;
}

iterator insert(const_iterator /*hint*/, value_type&& keyval)
{
    return insert(std::move(keyval)).first;
}

That should work.

@slavenf
Copy link
Author

slavenf commented Dec 10, 2021

If you need emplace_hint then you can also add this:

template <typename... Args>
iterator emplace_hint(const_iterator /*hint*/, Args&&... args)
{
    return emplace(std::forward<Args>(args)...).first;
}

@martinus
Copy link
Owner

Hi, thanks for being persitent 😅 I've created a new release with your fixes, thanks @slavenf!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants