2016-08-10 17 views
6

Clang 3.8.1 z libC++ kompiluje następujący program:Clang vs std :: crbegin gcc z boost :: iterator_range

#include <vector> 
#include <iterator> 
#include <algorithm> 
#include <iostream> 

#include <boost/range/iterator_range.hpp> 

int main() 
{ 
    const std::vector<int> v {1, 2, 3}; 

    const auto range = boost::make_iterator_range(v); 

    std::copy(std::crbegin(range), std::crend(range), std::ostream_iterator<int> {std::cout, " "}); 
    std::cout << std::endl; 

    return 0; 
} 

Ale gcc 6.1.0 z libstdC++ nie robi. Pierwsza linia błędu gcc to:

error: no matching function for call to 'crbegin(const boost::iterator_range<__gnu_cxx::__normal_iterator<const int*, std::vector<int> > >& 

Kto ma rację?

Uwaga wersja doładowania 1,61

+1

Jakie błędy daje gcc? – aschepler

+0

@aschepler Dodałem pierwszą linię błędu - reszta nie dodaje wiele. To samo dla 'std :: crend'. Właściwie uważam, że gcc jest tutaj poprawny - nie ma metody 'rbegin' lub' rend' member w 'boost :: iterator_range'. Po prostu nie bardzo rozumiem, jak Clang je wytwarza! – Daniel

+0

@Daniel: Czy używasz Clang z libC++ lub libstdC++? Jeśli pierwsza, prawdopodobnie nazywa się 'std :: make_reverse_iterator (range.begin())' jeśli nie ma funkcji członkowskiej 'rbegin'. Jeśli to drugie, to naprawdę dobre pytanie ... – ildjarn

Odpowiedz

11

Jest to bug in libc++; std::crbegin jest delegowanie do rbegin, ale nazywając to niewykwalifikowany to podniesienie boost::rbegin (documentation):

template <class _Cp> 
inline _LIBCPP_INLINE_VISIBILITY 
auto crbegin(const _Cp& __c) -> decltype(rbegin(__c)) 
{ 
    return rbegin(__c); 
    //  ^-- unqualified, allows ADL 
} 

Jest to sprzeczne z [iterator.range], który mówi, że crbegin powinny przekazywać jedynie :

template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));

14 - Powroty:std::rbegin(c).

implementacje LibC++ 's od cbegin, cendcrend i mają ten sam błąd.

+2

Dzięki za zgłoszenie błędu. –

+2

A teraz jest naprawiony. –

Powiązane problemy