ob_call_traits.hpp
Go to the documentation of this file.
00001 //  (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
00002 //  Use, modification and distribution are subject to the Boost Software License,
00003 //  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
00004 //  http://www.boost.org/LICENSE_1_0.txt).
00005 //
00006 //  See http://www.boost.org/libs/utility for most recent version including documentation.
00007 //
00008 //  Crippled version for crippled compilers:
00009 //  see libs/utility/call_traits.htm
00010 //
00011 
00012 /* Release notes:
00013    01st October 2000:
00014       Fixed call_traits on VC6, using "poor man's partial specialisation",
00015       using ideas taken from "Generative programming" by Krzysztof Czarnecki 
00016       & Ulrich Eisenecker.
00017 */
00018 
00019 #ifndef BOOST_OB_CALL_TRAITS_HPP
00020 #define BOOST_OB_CALL_TRAITS_HPP
00021 
00022 #ifndef BOOST_CONFIG_HPP
00023 #include <boost/config.hpp>
00024 #endif
00025 
00026 #ifndef BOOST_ARITHMETIC_TYPE_TRAITS_HPP
00027 #include <boost/type_traits/arithmetic_traits.hpp>
00028 #endif
00029 #ifndef BOOST_COMPOSITE_TYPE_TRAITS_HPP
00030 #include <boost/type_traits/composite_traits.hpp>
00031 #endif
00032 
00033 namespace boost{
00034 
00035 #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
00036 //
00037 // use member templates to emulate
00038 // partial specialisation:
00039 //
00040 namespace detail{
00041 
00042 template <class T>
00043 struct standard_call_traits
00044 {
00045    typedef T value_type;
00046    typedef T& reference;
00047    typedef const T& const_reference;
00048    typedef const T& param_type;
00049 };
00050 template <class T>
00051 struct simple_call_traits
00052 {
00053    typedef T value_type;
00054    typedef T& reference;
00055    typedef const T& const_reference;
00056    typedef const T param_type;
00057 };
00058 template <class T>
00059 struct reference_call_traits
00060 {
00061    typedef T value_type;
00062    typedef T reference;
00063    typedef T const_reference;
00064    typedef T param_type;
00065 };
00066 
00067 template <bool pointer, bool arithmetic, bool reference>
00068 struct call_traits_chooser
00069 {
00070    template <class T>
00071    struct rebind
00072    {
00073       typedef standard_call_traits<T> type;
00074    };
00075 };
00076 
00077 template <>
00078 struct call_traits_chooser<true, false, false>
00079 {
00080    template <class T>
00081    struct rebind
00082    {
00083       typedef simple_call_traits<T> type;
00084    };
00085 };
00086 
00087 template <>
00088 struct call_traits_chooser<false, false, true>
00089 {
00090    template <class T>
00091    struct rebind
00092    {
00093       typedef reference_call_traits<T> type;
00094    };
00095 };
00096 
00097 template <bool size_is_small> 
00098 struct call_traits_sizeof_chooser2
00099 {
00100    template <class T>
00101    struct small_rebind
00102    {
00103       typedef simple_call_traits<T> small_type;
00104    };
00105 };
00106 
00107 template<> 
00108 struct call_traits_sizeof_chooser2<false>
00109 {
00110    template <class T>
00111    struct small_rebind
00112    {
00113       typedef standard_call_traits<T> small_type;
00114    };
00115 };
00116 
00117 template <>
00118 struct call_traits_chooser<false, true, false>
00119 {
00120    template <class T>
00121    struct rebind
00122    {
00123       enum { sizeof_choice = (sizeof(T) <= sizeof(void*)) };
00124       typedef call_traits_sizeof_chooser2<(sizeof(T) <= sizeof(void*))> chooser;
00125       typedef typename chooser::template small_rebind<T> bound_type;
00126       typedef typename bound_type::small_type type;
00127    };
00128 };
00129 
00130 } // namespace detail
00131 template <typename T>
00132 struct call_traits
00133 {
00134 private:
00135     typedef detail::call_traits_chooser<
00136          ::boost::is_pointer<T>::value,
00137          ::boost::is_arithmetic<T>::value, 
00138          ::boost::is_reference<T>::value
00139       > chooser;
00140    typedef typename chooser::template rebind<T> bound_type;
00141    typedef typename bound_type::type call_traits_type;
00142 public:
00143    typedef typename call_traits_type::value_type       value_type;
00144    typedef typename call_traits_type::reference        reference;
00145    typedef typename call_traits_type::const_reference  const_reference;
00146    typedef typename call_traits_type::param_type       param_type;
00147 };
00148 
00149 #else
00150 //
00151 // sorry call_traits is completely non-functional
00152 // blame your broken compiler:
00153 //
00154 
00155 template <typename T>
00156 struct call_traits
00157 {
00158    typedef T value_type;
00159    typedef T& reference;
00160    typedef const T& const_reference;
00161    typedef const T& param_type;
00162 };
00163 
00164 #endif // member templates
00165 
00166 }
00167 
00168 #endif // BOOST_OB_CALL_TRAITS_HPP


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29