|
Boost Users : |
From: John C. Femiani (john.femiani_at_[hidden])
Date: 2008-07-17 20:54:02
Steven Watanabe wrote:
> AMDG
>
> John C. Femiani wrote:
>> What aspect wouldn't work as I expected? Do you mean that overloads
>> of repr that aren't in namespace boost could occlude ::boost::repr?
>> In that case its a lot like ::boost::begin I think.
>
> You do realize that boost::begin is implemented using
> range_begin which should be defined in the user's namespace, right?
> http://www.boost.org/doc/libs/1_35_0/libs/range/doc/boost_range.html#method2
>
>
Yes, but I thought it worked with std::vector because of the overload of
range_begin that is in the boost namespace. A similar strategy would
_not_ seem to fix your example though.
>
> It fails for exactly the same reason that overloading operator<< does.
>
> In Christ,
> Steven
Aaargh., the overload came too late :(
Will this approach using template specialization work?
//in repr.hpp
namespace boost {
template<class T>
struct repr {
typedef T const& type;
T const& make(T const& arg){
return arg;
}
};
template<class T>
typename repr<T>::type make_repr(T const& arg){
return ::boost::repr<T>().make(arg);
}
}
//In some code
namespace boost {
template<class T>
void print(const T& t) {
std::cout << make_repr(t);
}
}
//This is how you make a proxy
namespace boost {
template<class T>
struct repr<std::vector<T> > {
typedef std::string type;
std::string make(std::vector<T> const& arg){
return "<vector>";
}
};
}
--John
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net