Wrong vector ctor used with iterator

J

Johann Gerell

I have this iterator:

class CFileIterator : public std::iterator<std::input_iterator_tag,
const std::wstring>
{
public:
CFileIterator(const std::wstring& wildcardPath);
....
};

which I instantiate like this:

CFileIterator it(SomePathWithWildcard), end;

I was hoping to be able to fill a vector using the iterator, like this:

std::vector<std::wstring> filenames(it, end);

but the compiler spits this into my face:

error C2664:
'std::vector<_Ty>::vector(std::vector<_Ty>::size_type,
const _Ty &,const _A &)'
: cannot convert parameter 1 from 'CFileIterator'
to 'std::vector<_Ty>::size_type'

Apparently, the compiler believes I want to call the vector ctor

vector(size_type, const Type&, const Allocator&);

instead of

template<class InputIterator>
vector(InputIterator, InputIterator, const Allocator&);

I use the aged and all but standards compliant Dinkumware STL bundled
with Platform Builder 5 - it's probably the same that shipped with old
Visual C++ 6.
Any ideas what I might try to get resolve the ctor call correctly?
 
V

Victor Bazarov

Johann said:
[...]
I use the aged and all but standards compliant Dinkumware STL bundled
with Platform Builder 5 - it's probably the same that shipped with old
Visual C++ 6.
Any ideas what I might try to get resolve the ctor call correctly?

You might want to think of chaining the library implementation or updating
the compiler... Otherwise, compiler-specific questions should go to the
compiler-specific newsgroups (microsoft.public.vc.language, in your case).

VC++ v6 fails to compile this simple code with the same error message:

#include <vector>

int main()
{
std::vector<int> vi;
std::vector<double> vd(vi.begin(), vi.end());
}

Its template handling is seriously screwed up.

V
 
P

Pete Becker

Victor said:
Johann said:
[...]
I use the aged and all but standards compliant Dinkumware STL bundled
with Platform Builder 5 - it's probably the same that shipped with old
Visual C++ 6.
Any ideas what I might try to get resolve the ctor call correctly?


You might want to think of chaining the library implementation or updating
the compiler... Otherwise, compiler-specific questions should go to the
compiler-specific newsgroups (microsoft.public.vc.language, in your case).

VC++ v6 fails to compile this simple code with the same error message:

#include <vector>

int main()
{
std::vector<int> vi;
std::vector<double> vd(vi.begin(), vi.end());
}

Its template handling is seriously screwed up.

Well, that may be, but that's not really the cause of the error message.
<g> The problem is that the library doesn't define a constructor that
takes two arguments of an arbitrary iterator type; it only defines one
that takes vector::iterator. That's because of a limitation in early
versions of VC6. With SP6 (or is it 5?) that limitation is no longer
present. You can edit the header and change

typedef const_iterator _It;
vector(_It _F, _It _L, const _A& _Al = _A())
: allocator(_Al), _First(0), _Last(0), _End(0)
{insert(begin(), _F, _L); }

to

typedef const_iterator _It;
template <class _It>
vector(_It _F, _It _L, const _A& _Al = _A())
: allocator(_Al), _First(0), _Last(0), _End(0)
{insert(begin(), _F, _L); }

Or you can remove the typedef completely and add 'template <class _It>'
in front of each member function that takes a pair of arguments of type
_It. That's a better fix, but it's a little bigger.
 
V

Victor Bazarov

Pete said:
Victor said:
Johann said:
[...]
I use the aged and all but standards compliant Dinkumware STL bundled
with Platform Builder 5 - it's probably the same that shipped with old
Visual C++ 6.
Any ideas what I might try to get resolve the ctor call correctly?



You might want to think of chaining the library implementation or
updating
the compiler... Otherwise, compiler-specific questions should go to the
compiler-specific newsgroups (microsoft.public.vc.language, in your
case).

VC++ v6 fails to compile this simple code with the same error message:

#include <vector>

int main()
{
std::vector<int> vi;
std::vector<double> vd(vi.begin(), vi.end());
}

Its template handling is seriously screwed up.

Well, that may be, but that's not really the cause of the error message.
<g> The problem is that the library doesn't define a constructor that
takes two arguments of an arbitrary iterator type; it only defines one
that takes vector::iterator. That's because of a limitation in early
versions of VC6. With SP6 (or is it 5?) that limitation is no longer
present. You can edit the header and change [...]

That constitutes "changing the library implementation" that I earlier
recommended. I am sure the OP would benefit from reading about (and
applying) the other fixes listed on your Web site.

V
 
P

Pete Becker

Victor said:
That constitutes "changing the library implementation"

Okay. I took that to mean "replacing the library implementation", which
is far too often an off-the-cuff suggestion.
 
V

Victor Bazarov

Pete said:
Okay. I took that to mean "replacing the library implementation", which
is far too often an off-the-cuff suggestion.

Isn't English language grand? Allows me to wiggle out of any unpleasant
situation <g> especially because it's not my mother tongue.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top