您的位置:首页 > 大数据 > 人工智能

再续:增强boost中function_traits的能力

2006-09-12 14:52 411 查看
关于这个问题,John Maddock老大在新闻组里面给出了很详细的解答,虽然我还有些问题要问,不过得好好组织一下怎么说才行……可不要浪费网络资源哈~主要意思是,对于成员函数traits而言,一方面有const和volatile的麻烦事情,另一方面又有一个隐含的this参数不好处理(究竟是算一个入口参数还是不算?),最重要的是这种应用需求完全可以用其他方式替代。所以,John认为没有必要实现这样的功能。回信全文如下:From: John Maddock <john <at> johnmaddock.co.uk>Subject: Re: [type_traits]Member function traits in function_traits?Newsgroups: gmane.comp.lib.boost.develDate: 2006-09-11 17:41:01 GMT (12 hours and 41 minutes ago)Realdodo Du wrote:> I'm not sure the meaning of "wider questions". Could anyone tell me> what is the question and the differences between global function> pointers and member function pointers, please?OK let me try and explain:Function traits only recognises function types, for example given:typedef int ft(int);ft is a function type whose type is "int (int)", you can declare a functionwith it:ft myproc; // declares int myproc(int)but that's about it.In contrast a function pointer:int (*)(int)or a function reference:int (&)(int)can *not* be passed to function_traits, but you can always useremove_pointer or remove_reference respectively to convert them to somethingthat you can.Now, for member-functions there is no such type as "member function" onlypointers to member functions, for example:int (myclass::*)(int)You cannot pass such a type to function_traits, and you can't useremove_pointer to convert it to something that you can either.Now... if you try and extend function_traits to deal withmember-function-pointers the you get all kinds of tricky questions, like"what is the functions arity?" - does the hidden "this" pointer count inother words.Then you have to decide what to do about const or volatile qualifiedfunctions etc.So... the question might be, why not a remove_member_pointer trait thatconverts:T (U::*) to Texcept that no one seems to have thought of let alone needed such a beastuntil now.So.... the follow up question might be, since your code has to handlemember-function-pointers differently from regular function-pointers, why notchange:template <class T>void f(T f){typedef function_traits<typename remove_pointer<T>::type> ft;// use ft here...}totemplate <class T, class U>void f(T (U::*)){typedef function_traits<T> ft;// use ft here, T is deduced as a function type}which obviously may or may not look anything like your actual codeTo conclude, how should this best be handled?John._______________________________________________Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
document.domain = 'gmane.org';document.title = 'Re:  type traits Member function traits in function traits?';
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: