Skip to content
Snippets Groups Projects
Commit b8300759 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: HashTable cfind() method returning a const_iterator

- This follows the same idea as cbegin/cend and is helpful when using
  C++11 auto to ensure we have unambiguous const-safe access.

  Previously:
  ====
    typename someLongClass::const_iterator iter = someTable.find(key);

    ... later on:
    *iter = value; // Oops, but caught by compiler.

  We can save some typing with auto, but it is uncertain what we get:
  ====
    auto iter = someTable.find(key);
        // iterator or const_iterator?
        // depends on someTable having const or non-const access.

    ... later on:
    *iter = value;  // Oops, but not caught by compiler.

  Using cfind instead, auto will deduce const_iterator as the type:
  ====
    auto iter = someTable.cfind(key);  // definitely const_iterator

    ... later on:
    *iter = value; // Oops, but caught by compiler.
parent 2af602c2
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment