This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/65942] [5/6 Regression] [C++14] cannot use std::function as comparator in algorithms


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65942

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libstdc++                   |c++

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This seems to be a compiler bug not a library bug:

#include <functional>

bool cmp1(const int& a, const int& b) { return a < b; }
std::function<bool (const int&, const int&)> cmp2 = cmp1;

  template<typename _Compare>
    struct _Iter_comp_iter
    {
      _Compare _M_comp;
      _Iter_comp_iter(_Compare __comp)
        : _M_comp(__comp)
      { }

      template<typename _Iterator1, typename _Iterator2>
#if __cplusplus >= 201402L
        constexpr
#endif
        bool
        operator()(_Iterator1 __it1, _Iterator2 __it2)
        { return bool(_M_comp(*__it1, *__it2)); }
    };

  template<typename _Compare>
    inline _Iter_comp_iter<_Compare>
    __iter_comp_iter(_Compare __comp)
    { return _Iter_comp_iter<_Compare>(__comp); }

int main() {
  int v[1];
  int* iter = v;
  auto cmp = __iter_comp_iter(cmp2);
  cmp(iter, iter);
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]