This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/15910] can't compile self defined void distance(std::vector<T>, std::vector<T>)
- From: "adah at netstd dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Aug 2005 02:26:37 -0000
- Subject: [Bug libstdc++/15910] can't compile self defined void distance(std::vector<T>, std::vector<T>)
- References: <20040610143911.15910.king.benjamin@mh-hannover.de>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From adah at netstd dot com 2005-08-08 02:26 -------
Sorry, but some of you here have not read carefully enough and acted in a
haste. Please test with the following code piece and make a decision AFTER
that:
#include <iostream>
#include <vector>
int distance(std::vector<int> v1, std::vector<int> v2)
{
std::cout << "I am chosen!" << std::endl;
return v1.size() - v2.size();
}
// Begins the hack
namespace std {
template<>
struct iterator_traits<vector<int> >
{
typedef int iterator_category;
typedef int value_type;
typedef int difference_type;
typedef int distance_type;
typedef int pointer;
typedef int reference;
};
}
// End the hack
int main()
{
std::vector<int> v1(3), v2(1);
int d = distance(v1, v2);
return 0;
}
The point is: adding the seemingly unrelated code will make the user distance
be chosen.
Best regards,
Yongwei
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15910