Topic: deque constructor using Visual C++ 6.0


Author: Matt Austern <austern@sgi.com>
Date: 1999/04/01
Raw View
paul@paul.terranet.com (Paul McDonnell) writes:

> #include <string>
> #include <deque>
>
> using namespace std;
>
> void f()
> {
>  string s("Visual C++ can't find appropriate constructor");
>  deque<char> d( s.begin(), s.end() );
> }
>
> [ moderator's note: I'm taking this question to be asking whether the
>   code and/or the compiler is standard-conforming.  Discussion about
>   coping with specific compilers doesn't belong in this newsgroup. -sdc ]

And the answer, of course, is that it is conforming.  It uses
the member template constructor
    template <class T, class Allocator>
    template <class InputIterator>
    deque<T, Allocator>::deque(InputIterator first, InputIterator last);
which is described in section 23.2.1.1, paragraph 5, of the C++
standard.

Not all standard library implementations provide the STL member
template constructors, though, because some compilers have only
limited support for member templates.



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "AllanW {formerly AllanW@my-dejanews.com}" <allan_w@my-dejanews.com>
Date: 1999/04/02
Raw View
In article <7dtjur$16e$1@nntp.newengland.verio.net>,
  paul@paul.terranet.com (Paul McDonnell) wrote:
>
> This code compiles fine using g++ and HP aCC, but failes using Visual C++ 6.0
> with the following error:
[snip]
> Why won't the compiler use the standard deque constructor deque
(const_iterator
> first, const_iterator last, const A& al = A()); ???

> [ moderator's note: I'm taking this question to be asking whether the
>   code and/or the compiler is standard-conforming.  Discussion about
>   coping with specific compilers doesn't belong in this newsgroup. -sdc ]

In that spirit, I'd say that the compiler isn't yet standard-conforming.

----
Allan_W@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: paul@paul.terranet.com (Paul McDonnell)
Date: 1999/03/31
Raw View
This code compiles fine using g++ and HP aCC, but failes using Visual C++ 6.0
with the following error:

error C2664: '__thiscall std::deque<char,class std::allocator<char>
>::std::deque<char,class std::allocator<char> >(unsigned int,const char &,const
class std::allocator<char> &)' : cannot convert parameter 1
from 'char *' to 'unsigned int'
        This conversion requires a reinterpret_cast, a C-style cast or
function-style cast

Why won't the compiler use the standard deque constructor deque(const_iterator
first, const_iterator last, const A& al = A()); ???

#include <string>
#include <deque>

using namespace std;

void f()
{
 string s("Visual C++ can't find appropriate constructor");
 deque<char> d( s.begin(), s.end() );
}

[ moderator's note: I'm taking this question to be asking whether the
  code and/or the compiler is standard-conforming.  Discussion about
  coping with specific compilers doesn't belong in this newsgroup. -sdc ]


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: sirwillard@my-dejanews.com
Date: 1999/04/01
Raw View
In article <7dtjur$16e$1@nntp.newengland.verio.net>,
  paul@paul.terranet.com (Paul McDonnell) wrote:
>
> This code compiles fine using g++ and HP aCC, but failes using Visual C++ 6.0
> with the following error:
>
> error C2664: '__thiscall std::deque<char,class std::allocator<char>
> >::std::deque<char,class std::allocator<char> >(unsigned int,const char
&,const
> class std::allocator<char> &)' : cannot convert parameter 1
> from 'char *' to 'unsigned int'
>         This conversion requires a reinterpret_cast, a C-style cast or
> function-style cast
>
> Why won't the compiler use the standard deque constructor deque
(const_iterator
> first, const_iterator last, const A& al = A()); ???

Because it's not.  Your code should be calling deque(InIt, InIt, const A&).
Notice that that's InIt, not const_iterator.  The const_iterator is typedef
specific to deque, while your iterators are from string.  I point out this
technicality only because of the following quote from the Help files for the
VC++ implementation (actually, the DinkumWare implementation) of the STD:

---
In this implementation, if a translator does not support member template
functions, the template:

template<class InIt>
    deque(InIt first, InIt last, const A& al = A());
is replaced by:

deque(const_iterator first, const_iterator last, const A& al = A());
---

VC++ doesn't support member template functions (at least not well enough for
the library to have implemented this correctly).


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Biju Thomas <b_thomas@ibm.net>
Date: 1999/04/01
Raw View
Paul McDonnell wrote:
>
> This code compiles fine using g++ and HP aCC, but failes using Visual C++ 6.0
> with the following error:
>
> error C2664: '__thiscall std::deque<char,class std::allocator<char>
> >::std::deque<char,class std::allocator<char> >(unsigned int,const char &,const
> class std::allocator<char> &)' : cannot convert parameter 1
> from 'char *' to 'unsigned int'
>         This conversion requires a reinterpret_cast, a C-style cast or
> function-style cast
>
> Why won't the compiler use the standard deque constructor deque(const_iterator
> first, const_iterator last, const A& al = A()); ???
>
>         string s("Visual C++ can't find appropriate constructor");
>         deque<char> d( s.begin(), s.end() );

There is a constructor for deque accepting an InputIterator. But, this
is a member template:

  template < class InputIterator >
     deque ( InputIterator first, InputIterator last,
                      const Allocator& = Allocator() );


This problem may have to do with VC++'s lack of support for member
templates.

Best regards,
Biju Thomas
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]