[cxx-abi-dev] Magical type trait operators

Howard Hinnant howard.hinnant at gmail.com
Thu May 6 21:27:15 UTC 2010


On May 6, 2010, at 4:32 PM, David Vandevoorde wrote:

> The C++0x standard library has metaprogramming facilities (like the std::is_convertible) that require "magical" support from the compiler.  The principal implementations seem to have converged on nearly-identical "operators" for this.  E.g., std::is_convertible is typically implemented with an operator __is_convertible_to(T, U).
> 
> Now, I _think_ that if code is written only in terms of the standard templates, the operator invocations won't appear in ABI signatures, but I'd like confirmation of that.
> 
> Even so, would it be worthwhile to specify what the magical operators are, and how they are mangled?
> 
> Here is an example to illustrate:
> 
> 	struct A {
> 	  A();
> 	  A(A const&);
> 	  ~A();
> 	  operator int();
> 	};
> 	template<class T> auto f(T p)->decltype(__is_convertible_to(T, int) ? p : 0) {
> 	  return p;
> 	}
> 	int main() {
> 	  A a;
> 	  f(a);
> 	}
> 

Here is a straw-man I wrote up several years ago.  And it has been that long since I looked at it.  It needs updating to the current list of traits (e.g. is_constructible).

http://home.roadrunner.com/~hinnant/builtin_traits.html

-Howard




More information about the cxx-abi-dev mailing list