
Zeljko Vrba wrote:
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?
Read on Boost.Result of and the TR1 result_of conventions. http://www.boost.org/doc/libs/1_36_0/libs/utility/utility.htm http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1454.html 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!
It's not a function call. It's a function declarator. This is first discussed and put into use in the Boost.Function library: http://www.boost.org/doc/libs/1_36_0/doc/html/function/tutorial.html#id29033...
Even worse, why does it work at all when T is not in the scope of the template (.. because it's never used?)
Which template? 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?
Are you sure the one above works? You need the result type, AFAICT. Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net