Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-01-15 13:03:38


"Hendrik Schober" <SpamTrap_at_[hidden]> writes:

> David Abrahams <dave_at_[hidden]> wrote:
>> [...]
>> Comeau is nasty! Try this on it, for example:
>>
>> # include <map>
>> # include <vector>
>> # include <algorithm>
>> int main()
>> {
>> std::map<int,int> a;
>> std::vector<int> v(20);
>> std::copy(a.begin(), a.end(), v.begin());
>> return 0;
>> }
>
> I did:
>
> Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
> Copyright 1988-2003 Comeau Computing. All rights reserved.
> BD Software STL Message Decryptor (Release 1.24 for Comeau C++)
> MODE:strict errors C++
>
> stl_algobase.h(144): error: no suitable conversion function from
> "pair<int,int>" to "vector<int>::value_type" exists
> *__result = *__first;
> ^
> detected during:
> instantiation of "vector<int>::value_type * __copy(map<int,int>::iterator,
> map<int,int>::iterator, vector<int>::value_type *, input_iterator_tag,
> iterator_traits<map<int,int>::iterator>::difference_type *)" at line 175
> instantiation of "vector<int>::value_type * __copy_aux2(map<int,int>::iter,
> map<int,int>::iter, vector<int>::value_type *, __false_type)" at line 208
> instantiation of "vector<int>::value_type * __copy_aux(map<int,
> int>::iterator, map<int,int>::iterator, vector<int>::value_type *,
> iterator_traits<map<int,int>::iterator>::value_type *)" at line 216
> instantiation of "vector<int>::value_type * copy(map<int,int>::iter,
> map<int,int>::iter, vector<int>::value_type *)" at line 8 of "ComeauTest.c"
>
> 1 error detected in the compilation of "ComeauTest.c".
>
> Seems reasonable to me.

You got lucky (see below). Besides the fact that it gets much worse,
you just happen to know what vector<int>::value_type is, so it's worse
than you think.

Try comeau online:

Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

"stl_algobase.h", line 144: error: no suitable conversion function from
          "std::_Rb_tree<std::map<int, int, std::less<int>,
          std::allocator<int>>::key_type, std::map<int, int, std::less<int>,
          std::allocator<int>>::value_type, std::_Select1st<std::map<int, int,
          std::less<int>, std::allocator<int>>::value_type>, std::map<int,
          int, std::less<int>, std::allocator<int>>::key_compare,
          std::allocator<int>>::value_type" to
          "std::vector<int, std::allocator<int>>::value_type" exists
      *__result = *__first;
                  ^
          detected during:
            instantiation of "_OutputIter std::__copy(_InputIter, _InputIter,
                      _OutputIter, std::input_iterator_tag, _Distance *) [with
                      _InputIter=std::_Rb_tree_iterator<std::_Rb_tree<std::map<
                      int, int, std::less<int>,
                      std::allocator<int>>::key_type, std::map<int, int,
                      std::less<int>, std::allocator<int>>::value_type,
                      std::_Select1st<std::map<int, int, std::less<int>,
                      std::allocator<int>>::value_type>, std::map<int, int,
                      std::less<int>, std::allocator<int>>::key_compare,
                      std::allocator<int>>::value_type,
                      std::_Rb_tree<std::map<int, int, std::less<int>,
                      std::allocator<int>>::key_type, std::map<int, int,
                      std::less<int>, std::allocator<int>>::value_type,
                      std::_Select1st<std::map<int, int, std::less<int>,
                      std::allocator<int>>::value_type>, std::map<int, int,
                      std::less<int>, std::allocator<int>>::key_compare,
                      std::allocator<int>>::reference,
                      std::_Rb_tree<std::map<int, int, std::less<int>,
                      std::allocator<int>>::key_type, std::map<int, int,
                      std::less<int>, std::allocator<int>>::value_type,
                      std::_Select1st<std::map<int, int, std::less<int>,
                      std::allocator<int>>::value_type>, std::map<int, int,
                      std::less<int>, std::allocator<int>>::key_compare,
                      std::allocator<int>>::pointer>,
                      _OutputIter=std::vector<int,
                      std::allocator<int>>::value_type *,
                      _Distance=std::iterator_traits<std::_Rb_tree_iterator<std
                      ::_Rb_tree<std::map<int, int, std::less<int>,
                      std::allocator<int>>::key_type, std::map<int, int,
                      std::less<int>, std::allocator<int>>::value_type,
                      std::_Select1st<std::map<int, int, std::less<int>,
                      std::allocator<int>>::value_type>, std::map<int, int,
                      std::less<int>, std::allocator<int>>::key_compare,
                      std::allocator<int>>::value_type,

                      ...

Now compare with gcc:

  /usr/include/c++/3.3.1/bits/stl_algobase.h: In function `_OutputIter
     std::__copy(_InputIter, _InputIter, _OutputIter, std::input_iterator_tag)
     [with _InputIter = std::_Rb_tree_iterator<std::pair<const int, int>,
     std::pair<const int, int>&, std::pair<const int, int>*>, _OutputIter = int*]
     ':

     ...
  /usr/include/c++/3.3.1/bits/stl_algobase.h:228: error: cannot convert `
     std::pair<const int, int>' to `int' in assignment

Too bad about the "...", but STLFilt can help.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk