|
Boost Users : |
From: Zeljko Vrba (zvrba_at_[hidden])
Date: 2008-08-21 13:21:49
I have succeeded in writing the following transform functor:
typedef bf::map<bf::pair<net, unsigned>, bf::pair<pin, unsigned> > Map;
typedef bf::vector<unsigned, unsigned> Pair;
struct Map2Pair
{
template<typename Sig>
struct result;
template<typename U>
struct result<Map2Pair(U)>
: remove_reference<T::second_type>
{ };
template<typename T>
typename T::second_type operator()(T t) const
{
return t.second;
}
};
I have tested it, it works. The result magic has been copied from the
transform_view example in the documentation and adjusted for the proper return
type. Where can I read a bit more about result conventions? In particular,
how does the
template<typename U>
struct result<Map2Pair(U)>
: remove_reference<T::second_type>
{ };
specialization work when Map2Pair is a struct, and it doesn't even have a
constructor! Even worse, why does it work at all when T is not in the
scope of the template (.. because it's never used?) Yes, it is not used,
the following functor also works:
struct Map2Pair
{
template<typename T>
typename T::second_type operator()(T t) const
{
return t.second;
}
};
When and how is the above version preferred than the simpler version?
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