This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/16154] New: input iterator concept too restrictive
- From: "cludwig at cdc dot informatik dot tu-darmstadt dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Jun 2004 09:14:57 -0000
- Subject: [Bug libstdc++/16154] New: input iterator concept too restrictive
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The input iterator concept checks performed if std::copy is called are too
restrictive. Neither in section 24.1.1 nor in section 25.2 of the C++ standard
I see any requirement that input iterators have to be default constructible.
But the compilation of the following program fails anyway due to a failed
DefaultConstructibleConcept check.
cludwig@lap200:~/C++/gcc3.4/tmp> cat input-iterator.cc
#include <iterator>
#include <string>
#include <iostream>
#include <algorithm>
class myInputIterator : public std::iterator<std::input_iterator_tag, char> {
std::string data;
public:
// past-the-end iterators can be constructed
// by myInputIterator("")
explicit myInputIterator(std::string const& input)
: data(input) {
}
value_type operator*() {
return data.at(data.length() - 1);
}
myInputIterator& operator++() {
if(!data.empty()) {
data.resize(data.length() - 1);
}
return *this;
}
myInputIterator operator++(int) {
myInputIterator result(*this);
++(*this);
return result;
}
friend bool operator==(myInputIterator const& lhs,
myInputIterator const& rhs);
};
bool operator==(myInputIterator const& lhs, myInputIterator const& rhs) {
return lhs.data == rhs.data;
}
bool operator!=(myInputIterator const& lhs, myInputIterator const& rhs) {
return !(lhs == rhs);
}
int main() {
std::copy(myInputIterator("Hello world!"), myInputIterator(""),
std::ostream_iterator<char>(std::cout));
return 0;
}
I am going to attach the compiler output.
Regards
Christoph
--
Summary: input iterator concept too restrictive
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: cludwig at cdc dot informatik dot tu-darmstadt dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16154