type_traits.h revision 193323
1262569Simp//===- llvm/Support/type_traits.h - Simplfied type traits -------*- C++ -*-===// 2262569Simp// 3262569Simp// The LLVM Compiler Infrastructure 4262569Simp// 5262569Simp// This file is distributed under the University of Illinois Open Source 6262569Simp// License. See LICENSE.TXT for details. 7262569Simp// 8262569Simp//===----------------------------------------------------------------------===// 9262569Simp// 10262569Simp// This file provides a template class that determines if a type is a class or 11262569Simp// not. The basic mechanism, based on using the pointer to member function of 12262569Simp// a zero argument to a function was "boosted" from the boost type_traits 13262569Simp// library. See http://www.boost.org/ for all the gory details. 14262569Simp// 15262569Simp//===----------------------------------------------------------------------===// 16262569Simp 17262569Simp#ifndef LLVM_SUPPORT_TYPE_TRAITS_H 18262569Simp#define LLVM_SUPPORT_TYPE_TRAITS_H 19262569Simp 20262569Simp// This is actually the conforming implementation which works with abstract 21262569Simp// classes. However, enough compilers have trouble with it that most will use 22262569Simp// the one in boost/type_traits/object_traits.hpp. This implementation actually 23262569Simp// works with VC7.0, but other interactions seem to fail when we use it. 24262569Simp 25262569Simpnamespace llvm { 26262569Simp 27262569Simpnamespace dont_use 28262569Simp{ 29262569Simp // These two functions should never be used. They are helpers to 30262569Simp // the is_class template below. They cannot be located inside 31262569Simp // is_class because doing so causes at least GCC to think that 32262569Simp // the value of the "value" enumerator is not constant. Placing 33262569Simp // them out here (for some strange reason) allows the sizeof 34262569Simp // operator against them to magically be constant. This is 35262569Simp // important to make the is_class<T>::value idiom zero cost. it 36262569Simp // evaluates to a constant 1 or 0 depending on whether the 37262569Simp // parameter T is a class or not (respectively). 38262569Simp template<typename T> char is_class_helper(void(T::*)(void)); 39262569Simp template<typename T> double is_class_helper(...); 40262569Simp} 41262569Simp 42262569Simptemplate <typename T> 43262569Simpstruct is_class 44262569Simp{ 45262569Simp // is_class<> metafunction due to Paul Mensonides (leavings@attbi.com). For 46262569Simp // more details: 47262569Simp // http://groups.google.com/groups?hl=en&selm=000001c1cc83%24e154d5e0%247772e50c%40c161550a&rnum=1 48262569Simp public: 49262569Simp enum { value = sizeof(char) == sizeof(dont_use::is_class_helper<T>(0)) }; 50262569Simp}; 51262569Simp 52262569Simp} 53262569Simp 54262569Simp#endif 55262569Simp