mattreecebentley / plf_colony

An unordered C++ data container providing fast iteration/insertion/erasure while maintaining pointer/iterator validity to non-erased elements regardless of insertions/erasures. Provides higher-performance than std:: library containers for high-modification scenarios with unordered data.
https://plflib.org/colony.htm
zlib License
398 stars 33 forks source link

Get const_iterator from const_pointer #32

Closed Magnutic closed 4 years ago

Magnutic commented 4 years ago

Thank you for this library! I had used something less-than-ideal for this container's purpose before.

I have a use case for getting an (const_)iterator from a const T*. get_iterator_from_pointer works, but I must const_cast the pointer first.

If you will allow a const_cast, it should be trivial to implement an overload for this:

const_iterator get_iterator_from_pointer(const const_pointer element_pointer) const
{
    return get_iterator_from_pointer(const_cast<pointer>(element_pointer));
}
mattreecebentley commented 4 years ago

WIll do-

mattreecebentley commented 4 years ago

Hi, put this in but ended up taking it out in v5.26, as it wasn't in keeping with what the std:: containers do - so just use const_cast for your pointer, and using const_iterator for the return type should automatically convert from iterator. Thanks for bringing it to my attention though- if you have any further info let me know.

mattreecebentley commented 3 years ago

Have put this back in but may be removed again depending on what the committee says