annotate DEPENDENCIES/generic/include/boost/multi_index/member.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@101 1 /* Copyright 2003-2013 Joaquin M Lopez Munoz.
Chris@16 2 * Distributed under the Boost Software License, Version 1.0.
Chris@16 3 * (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 4 * http://www.boost.org/LICENSE_1_0.txt)
Chris@16 5 *
Chris@16 6 * See http://www.boost.org/libs/multi_index for library home page.
Chris@16 7 */
Chris@16 8
Chris@16 9 #ifndef BOOST_MULTI_INDEX_MEMBER_HPP
Chris@16 10 #define BOOST_MULTI_INDEX_MEMBER_HPP
Chris@16 11
Chris@101 12 #if defined(_MSC_VER)
Chris@16 13 #pragma once
Chris@16 14 #endif
Chris@16 15
Chris@16 16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
Chris@16 17 #include <boost/mpl/if.hpp>
Chris@16 18 #include <boost/type_traits/is_const.hpp>
Chris@16 19 #include <boost/utility/enable_if.hpp>
Chris@16 20 #include <cstddef>
Chris@16 21
Chris@16 22 #if !defined(BOOST_NO_SFINAE)
Chris@16 23 #include <boost/type_traits/is_convertible.hpp>
Chris@16 24 #endif
Chris@16 25
Chris@16 26 namespace boost{
Chris@16 27
Chris@16 28 template<class T> class reference_wrapper; /* fwd decl. */
Chris@16 29
Chris@16 30 namespace multi_index{
Chris@16 31
Chris@16 32 namespace detail{
Chris@16 33
Chris@16 34 /* member is a read/write key extractor for accessing a given
Chris@16 35 * member of a class.
Chris@16 36 * Additionally, member is overloaded to support referece_wrappers
Chris@16 37 * of T and "chained pointers" to T's. By chained pointer to T we mean
Chris@16 38 * a type P such that, given a p of Type P
Chris@16 39 * *...n...*x is convertible to T&, for some n>=1.
Chris@16 40 * Examples of chained pointers are raw and smart pointers, iterators and
Chris@16 41 * arbitrary combinations of these (vg. T** or auto_ptr<T*>.)
Chris@16 42 */
Chris@16 43
Chris@16 44 template<class Class,typename Type,Type Class::*PtrToMember>
Chris@16 45 struct const_member_base
Chris@16 46 {
Chris@16 47 typedef Type result_type;
Chris@16 48
Chris@16 49 template<typename ChainedPtr>
Chris@16 50
Chris@16 51 #if !defined(BOOST_NO_SFINAE)
Chris@16 52 typename disable_if<
Chris@16 53 is_convertible<const ChainedPtr&,const Class&>,Type&>::type
Chris@16 54 #else
Chris@16 55 Type&
Chris@16 56 #endif
Chris@16 57
Chris@16 58 operator()(const ChainedPtr& x)const
Chris@16 59 {
Chris@16 60 return operator()(*x);
Chris@16 61 }
Chris@16 62
Chris@16 63 Type& operator()(const Class& x)const
Chris@16 64 {
Chris@16 65 return x.*PtrToMember;
Chris@16 66 }
Chris@16 67
Chris@16 68 Type& operator()(const reference_wrapper<const Class>& x)const
Chris@16 69 {
Chris@16 70 return operator()(x.get());
Chris@16 71 }
Chris@16 72
Chris@101 73 Type& operator()(const reference_wrapper<Class>& x)const
Chris@16 74 {
Chris@16 75 return operator()(x.get());
Chris@16 76 }
Chris@16 77 };
Chris@16 78
Chris@16 79 template<class Class,typename Type,Type Class::*PtrToMember>
Chris@16 80 struct non_const_member_base
Chris@16 81 {
Chris@16 82 typedef Type result_type;
Chris@16 83
Chris@16 84 template<typename ChainedPtr>
Chris@16 85
Chris@16 86 #if !defined(BOOST_NO_SFINAE)
Chris@16 87 typename disable_if<
Chris@16 88 is_convertible<const ChainedPtr&,const Class&>,Type&>::type
Chris@16 89 #else
Chris@16 90 Type&
Chris@16 91 #endif
Chris@16 92
Chris@16 93 operator()(const ChainedPtr& x)const
Chris@16 94 {
Chris@16 95 return operator()(*x);
Chris@16 96 }
Chris@16 97
Chris@101 98 const Type& operator()(const Class& x)const
Chris@16 99 {
Chris@16 100 return x.*PtrToMember;
Chris@16 101 }
Chris@16 102
Chris@16 103 Type& operator()(Class& x)const
Chris@16 104 {
Chris@16 105 return x.*PtrToMember;
Chris@16 106 }
Chris@16 107
Chris@101 108 const Type& operator()(const reference_wrapper<const Class>& x)const
Chris@16 109 {
Chris@16 110 return operator()(x.get());
Chris@16 111 }
Chris@16 112
Chris@16 113 Type& operator()(const reference_wrapper<Class>& x)const
Chris@16 114 {
Chris@16 115 return operator()(x.get());
Chris@16 116 }
Chris@16 117 };
Chris@16 118
Chris@16 119 } /* namespace multi_index::detail */
Chris@16 120
Chris@16 121 template<class Class,typename Type,Type Class::*PtrToMember>
Chris@16 122 struct member:
Chris@16 123 mpl::if_c<
Chris@16 124 is_const<Type>::value,
Chris@16 125 detail::const_member_base<Class,Type,PtrToMember>,
Chris@16 126 detail::non_const_member_base<Class,Type,PtrToMember>
Chris@16 127 >::type
Chris@16 128 {
Chris@16 129 };
Chris@16 130
Chris@16 131 namespace detail{
Chris@16 132
Chris@16 133 /* MSVC++ 6.0 does not support properly pointers to members as
Chris@16 134 * non-type template arguments, as reported in
Chris@16 135 * http://support.microsoft.com/default.aspx?scid=kb;EN-US;249045
Chris@16 136 * A similar problem (though not identical) is shown by MSVC++ 7.0.
Chris@16 137 * We provide an alternative to member<> accepting offsets instead
Chris@16 138 * of pointers to members. This happens to work even for non-POD
Chris@16 139 * types (although the standard forbids use of offsetof on these),
Chris@16 140 * so it serves as a workaround in this compiler for all practical
Chris@16 141 * purposes.
Chris@16 142 * Surprisingly enough, other compilers, like Intel C++ 7.0/7.1 and
Chris@16 143 * Visual Age 6.0, have similar bugs. This replacement of member<>
Chris@16 144 * can be used for them too.
Chris@101 145 *
Chris@101 146 * Support for such old compilers is dropped and
Chris@101 147 * [non_]const_member_offset_base is deprecated.
Chris@16 148 */
Chris@16 149
Chris@16 150 template<class Class,typename Type,std::size_t OffsetOfMember>
Chris@16 151 struct const_member_offset_base
Chris@16 152 {
Chris@16 153 typedef Type result_type;
Chris@16 154
Chris@16 155 template<typename ChainedPtr>
Chris@16 156
Chris@16 157 #if !defined(BOOST_NO_SFINAE)
Chris@16 158 typename disable_if<
Chris@16 159 is_convertible<const ChainedPtr&,const Class&>,Type&>::type
Chris@16 160 #else
Chris@16 161 Type&
Chris@16 162 #endif
Chris@16 163
Chris@16 164 operator()(const ChainedPtr& x)const
Chris@16 165 {
Chris@16 166 return operator()(*x);
Chris@16 167 }
Chris@16 168
Chris@16 169 Type& operator()(const Class& x)const
Chris@16 170 {
Chris@16 171 return *static_cast<const Type*>(
Chris@16 172 static_cast<const void*>(
Chris@16 173 static_cast<const char*>(
Chris@16 174 static_cast<const void *>(&x))+OffsetOfMember));
Chris@16 175 }
Chris@16 176
Chris@16 177 Type& operator()(const reference_wrapper<const Class>& x)const
Chris@16 178 {
Chris@16 179 return operator()(x.get());
Chris@16 180 }
Chris@16 181
Chris@101 182 Type& operator()(const reference_wrapper<Class>& x)const
Chris@16 183 {
Chris@16 184 return operator()(x.get());
Chris@16 185 }
Chris@16 186 };
Chris@16 187
Chris@16 188 template<class Class,typename Type,std::size_t OffsetOfMember>
Chris@16 189 struct non_const_member_offset_base
Chris@16 190 {
Chris@16 191 typedef Type result_type;
Chris@16 192
Chris@16 193 template<typename ChainedPtr>
Chris@16 194
Chris@16 195 #if !defined(BOOST_NO_SFINAE)
Chris@16 196 typename disable_if<
Chris@16 197 is_convertible<const ChainedPtr&,const Class&>,Type&>::type
Chris@16 198 #else
Chris@16 199 Type&
Chris@16 200 #endif
Chris@16 201
Chris@16 202 operator()(const ChainedPtr& x)const
Chris@16 203 {
Chris@16 204 return operator()(*x);
Chris@16 205 }
Chris@16 206
Chris@101 207 const Type& operator()(const Class& x)const
Chris@16 208 {
Chris@16 209 return *static_cast<const Type*>(
Chris@16 210 static_cast<const void*>(
Chris@16 211 static_cast<const char*>(
Chris@16 212 static_cast<const void *>(&x))+OffsetOfMember));
Chris@16 213 }
Chris@16 214
Chris@16 215 Type& operator()(Class& x)const
Chris@16 216 {
Chris@16 217 return *static_cast<Type*>(
Chris@16 218 static_cast<void*>(
Chris@16 219 static_cast<char*>(static_cast<void *>(&x))+OffsetOfMember));
Chris@16 220 }
Chris@16 221
Chris@101 222 const Type& operator()(const reference_wrapper<const Class>& x)const
Chris@16 223 {
Chris@16 224 return operator()(x.get());
Chris@16 225 }
Chris@16 226
Chris@16 227 Type& operator()(const reference_wrapper<Class>& x)const
Chris@16 228 {
Chris@16 229 return operator()(x.get());
Chris@16 230 }
Chris@16 231 };
Chris@16 232
Chris@16 233 } /* namespace multi_index::detail */
Chris@16 234
Chris@16 235 template<class Class,typename Type,std::size_t OffsetOfMember>
Chris@16 236 struct member_offset:
Chris@16 237 mpl::if_c<
Chris@16 238 is_const<Type>::value,
Chris@16 239 detail::const_member_offset_base<Class,Type,OffsetOfMember>,
Chris@16 240 detail::non_const_member_offset_base<Class,Type,OffsetOfMember>
Chris@16 241 >::type
Chris@16 242 {
Chris@16 243 };
Chris@16 244
Chris@16 245 /* BOOST_MULTI_INDEX_MEMBER resolves to member in the normal cases,
Chris@16 246 * and to member_offset as a workaround in those defective compilers for
Chris@16 247 * which BOOST_NO_POINTER_TO_MEMBER_TEMPLATE_PARAMETERS is defined.
Chris@16 248 */
Chris@16 249
Chris@16 250 #if defined(BOOST_NO_POINTER_TO_MEMBER_TEMPLATE_PARAMETERS)
Chris@16 251 #define BOOST_MULTI_INDEX_MEMBER(Class,Type,MemberName) \
Chris@16 252 ::boost::multi_index::member_offset< Class,Type,offsetof(Class,MemberName) >
Chris@16 253 #else
Chris@16 254 #define BOOST_MULTI_INDEX_MEMBER(Class,Type,MemberName) \
Chris@16 255 ::boost::multi_index::member< Class,Type,&Class::MemberName >
Chris@16 256 #endif
Chris@16 257
Chris@16 258 } /* namespace multi_index */
Chris@16 259
Chris@16 260 } /* namespace boost */
Chris@16 261
Chris@16 262 #endif