Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/intrusive/detail/array_initializer.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga  2014-2014
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 //    (See accompanying file LICENSE_1_0.txt or copy at
0007 //          http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 // See http://www.boost.org/libs/intrusive for documentation.
0010 //
0011 /////////////////////////////////////////////////////////////////////////////
0012 
0013 #ifndef BOOST_INTRUSIVE_DETAIL_ARRAY_INITIALIZER_HPP
0014 #define BOOST_INTRUSIVE_DETAIL_ARRAY_INITIALIZER_HPP
0015 
0016 #ifndef BOOST_CONFIG_HPP
0017 #  include <boost/config.hpp>
0018 #endif
0019 
0020 #if defined(BOOST_HAS_PRAGMA_ONCE)
0021 #  pragma once
0022 #endif
0023 
0024 #include <boost/config.hpp>
0025 #include <boost/intrusive/detail/workaround.hpp>
0026 #include <boost/move/detail/placement_new.hpp>
0027 #include <boost/move/detail/force_ptr.hpp>
0028 
0029 namespace boost {
0030 namespace intrusive {
0031 namespace detail {
0032 
0033 //This is not standard, but should work with all compilers
0034 union max_align
0035 {
0036    char        char_;
0037    short       short_;
0038    int         int_;
0039    long        long_;
0040    #ifdef BOOST_HAS_LONG_LONG
0041    ::boost::long_long_type  long_long_;
0042    #endif
0043    float       float_;
0044    double      double_;
0045    long double long_double_;
0046    void *      void_ptr_;
0047 };
0048 
0049 template<class T, std::size_t N>
0050 class array_initializer
0051 {
0052    public:
0053    template<class CommonInitializer>
0054    array_initializer(const CommonInitializer &init)
0055    {
0056       char *init_buf = (char*)rawbuf;
0057       std::size_t i = 0;
0058       BOOST_INTRUSIVE_TRY{
0059          for(; i != N; ++i){
0060             ::new(init_buf, boost_move_new_t()) T(init);
0061             init_buf += sizeof(T);
0062          }
0063       }
0064       BOOST_INTRUSIVE_CATCH(...){
0065          while(i--){
0066             init_buf -= sizeof(T);
0067             move_detail::force_ptr<T*>(init_buf)->~T();
0068          }
0069          BOOST_INTRUSIVE_RETHROW;
0070       }
0071       BOOST_INTRUSIVE_CATCH_END
0072    }
0073 
0074    operator T* ()
0075    {  return (T*)(rawbuf);  }
0076 
0077    operator const T*() const
0078    {  return (const T*)(rawbuf);  }
0079 
0080    ~array_initializer()
0081    {
0082       char *init_buf = (char*)rawbuf + N*sizeof(T);
0083       for(std::size_t i = 0; i != N; ++i){
0084          init_buf -= sizeof(T);
0085          move_detail::force_ptr<T*>(init_buf)->~T();
0086       }
0087    }
0088 
0089    private:
0090    detail::max_align rawbuf[(N*sizeof(T)-1)/sizeof(detail::max_align)+1];
0091 };
0092 
0093 }  //namespace detail{
0094 }  //namespace intrusive{
0095 }  //namespace boost{
0096 
0097 #endif //BOOST_INTRUSIVE_DETAIL_ARRAY_INITIALIZER_HPP