libstdc++ __inplace_stable_sort build failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The following program:


#include <algorithm>

#define ARRAY_LEN(arr) (sizeof(arr) / sizeof((arr)[0]))

typedef struct {
        int64_t a;
        int64_t b;
} intPair;
intPair data[(int64_t)1e7];

bool
less(const intPair lhs, const intPair rhs) {
        return lhs.a < rhs.a;
}

int
main(void) {
        std::stable_sort(data, data + ARRAY_LEN(data), less);
        std::__inplace_stable_sort(data, data + ARRAY_LEN(data), less);
        return 0;
}


gives the following error (notice that the error is only for
__inplace_stable_sort, not for stable_sort):


In file included from /usr/include/c++/7.3.1/algorithm:62:0,
                 from cxxStableSortSimpler.cxx:1:
/usr/include/c++/7.3.1/bits/stl_algo.h: In instantiation of ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = intPair*; _Compare = bool (*)(intPair, intPair)]’:
/usr/include/c++/7.3.1/bits/stl_algo.h:2766:25:   required from ‘void std::__inplace_stable_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = intPair*; _Compare = bool (*)(intPair, intPair)]’
cxxStableSortSimpler.cxx:19:63:   required from here
/usr/include/c++/7.3.1/bits/stl_algo.h:1847:14: error: could not convert ‘__i’ from ‘intPair*’ to ‘intPair’
    if (__comp(__i, __first))
        ~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/7.3.1/bits/stl_algo.h: In instantiation of ‘void std::__merge_without_buffer(_BidirectionalIterator, _BidirectionalIterator, _BidirectionalIterator, _Distance, _Distance, _Compare) [with _BidirectionalIterator = intPair*; _Distance = long int; _Compare = bool (*)(intPair, intPair)]’:
/usr/include/c++/7.3.1/bits/stl_algo.h:2772:34:   required from ‘void std::__inplace_stable_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = intPair*; _Compare = bool (*)(intPair, intPair)]’
cxxStableSortSimpler.cxx:19:63:   required from here
/usr/include/c++/7.3.1/bits/stl_algo.h:2487:14: error: could not convert ‘__middle’ from ‘intPair*’ to ‘intPair’
    if (__comp(__middle, __first))
        ~~~~~~^~~~~~~~~~~~~~~~~~~


So how does one use __inplace_stable_sort correctly?

Regards,
Neven Sajko

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux