type_traits.h revision 193323
1193323Sed//===- llvm/Support/type_traits.h - Simplfied type traits -------*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file provides a template class that determines if a type is a class or 11193323Sed// not. The basic mechanism, based on using the pointer to member function of 12193323Sed// a zero argument to a function was "boosted" from the boost type_traits 13193323Sed// library. See http://www.boost.org/ for all the gory details. 14193323Sed// 15193323Sed//===----------------------------------------------------------------------===// 16193323Sed 17193323Sed#ifndef LLVM_SUPPORT_TYPE_TRAITS_H 18193323Sed#define LLVM_SUPPORT_TYPE_TRAITS_H 19193323Sed 20193323Sed// This is actually the conforming implementation which works with abstract 21193323Sed// classes. However, enough compilers have trouble with it that most will use 22193323Sed// the one in boost/type_traits/object_traits.hpp. This implementation actually 23193323Sed// works with VC7.0, but other interactions seem to fail when we use it. 24193323Sed 25193323Sednamespace llvm { 26193323Sed 27193323Sednamespace dont_use 28193323Sed{ 29193323Sed // These two functions should never be used. They are helpers to 30193323Sed // the is_class template below. They cannot be located inside 31193323Sed // is_class because doing so causes at least GCC to think that 32193323Sed // the value of the "value" enumerator is not constant. Placing 33193323Sed // them out here (for some strange reason) allows the sizeof 34193323Sed // operator against them to magically be constant. This is 35193323Sed // important to make the is_class<T>::value idiom zero cost. it 36193323Sed // evaluates to a constant 1 or 0 depending on whether the 37193323Sed // parameter T is a class or not (respectively). 38193323Sed template<typename T> char is_class_helper(void(T::*)(void)); 39193323Sed template<typename T> double is_class_helper(...); 40193323Sed} 41193323Sed 42193323Sedtemplate <typename T> 43193323Sedstruct is_class 44193323Sed{ 45193323Sed // is_class<> metafunction due to Paul Mensonides (leavings@attbi.com). For 46193323Sed // more details: 47193323Sed // http://groups.google.com/groups?hl=en&selm=000001c1cc83%24e154d5e0%247772e50c%40c161550a&rnum=1 48193323Sed public: 49193323Sed enum { value = sizeof(char) == sizeof(dont_use::is_class_helper<T>(0)) }; 50193323Sed}; 51193323Sed 52193323Sed} 53193323Sed 54193323Sed#endif 55