2016-08-10 8 views
6

बजना 3.8.1 ++ निम्नलिखित कार्यक्रम संकलित libc साथ: libstdc साथबजना बनाम जीसीसी std :: बढ़ावा साथ crbegin :: 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; 
} 

लेकिन जीसीसी 6.1.0 ++ नहीं करता है। जीसीसी त्रुटि की पहली पंक्ति है:

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

कौन सही है?

नोट: बूस्ट संस्करण 1,61

+1

जीसीसी क्या त्रुटियां देता है? – aschepler

+0

@aschepler मैंने त्रुटि की पहली पंक्ति जोड़ दी है - शेष में ज्यादा कुछ नहीं जोड़ा गया है। 'Std :: crend' के लिए वही। मुझे लगता है कि जीसीसी यहाँ सही है - 'boost :: iterator_range' में' rbegin' या 'rend' सदस्य विधि नहीं है। मैं समझ में नहीं आता कि क्लैंग कैसे बना रहा है! – Daniel

+0

@Daniel: क्या आप libC++ या libstdC++ के साथ क्लैंग का उपयोग कर रहे हैं? यदि पूर्व, संभवतः यह 'std :: make_reverse_iterator (range.begin()) 'को कॉल करता है, यदि कोई' rbegin' सदस्य फ़ंक्शन मौजूद नहीं है। यदि उत्तरार्द्ध, तो वास्तव में अच्छा सवाल ... – ildjarn

उत्तर

11

यह एक bug in libc++ है; std::crbeginrbegin को सौंपने का है, लेकिन फोन करके यह boost::rbegin (documentation) उठा रहा है अयोग्य:

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

यह [iterator.range], जो कहता है कि crbegin केवल प्रतिनिधि चाहिए के विपरीत है:

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

14 - रिटर्न:std::rbegin(c)

libC++ के cbegin, cend और crend के कार्यान्वयन ही बग है।

+2

बग रिपोर्ट के लिए धन्यवाद। –

+2

और अब यह तय है। –

संबंधित मुद्दे