• Raphael Kubo da Costa's avatar
    Make cc::ListContainer's iterators STL-compatible · 0daaef05
    Raphael Kubo da Costa authored
    This fixes the libstdc++ build, and future-proofs the code against libc++
    changes related to https://cplusplus.github.io/LWG/lwg-defects.html#2408
    
    That defect report states that std::iterator_traits should be
    SFINAE-friendly, and libstdc++ already complies with that, so when commit
    2808b7ec ("cros: Improve damage for underlays") started using std::any_of()
    with a cc::ListContainer the underlying code that function assumes (per the
    standard) that the iterators it receives are at least input iterators. For
    that to be true, std::iterator_traits needs to have a valid specialization
    rather than the empty one (SFINAE), otherwise we end up with an error like
    this:
    
    In file included from ../../components/viz/service/display/overlay_processor.cc:5:
    In file included from ../../components/viz/service/display/overlay_processor.h:10:
    In file included from ../../base/containers/flat_map.h:12:
    In file included from ../../base/containers/flat_tree.h:8:
    In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/algorithm:62:
    /usr/bin/../lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/stl_algo.h:162:10: error: no matching function for call to '__iterator_category'
                           std::__iterator_category(__first));
                           ^~~~~~~~~~~~~~~~~~~~~~~~
    /usr/bin/../lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/stl_algo.h:3930:19: note: in instantiation of function template specialization 'std::__find_if<cc::ListContainer<viz::DrawQuad>::ConstIterator,
          __gnu_cxx::__ops::_Iter_pred<(lambda at ../../components/viz/service/display/overlay_processor.cc:258:49)> >' requested here
          return std::__find_if(__first, __last,
                      ^
    /usr/bin/../lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/stl_algo.h:526:40: note: in instantiation of function template specialization 'std::find_if<cc::ListContainer<viz::DrawQuad>::ConstIterator,
          (lambda at ../../components/viz/service/display/overlay_processor.cc:258:49)>' requested here
        { return __last == _GLIBCXX_STD_A::find_if(__first, __last, __pred); }
                                           ^
    /usr/bin/../lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/stl_algo.h:544:20: note: in instantiation of function template specialization 'std::none_of<cc::ListContainer<viz::DrawQuad>::ConstIterator,
          (lambda at ../../components/viz/service/display/overlay_processor.cc:258:49)>' requested here
        { return !std::none_of(__first, __last, __pred); }
                       ^
    ../../components/viz/service/display/overlay_processor.cc:257:30: note: in instantiation of function template specialization 'std::any_of<cc::ListContainer<viz::DrawQuad>::ConstIterator,
          (lambda at ../../components/viz/service/display/overlay_processor.cc:258:49)>' requested here
          bool has_damage = std::any_of(
                                 ^
    /usr/bin/../lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/stl_iterator_base_types.h:205:5: note: candidate template ignored: substitution failure [with _Iter = cc::ListContainer<viz::DrawQuad>::ConstIterator]: no type named
          'iterator_category' in 'std::iterator_traits<cc::ListContainer<viz::DrawQuad>::ConstIterator>'
        __iterator_category(const _Iter&)
        ^
    
    Fix it by adding a few types confirming to STL's naming conventions so that
    std::iterator_traits works with all 4 iterator types cc::ListContainer
    defines.
    
    Bug: 819294
    Change-Id: I1424e22b3793bec810d6d83be2490b4a402ed94d
    Reviewed-on: https://chromium-review.googlesource.com/c/1496991
    Commit-Queue: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
    Auto-Submit: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
    Reviewed-by: default avatardanakj <danakj@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#636860}
    0daaef05
list_container.h 13.2 KB