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: "giovannibajo at libero dot it" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Aug 2004 13:51:58 -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 giovannibajo at libero dot it 2004-08-03 13:51 -------
Subject: Re: can't compile self defined void distance(std::vector<T>, std::vector<T>)
pcarlini at suse dot de wrote:
> First, the ongoing work on type traits + tr1 may simplify
> considerably this kind of refinements, exploting enable_if idioms.
OK. Meanwhile, so that it does not seem I am here just to do FUD, this is
another proto-patch to fix this bug. This solution seems almost perfect to me:
template <class Iter>
typedef typename lazy_enable_if<
has_difference_type<iterator_traits<T> >,
get_difference_type<iterator_traits<T> >
>::type
distance(Iter first, Iter last) { ... }
with the following obvious definitions for the helpers:
template <bool C, class T> struct lazy_enable_if {};
template <class T> struct lazy_enable_if<true,T> { typedef typename T::type
type };
template <class T> struct get_difference_type {
typedef typename T::difference_type type;
};
template <class T> struct has_difference_type {
typedef char yes[1];
typedef char no[2];
template <class T> yes test(typename T::difference_type* );
template <class T> no test(...);
enum { result = (sizeof(test<T>(0)) == sizeof(yes)) };
};
> Second, if we really want to go this way, we should do it
> consistently: don't you believe that most definitely *many* other
> places of the library could be amenable to this treatment?
I don't know how many off-hand. Many other functions don't return a type which
is *indirectly* invalid if T is not an iterator (indirectly = causes an
instantiation error, rather than being directly invalid and trigger SFINAE), so
I don't think it affects v3 that much.
Giovanni Bajo
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15910