PageRenderTime 18ms CodeModel.GetById 8ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/interprocess/detail/type_traits.hpp

http://hadesmem.googlecode.com/
C++ Header | 166 lines | 120 code | 30 blank | 16 comment | 2 complexity | 1a3e2e5e9107bcbac90b319c1bb41483 MD5 | raw file
  1//////////////////////////////////////////////////////////////////////////////
  2// (C) Copyright John Maddock 2000.
  3// (C) Copyright Ion Gaztanaga 2005-2009.
  4//
  5// Distributed under the Boost Software License, Version 1.0.
  6// (See accompanying file LICENSE_1_0.txt or copy at
  7// http://www.boost.org/LICENSE_1_0.txt)
  8//
  9// See http://www.boost.org/libs/interprocess for documentation.
 10//
 11// The alignment_of implementation comes from John Maddock's boost::alignment_of code
 12//
 13//////////////////////////////////////////////////////////////////////////////
 14
 15#ifndef BOOST_INTERPROCESS_DETAIL_TYPE_TRAITS_HPP
 16#define BOOST_INTERPROCESS_DETAIL_TYPE_TRAITS_HPP
 17
 18#if (defined _MSC_VER) && (_MSC_VER >= 1200)
 19#  pragma once
 20#endif
 21
 22#include <boost/interprocess/detail/config_begin.hpp>
 23
 24namespace boost {
 25namespace interprocess { 
 26namespace detail {
 27
 28struct nat{};
 29
 30//boost::alignment_of yields to 10K lines of preprocessed code, so we
 31//need an alternative
 32template <typename T> struct alignment_of;
 33
 34template <typename T>
 35struct alignment_of_hack
 36{
 37    char c;
 38    T t;
 39    alignment_of_hack();
 40};
 41
 42template <unsigned A, unsigned S>
 43struct alignment_logic
 44{
 45    enum{   value = A < S ? A : S  };
 46};
 47
 48template< typename T >
 49struct alignment_of
 50{
 51   enum{ value = alignment_logic
 52            < sizeof(alignment_of_hack<T>) - sizeof(T)
 53            , sizeof(T)>::value   };
 54};
 55
 56//This is not standard, but should work with all compilers
 57union max_align
 58{
 59   char        char_;
 60   short       short_;
 61   int         int_;
 62   long        long_;
 63   #ifdef BOOST_HAS_LONG_LONG
 64   long long   long_long_;
 65   #endif
 66   float       float_;
 67   double      double_;
 68   long double long_double_;
 69   void *      void_ptr_;
 70};
 71
 72template<class T>
 73struct remove_reference
 74{
 75   typedef T type;
 76};
 77
 78template<class T>
 79struct remove_reference<T&>
 80{
 81   typedef T type;
 82};
 83
 84template<class T>
 85struct is_reference
 86{
 87   enum {  value = false   };
 88};
 89
 90template<class T>
 91struct is_reference<T&>
 92{
 93   enum {  value = true   };
 94};
 95
 96template<class T>
 97struct is_pointer
 98{
 99   enum {  value = false   };
100};
101
102template<class T>
103struct is_pointer<T*>
104{
105   enum {  value = true   };
106};
107
108template <typename T>
109struct add_reference
110{
111    typedef T& type;
112};
113
114template<class T>
115struct add_reference<T&>
116{
117    typedef T& type;
118};
119
120template<>
121struct add_reference<void>
122{
123    typedef nat &type;
124};
125
126template<>
127struct add_reference<const void>
128{
129    typedef const nat &type;
130};
131
132template <class T>
133struct add_const_reference
134{  typedef const T &type;   };
135
136template <class T>
137struct add_const_reference<T&>
138{  typedef T& type;   };
139
140template <typename T, typename U>
141struct is_same
142{
143   typedef char yes_type;
144   struct no_type
145   {
146      char padding[8];
147   };
148
149   template <typename V>
150   static yes_type is_same_tester(V*, V*);
151   static no_type is_same_tester(...);
152
153   static T *t;
154   static U *u;
155
156   static const bool value = sizeof(yes_type) == sizeof(is_same_tester(t,u));
157};
158
159} // namespace detail
160}  //namespace interprocess { 
161}  //namespace boost {
162
163#endif   //#ifndef BOOST_INTERPROCESS_DETAIL_TYPE_TRAITS_HPP
164
165#include <boost/interprocess/detail/config_end.hpp>
166