1 ///////////////////////////////////////////////////////////////////////////// 2 // Copyright (c) Electronic Arts Inc. All rights reserved. 3 ///////////////////////////////////////////////////////////////////////////// 4 5 /////////////////////////////////////////////////////////////////////////////// 6 // The design for call_traits here is very similar to that found in template 7 // metaprogramming libraries such as Boost, GCC, and Metrowerks, given that 8 // these libraries have established this interface as a defacto standard for 9 // solving this problem. Also, these are described in various books on the 10 // topic of template metaprogramming, such as "Modern C++ Design". 11 // 12 // See http://www.boost.org/libs/utility/call_traits.htm or search for 13 // call_traits in Google for a description of call_traits. 14 /////////////////////////////////////////////////////////////////////////////// 15 16 17 #ifndef EASTL_CALL_TRAITS_H 18 #define EASTL_CALL_TRAITS_H 19 20 21 #include <EASTL/internal/config.h> 22 #include <EASTL/type_traits.h> 23 24 #if defined(EA_PRAGMA_ONCE_SUPPORTED) 25 #pragma once // Some compilers (e.g. VC++) benefit significantly from using this. We've measured 3-4% build speed improvements in apps as a result. 26 #endif 27 28 29 30 namespace eastl 31 { 32 33 34 template <typename T, bool small_> 35 struct ct_imp2 { typedef const T& param_type; }; 36 37 template <typename T> 38 struct ct_imp2<T, true> { typedef const T param_type; }; 39 40 template <typename T, bool isp, bool b1> 41 struct ct_imp { typedef const T& param_type; }; 42 43 template <typename T, bool isp> 44 struct ct_imp<T, isp, true> { typedef typename ct_imp2<T, sizeof(T) <= sizeof(void*)>::param_type param_type; }; 45 46 template <typename T, bool b1> 47 struct ct_imp<T, true, b1> { typedef T const param_type; }; 48 49 50 51 template <typename T> 52 struct call_traits 53 { 54 public: 55 typedef T value_type; 56 typedef T& reference; 57 typedef const T& const_reference; 58 typedef typename ct_imp<T, is_pointer<T>::value, is_arithmetic<T>::value>::param_type param_type; 59 }; 60 61 62 template <typename T> 63 struct call_traits<T&> 64 { 65 typedef T& value_type; 66 typedef T& reference; 67 typedef const T& const_reference; 68 typedef T& param_type; 69 }; 70 71 72 template <typename T, size_t N> 73 struct call_traits<T [N]> 74 { 75 private: 76 typedef T array_type[N]; 77 78 public: 79 typedef const T* value_type; 80 typedef array_type& reference; 81 typedef const array_type& const_reference; 82 typedef const T* const param_type; 83 }; 84 85 86 template <typename T, size_t N> 87 struct call_traits<const T [N]> 88 { 89 private: 90 typedef const T array_type[N]; 91 92 public: 93 typedef const T* value_type; 94 typedef array_type& reference; 95 typedef const array_type& const_reference; 96 typedef const T* const param_type; 97 }; 98 99 100 } // namespace eastl 101 102 103 #endif // Header include guard 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118