Changes For Bug 352
[oota-llvm.git] / include / llvm / Support / type_traits.h
1 //===- llvm/Support/type_traits.h - Simplfied type traits -------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file provides a template class that determines if a type is a class or
11 // not. The basic mechanism, based on using the pointer to member function of
12 // a zero argument to a function was "boosted" from the boost type_traits 
13 // library. See http://www.boost.org/ for all the gory details. 
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_SUPPORT_TYPE_TRAITS_H
18 #define LLVM_SUPPORT_TYPE_TRAITS_H
19
20 // This is actually the conforming implementation which works with abstract
21 // classes.  However, enough compilers have trouble with it that most will use
22 // the one in boost/type_traits/object_traits.hpp. This implementation actually
23 // works with VC7.0, but other interactions seem to fail when we use it.
24
25 namespace llvm {
26
27 namespace dont_use
28 {
29     // These two functions should never be used. They are helpers to
30     // the is_class template below. They cannot be located inside 
31     // is_class because doing so causes at least GCC to think that
32     // the value of the "value" enumerator is not constant. Placing
33     // them out here (for some strange reason) allows the sizeof 
34     // operator against them to magically be constant. This is
35     // important to make the is_class<T>::value idiom zero cost. it
36     // evaluates to a constant 1 or 0 depending on whether the 
37     // parameter T is a class or not (respectively).
38     template<typename T> char is_class_helper(void(T::*)(void));
39     template<typename T> double is_class_helper(...);
40 }
41
42 template <typename T>
43 struct is_class
44 {
45   // is_class<> metafunction due to Paul Mensonides (leavings@attbi.com). For
46   // more details:
47   // http://groups.google.com/groups?hl=en&selm=000001c1cc83%24e154d5e0%247772e50c%40c161550a&rnum=1
48  public:
49     enum { value = sizeof(char) == sizeof(dont_use::is_class_helper<T>(0)) };
50 };
51
52 }
53
54 #endif