skarupke / flat_hash_map

A very fast hashtable
1.69k stars 186 forks source link

template_iterator iterator do not always return a value #7

Closed Dllieu closed 6 years ago

Dllieu commented 6 years ago

Hello,

Is it intended?

            iterator begin()
            {
                for (EntryPointer it = entries;; ++it)
                {
                    if (it->has_value())
                        return { it };
                }

                // No return value here
            }

I believe it should at least return end() or cend() depending of the constness of the iterator

see https://github.com/skarupke/flat_hash_map/pull/8

skarupke commented 6 years ago

The loop has no exit condition, so you can't get down there. The only way to exit the loop is through the return statement. You will always hit the it->has_value() case because there is a special entry at the end of the table that stops iteration.