Re: [Boost-users] Puzzled: compiler can't find a match for function call

________________________________________ De: boost-users-bounces@lists.boost.org [boost-users-bounces@lists.boost.org] En nombre de Zeljko Vrba [zvrba@ifi.uio.no] Enviado el: jueves, 11 de septiembre de 2008 17:05 Para: boost-users@lists.boost.org Asunto: Re: [Boost-users] Puzzled: compiler can't find a match for functioncall
Indeed it works. Could you please explain why the compiler can deduce K in BF::map<BF::pair<K, int> > , but not in typename id_t<K>::type?
Suppose that id_t<K1>::type == id_t<K2>::type == int (for instance). If we pass int, how can the compiler figure out whether it's K1 or K2 that has to be deduced? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

On Thu, Sep 11, 2008 at 05:13:15PM +0200, JOAQUIN M. LOPEZ MU?OZ wrote:
________________________________________ De: boost-users-bounces@lists.boost.org [boost-users-bounces@lists.boost.org] En nombre de Zeljko Vrba [zvrba@ifi.uio.no] Enviado el: jueves, 11 de septiembre de 2008 17:05 Para: boost-users@lists.boost.org Asunto: Re: [Boost-users] Puzzled: compiler can't find a match for functioncall
Indeed it works. Could you please explain why the compiler can deduce K in BF::map<BF::pair<K, int> > , but not in typename id_t<K>::type?
Suppose that id_t<K1>::type == id_t<K2>::type == int (for instance). If we pass int, how can the compiler figure out whether it's K1 or K2 that has to be deduced?
True, but it could look into the ::type typedef, see that it depends on the id_t template argument, and proceed in the same way as when you give it explicitly written out type. (In fact, that's what I expected would happen, since typedef just declares a type alias, not a new type.) OK, I was unsuccessfully trying to make a "template-typedef". Is there a way in which I can shorten BF::map<BF::pair<K, int> > to just something like id_t<K>, but that works with type-deduction?

AMDG Zeljko Vrba wrote:
Suppose that id_t<K1>::type == id_t<K2>::type == int (for instance). If we pass int, how can the compiler figure out whether it's K1 or K2 that has to be deduced?
True, but it could look into the ::type typedef, see that it depends on the id_t template argument, and proceed in the same way as when you give it explicitly written out type. (In fact, that's what I expected would happen, since typedef just declares a type alias, not a new type.)
A template cannot be instantiated until the argument type is known. Because templates are Turing complete, it is not possible in general for the compiler to x-ray class templates.
OK, I was unsuccessfully trying to make a "template-typedef". Is there a way in which I can shorten BF::map<BF::pair<K, int> > to just something like id_t<K>, but that works with type-deduction?
A solution which works if you don't need partial ordering, is to use SFINAE: template<class T> struct is_fusion_map_with_int : boost::mpl::false_ {}; template<class T> struct is_fusion_map_with_int<BF::map<BF::pair<T, int> > > : boost::mpl::true_ {}; template<class T> typename boost::enable_if<is_fusion_map_with_int<T>, T&>::type inc3(T& arg); In Christ, Steven Watanabe
participants (3)
-
JOAQUIN M. LOPEZ MUÑOZ
-
Steven Watanabe
-
Zeljko Vrba