utilities.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 890 行 · 第 1/2 页
HPP
890 行
//!Obtains a generic pointer of the same type that//!can point to other pointed type: Ptr<?> -> Ptr<NewValueType>template<class T, class U>struct pointer_to_other;template<class T, class U, template<class> class Sp>struct pointer_to_other< Sp<T>, U >{ typedef Sp<U> type;};template<class T, class T2, class U, template<class, class> class Sp>struct pointer_to_other< Sp<T, T2>, U >{ typedef Sp<U, T2> type;};template<class T, class T2, class T3, class U, template<class, class, class> class Sp>struct pointer_to_other< Sp<T, T2, T3>, U >{ typedef Sp<U, T2, T3> type;};template<class T, class U>struct pointer_to_other< T*, U >{ typedef U* type;};} //namespace detail {//!Trait class to detect if an index is a node//!index. This allows more efficient operations//!when deallocating named objects.template <class Index>struct is_node_index{ enum { value = false };};//!Trait class to detect if an index is an intrusive//!index. This will embed the derivation hook in each//!allocation header, to provide memory for the intrusive//!container.template <class Index>struct is_intrusive_index{ enum { value = false };};template <class SizeType>SizeType get_next_capacity(const SizeType max_size ,const SizeType capacity ,const SizeType n){// if (n > max_size - capacity)// throw std::length_error("get_next_capacity"); const SizeType m3 = max_size/3; if (capacity < m3) return capacity + max_value(3*(capacity+1)/5, n); if (capacity < m3*2) return capacity + max_value((capacity+1)/2, n); return max_size;}namespace detail {template <class T1, class T2>struct pair{ typedef T1 first_type; typedef T2 second_type; T1 first; T2 second; //std::pair compatibility template <class D, class S> pair(const std::pair<D, S>& p) : first(p.first), second(p.second) {} //To resolve ambiguity with the variadic constructor of 1 argument //and the previous constructor pair(std::pair<T1, T2>& x) : first(x.first), second(x.second) {} #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE template <class D, class S> pair(const detail::moved_object<std::pair<D, S> >& p) : first(detail::move_impl(p.get().first)), second(detail::move_impl(p.get().second)) {} #else template <class D, class S> pair(std::pair<D, S> && p) : first(detail::move_impl(p.first)), second(detail::move_impl(p.second)) {} #endif pair() : first(), second() {} pair(const pair<T1, T2>& x) : first(x.first), second(x.second) {} //To resolve ambiguity with the variadic constructor of 1 argument //and the copy constructor pair(pair<T1, T2>& x) : first(x.first), second(x.second) {} #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE pair(const detail::moved_object<pair<T1, T2> >& p) : first(detail::move_impl(p.get().first)), second(detail::move_impl(p.get().second)) {} #else pair(pair<T1, T2> && p) : first(detail::move_impl(p.first)), second(detail::move_impl(p.second)) {} #endif #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE template <class D, class S> pair(const detail::moved_object<pair<D, S> >& p) : first(detail::move_impl(p.get().first)), second(detail::move_impl(p.get().second)) {} #else template <class D, class S> pair(pair<D, S> && p) : first(detail::move_impl(p.first)), second(detail::move_impl(p.second)) {} #endif #ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING template<class U, class ...Args> pair(U &&u, Args &&... args) : first(detail::forward_impl<U>(u)) , second(detail::forward_impl<Args>(args)...) {} #else template<class U> pair(BOOST_INTERPROCESS_PARAM(U, u)) : first(detail::forward_impl<U>(u)) {} #define BOOST_PP_LOCAL_MACRO(n) \ template<class U, BOOST_PP_ENUM_PARAMS(n, class P)> \ pair(BOOST_INTERPROCESS_PARAM(U, u) \ ,BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_PARAM_LIST, _)) \ : first(detail::forward_impl<U>(u)) \ , second(BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_PARAM_FORWARD, _)) \ {} \ //! #define BOOST_PP_LOCAL_LIMITS (1, BOOST_INTERPROCESS_MAX_CONSTRUCTOR_PARAMETERS) #include BOOST_PP_LOCAL_ITERATE() #endif #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE pair& operator=(const detail::moved_object<pair<T1, T2> > &p) { first = detail::move_impl(p.get().first); second = detail::move_impl(p.get().second); return *this; } #else pair& operator=(pair<T1, T2> &&p) { first = detail::move_impl(p.first); second = detail::move_impl(p.second); return *this; } #endif #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE pair& operator=(const detail::moved_object<std::pair<T1, T2> > &p) { first = detail::move_impl(p.get().first); second = detail::move_impl(p.get().second); return *this; } #else pair& operator=(std::pair<T1, T2> &&p) { first = detail::move_impl(p.first); second = detail::move_impl(p.second); return *this; } #endif #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE template <class D, class S> pair& operator=(const detail::moved_object<std::pair<D, S> > &p) { first = detail::move_impl(p.get().first); second = detail::move_impl(p.get().second); return *this; } #else template <class D, class S> pair& operator=(std::pair<D, S> &&p) { first = detail::move_impl(p.first); second = detail::move_impl(p.second); return *this; } #endif #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE void swap(const detail::moved_object<pair> &p) { std::swap(*this, p.get()); } void swap(pair& p) { std::swap(*this, p); } #else void swap(pair &&p) { std::swap(*this, p); } #endif};template <class T1, class T2>inline bool operator==(const pair<T1,T2>& x, const pair<T1,T2>& y){ return static_cast<bool>(x.first == y.first && x.second == y.second); }template <class T1, class T2>inline bool operator< (const pair<T1,T2>& x, const pair<T1,T2>& y){ return static_cast<bool>(x.first < y.first || (!(y.first < x.first) && x.second < y.second)); }template <class T1, class T2>inline bool operator!=(const pair<T1,T2>& x, const pair<T1,T2>& y){ return static_cast<bool>(!(x == y)); }template <class T1, class T2>inline bool operator> (const pair<T1,T2>& x, const pair<T1,T2>& y){ return y < x; }template <class T1, class T2>inline bool operator>=(const pair<T1,T2>& x, const pair<T1,T2>& y){ return static_cast<bool>(!(x < y)); }template <class T1, class T2>inline bool operator<=(const pair<T1,T2>& x, const pair<T1,T2>& y){ return static_cast<bool>(!(y < x)); }template <class T1, class T2>inline pair<T1, T2> make_pair(T1 x, T2 y){ return pair<T1, T2>(x, y); }#ifndef BOOST_INTERPROCESS_RVALUE_REFERENCEtemplate <class T1, class T2>inline void swap(const detail::moved_object<pair<T1, T2> > &x, pair<T1, T2>& y){ swap(x.get().first, y.first); swap(x.get().second, y.second);}template <class T1, class T2>inline void swap(pair<T1, T2>& x, const detail::moved_object<pair<T1, T2> > &y){ swap(x.first, y.get().first); swap(x.second, y.get().second);}template <class T1, class T2>inline void swap(pair<T1, T2>& x, pair<T1, T2>& y){ swap(x.first, y.first); swap(x.second, y.second);}#elsetemplate <class T1, class T2>inline void swap(pair<T1, T2>&&x, pair<T1, T2>&&y){ swap(x.first, y.first); swap(x.second, y.second);}#endiftemplate<class T>struct cast_functor{ typedef typename detail::add_reference<T>::type result_type; result_type operator()(char &ptr) const { return *static_cast<T*>(static_cast<void*>(&ptr)); }};template<class MultiallocChain, class T>class multiallocation_chain_adaptor{ private: MultiallocChain chain_; multiallocation_chain_adaptor (const multiallocation_chain_adaptor &); multiallocation_chain_adaptor &operator= (const multiallocation_chain_adaptor &); public: typedef transform_iterator < typename MultiallocChain:: multiallocation_iterator , detail::cast_functor <T> > multiallocation_iterator; multiallocation_chain_adaptor() : chain_() {} void push_back(T *mem) { chain_.push_back(mem); } void push_front(T *mem) { chain_.push_front(mem); } void swap(multiallocation_chain_adaptor &other_chain) { chain_.swap(other_chain.chain_); } void splice_back(multiallocation_chain_adaptor &other_chain) { chain_.splice_back(other_chain.chain_); } T *pop_front() { return static_cast<T*>(chain_.pop_front()); } bool empty() const { return chain_.empty(); } multiallocation_iterator get_it() const { return multiallocation_iterator(chain_.get_it()); } std::size_t size() const { return chain_.size(); }};template<class T>struct value_init{ value_init() : m_t() {} T m_t;};} //namespace detail {//!The pair is movable if any of its members is movabletemplate <class T1, class T2>struct is_movable<boost::interprocess::detail::pair<T1, T2> >{ enum { value = is_movable<T1>::value || is_movable<T2>::value };};//!The pair is movable if any of its members is movabletemplate <class T1, class T2>struct is_movable<std::pair<T1, T2> >{ enum { value = is_movable<T1>::value || is_movable<T2>::value };};///has_trivial_destructor_after_move<> == true_type///specialization for optimizationstemplate <class T>struct has_trivial_destructor_after_move : public boost::has_trivial_destructor<T>{};template <typename T> T*addressof(T& v){ return reinterpret_cast<T*>( &const_cast<char&>(reinterpret_cast<const volatile char &>(v)));}//Anti-exception node erasertemplate<class Cont>class value_eraser{ public: value_eraser(Cont & cont, typename Cont::iterator it) : m_cont(cont), m_index_it(it), m_erase(true){} ~value_eraser() { if(m_erase) m_cont.erase(m_index_it); } void release() { m_erase = false; } private: Cont &m_cont; typename Cont::iterator m_index_it; bool m_erase;};template <class T>struct sizeof_value{ static const std::size_t value = sizeof(T);};template <>struct sizeof_value<void>{ static const std::size_t value = sizeof(void*);};template <>struct sizeof_value<const void>{ static const std::size_t value = sizeof(void*);};template <>struct sizeof_value<volatile void>{ static const std::size_t value = sizeof(void*);};template <>struct sizeof_value<const volatile void>{ static const std::size_t value = sizeof(void*);};} //namespace interprocess { } //namespace boost {#include <boost/interprocess/detail/config_end.hpp>#endif //#ifndef BOOST_INTERPROCESS_DETAIL_UTILITIES_HPP
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?