Skip to content

STL-incompatible labelHashSet iterators

Error description

Implementation of labelHashSet iterators produces the following compilation error:

In file included from containers/HashTables/HashOps/HashOps.C:28:
In file included from containers/HashTables/HashOps/HashOps.H:46:
In file included from lnInclude/HashSet.H:68:
In file included from lnInclude/HashTable.H:86:
In file included from lnInclude/word.H:46:
In file included from lnInclude/string.H:55:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string:504:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string_view:175:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__string:56:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:2587:66: error: no type named 'value_type' in
      'std::__1::iterator_traits<Foam::HashTable<Foam::zero::null, long long, Foam::Hash<Foam::label>
      >::key_iterator_base<Foam::HashTable<Foam::zero::null, long long, Foam::Hash<Foam::label> >::const_iterator> >'
              __less<typename iterator_traits<_ForwardIterator>::value_type>());
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
containers/HashTables/HashOps/HashOps.C:84:27: note: in instantiation of function template specialization
      'std::__1::max_element<Foam::HashTable<Foam::zero::null, long long, Foam::Hash<Foam::label>
      >::key_iterator_base<Foam::HashTable<Foam::zero::null, long long, Foam::Hash<Foam::label> >::const_iterator> >' requested here
    auto const max = std::max_element(locations.begin(), locations.end());
                          ^
1 error generated.

The error happens in two locations - HashOps.C:84 and bitSetTemplates.C:79 - during invocation of std::max_element.

Environment

OpenFOAM(R) version: 1912

OS: macOS (10.15.4)

Compiler: Apple clang version 11.0.3 (clang-1103.0.32.29)

Possible fix

Unfortunately I was not able to find the root of the error, so I have changed max_element invocations to its naive implementation:

#ifndef __APPLE__
    auto const max = std::max_element(locations.begin(), locations.end());
#else
    auto max = locations.begin();
    auto first = locations.begin();
    auto last = locations.end();
    for (; first != last; ++first)
        if (*max < *first) max = first;
#endif