<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Dec 18, 2011, at 1:53 PM, Nicola Gigante wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>Il giorno 18/dic/2011, alle ore 19:12, David Chisnall ha scritto:<br><br><blockquote type="cite">Is this actually required to accomplish what you want?  Any Objective-C type can be implicitly cast to id, so if you have a template specialisation that uses id then it will be selected for any Objective-C type.  You can, for example, implement something like this:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">template<typename T><br></blockquote><blockquote type="cite">bool is_objc_type(T x) { return false; }<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">template<><br></blockquote><blockquote type="cite">bool is_objc_type(id x) { return true; }<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Which will return true when called with an Objective-C type as an argument and false when called with any other type.  <br></blockquote><blockquote type="cite"><br></blockquote><br>Well, that doesn't seam to work, because overloading resolution <br>rules seems to always prefer the template version.<br><br>I had to write something like:<br><br>template<typename T><br>inline typename std::enable_if<!std::is_convertible<T, id>::value, bool>::type<br>is_objc_type(T t) { return false; }<br><br>inline bool is_objc_type(id obj) { return true; }<br><br>But you got the point, yes, an intrinsic is not needed.<br>However, this is still possible only in C++11 mode with<br>the is_convertible type trait, or am I missing something?<font class="Apple-style-span" color="#00731d"><br></font></div></blockquote><br></div><div>This kind of thing works fine in C++98/03 as well. It's probably worth checking that T is a pointer type, so you don't treat something like</div><div><br></div><div>struct X {</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>operator id() const;</div><div>};</div><div><br></div><div>as an Objective-C pointer type.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>- Doug</div><br></body></html>