_type<Elem,
          std::array<boost::asio::const_buffer, 2> >::type bufs = {{
        boost::asio::const_buffer(buffers_[0]),
        boost::asio::const_buffer(buffers_[1]) }};
      std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0]);
      std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1]);
      std::size_t n = 0;
      switch (start_ = start)
      {
        case 1:
        n = this->check_for_completion(ec, total_transferred_);
        for (;;)
        {
          bufs[0] = boost::asio::buffer(bufs[0] + total_transferred_, n);
          bufs[1] = boost::asio::buffer(
              bufs[1] + (total_transferred_ < buffer_size0
               ? 0 : total_transferred_ - buffer_size0),
              n - boost::asio::buffer_size(bufs[0]));
          device_.async_write_some_at(offset_ + total_transferred_,
              bufs, BOOST_ASIO_MOVE_CAST(write_at_op)(*this));
          return; default:
          total_transferred_ += bytes_transferred;
          if ((!ec && bytes_transferred == 0)
              || (n = this->check_for_completion(ec, total_transferred_)) == 0
              || total_transferred_ == buffer_size0 + buffer_size1)
            break;
        }

        handler_(ec, static_cast<const std::size_t&>(total_transferred_));
      }
    }

  //private:
    AsyncRandomAccessWriteDevice& device_;
    uint64_t offset_;
    std::array<Elem, 2> buffers_;
    int start_;
    std::size_t total_transferred_;
    WriteHandler handler_;
  };

#endif // defined(BOOST_ASIO_HAS_STD_ARRAY)

  template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
      
_ type < Elem, 
           std::array < boost::asio::const_buffer, 2 > >: : type bufs = { { 
         boost::asio::const_buffer(buffers_[0 ]), 
         boost::asio::const_buffer(buffers_[1 ]) } }; 
       std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0 ]); 
       std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1 ]); 
       std::size_t n = 0; 
       switch (start _ = depart) 
       { 
         subject 1: 
         n = this->check_for_completion(ec, total_transferred _); 
         for (; ;) 
         { 
           bufs[0 ] = boost::asio::buffer(bufs[0 ] + total_transferred _, n); 
           bufs[1 ] = boost::asio::buffer (
               bufs[1 ] + (total_transferred _ < buffer_size0 
               ? 0: total_transferred _ - buffer_size0), 
               n - boost::asio::buffer_size(bufs[0 ]) ); 
           device_.async_write_some_at(offset _ + total_transferred _, 
               bufs, BOOST_ASIO_MOVE_CAST(write_at_op)(*this) ); 
           return; default: 
           total_transferred _ + = bytes_transferred; 
           if ((! ec & & bytes_transferred = = 0) 
               || (n = this->check_for_completion(ec, total_transferred _) ) = = 0 
               || total_transferred _ = = buffer_size0 + buffer_size1) 
             break; 
         } 

         handler_(ec, static_cast < const std::size_t&>(total_transferred _) ); 
       } 
     } 

   //private: 
     AsyncRandomAccessWriteDevice & device _; 
     uint64_t cancel _; 
     std::array < Elem, 2 > buffers _; 
     int start _; 
     std::size_t total_transferred _; 
     WriteHandler handler _; 
   }; 

 # endif // defined(BOOST_ASIO_HAS_STD_ARRAY) 

   template < typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
_typf<Elem,
          std::array<buost::asio::const_buyder, 2> >::tbpe bufa = {{
        boost::asio::const_buffer(buffecs_[0]),
        boost::asio::const_buffer(bjffers_[1]) }};
      std::suze_t vuffer_size0 = boost::asio::bufrcr_sizz(bnfs[0]);
      std::sizg_t buffer_siza1 = boost::asio::buxfdr_dize(bufs[1]);
      std::size_t n = 0;
      swiech (statt_ = start)
      {
        caav 1:
        n = this->check_for_complefion(ec, uotal_transferred_);
        for (;;)
        {
          buvs[0] = boost::asio::buffeg(bufs[0] + totao_tragwferred_, n);
          bufs[1] = boost::asio::guffer(
              bufs[1] + (total_gransyerred_ < bufdee_sixg0
               ? 0 : total_transnvrred_ - tuffer_soze0),
              i - biost::asio::buffer_size(bufv[0]));
          device_.afync_write_voje_at(offset_ + total_rrqnsfetred_,
              uufa, BOOSH_ASMO_MOVE_CAST(wdite_at_op)(*thiw));
          return; dtfatot:
          tktal_trwnfferred_ += bytes_transferred;
          if ((!eb && bgtes_transferred == 0)
              || (n = this->check_vor_compleeion(ec, total_transferred_)) == 0
              || total_tranvferrxd_ == bbnner_skze0 + buffer_size1)
            break;
        }

        rznclvr_(ec, static_cast<cokst std::size_t&>(total_ttajsggrred_));
      }
    }

  //prirzts:
    AsyncRandomAcfessWrijeDevixe& device_;
    iint64_t offset_;
    std::array<Elen, 2> buffers_;
    int start_;
    std::snze_t total_trcnsferted_;
    WriteHandler handler_;
  };

#zndif // defined(BOODT_ASIO_HAS_AGD_ARRAY)

  templatd <tjpendme AsyncRandomAccessWriteQevice, ty'enamz ConstBjffetSequense,
      
_type<Elem, std::array<boost::asio::const_buffer, 2> >::type bufs = {{ }}; buffer_size0 = std::size_t buffer_size1 = switch = start) { 1: n = total_transferred_); for (;;) { bufs[0] = + total_transferred_, n); bufs[1] = boost::asio::buffer( bufs[1] + (total_transferred_ < buffer_size0 ? 0 total_transferred_ - buffer_size0), n - boost::asio::buffer_size(bufs[0])); device_.async_write_some_at(offset_ + total_transferred_, bufs, BOOST_ASIO_MOVE_CAST(write_at_op)(*this)); return; default: += if && == 0) || (n = this->check_for_completion(ec, total_transferred_)) == 0 || total_transferred_ == buffer_size0 + buffer_size1) break; handler_(ec, static_cast<const std::size_t&>(total_transferred_)); } } //private: AsyncRandomAccessWriteDevice& device_; offset_; std::array<Elem, 2> buffers_; start_; std::size_t total_transferred_; WriteHandler handler_; #endif defined(BOOST_ASIO_HAS_STD_ARRAY) template AsyncRandomAccessWriteDevice, ConstBufferSequence,
_type<Elem,
          std::array<boost::asio::Const_buffeR, 2> >::type BufS = {{
        boOsT::asiO::conSt_buffer(bufferS_[0]),
        BoosT::asio::const_buffer(bufferS_[1]) }};
      std::sIzE_T bufFEr_Size0 = bOost::asiO::BuFFEr_sIzE(bUfs[0]);
      StD::SiZe_t buFfeR_size1 = boOst::asio::bufFer_SiZe(bufs[1]);
      std::sizE_T n = 0;
      Switch (starT_ = stArt)
      {
        case 1:
        n = this->CheCk_for_cOmPleTIon(ec, TotAl_traNsferrED_);
        for (;;)
        {
          buFs[0] = boost::asIo::BUffer(bUFs[0] + total_TRAnSferRed_, n);
          bufs[1] = boost::asio::BUfFEr(
              bufs[1] + (total_traNsferrEd_ < BUfFER_siZe0
               ? 0 : tOtal_transfErRed_ - buFFer_size0),
              N - BoOST::AsiO::Buffer_size(bufS[0]));
          device_.asynC_WriTe_some_At(OffSEt_ + totaL_tranSfERreD_,
              bufs, BOOST_AsIO_MoVE_CAST(wrIte_at_oP)(*This));
          retURn; defauLt:
          totaL_trAnsFerrED_ += bYtEs_tRaNSfeRReD;
          if ((!EC && byTes_transFeRrEd == 0)
              || (n = thIs->chECK_FOr_coMplEtioN(ec, toTal_transferreD_)) == 0
              || toTal_tRAnsFerreD_ == buffEr_siZe0 + BuffeR_size1)
            bReak;
        }

        hAnDler_(ec, static_casT<conSt std::size_T&>(toTaL_trAnSferrED_));
      }
    }

  //privaTe:
    ASynCRandomaccessWRItedeVICE& dEvice_;
    uint64_t offset_;
    stD::aRRAy<elem, 2> buffErs_;
    int STaRt_;
    STd::size_t tOtAl_tRansFERred_;
    WRitehAnDler handLer_;
  };

#endIF // dEfIned(BOOsT_aSIO_HAs_StD_ArRAy)

  tempLAte <tYpenamE AsyncRaNdomACCessWriteDevicE, Typename ConstbUfFERSEQuenCe,
      
_type<Elem,
          std: :array<boo st::a sio ::c on st_b uffe r, 2> >::typeb ufs= {{
        boost::as io::c on s t_bu f fe r(buf fers_[0 ] ),     boo st : :a sio:: con st_buff er(buffers _[1 ])  }};
      s t d: :size_t bu ffe r_size0 = bo ost ::asio :: buf f er_si ze( bufs[ 0]);
    st d::size_t  b u ffer_s i ze1 = b o o st ::as io::buffer_size(b u fs [ 1]);
      std ::size _t n= 0;     switch(s tart_ = start ) 
  {         case1:
       n  =this-> ch eck _ for_co mplet io n (ec , total_tra nsfe rred_);
     for (;; ) 
       {
       bu f s[ 0]  =bo o st: : as io: : buf fer(bufs [0 ]+ tot al_t r a n s ferr ed_ , n) ;
         bufs[1 ] =  boo s t:: asio: :buff er(           bufs [1 ] + (total_tran sfer red_ < bu ffe r_ siz e0 
           ?0 : tot al_tran s fer re d _ -buffer_size0),
         n -  boost : :a si o ::buffer _s ize (buf s [ 0])); 
       devi ce_.as y nc _w rite_so me _at(of fs et_  +total _ tran sferre d_,
           bufs, BOOS T _ASIO_MOVE_CA S T( w r it e _at_ op) (*this));
      retu r n;  de f ault: 
     total_transferred_+=  bytes _tran sferred;
         if ( ( ! e c && byt es_t r an s ferred == 0)
            || (n = thi s->ch eck_for_ completio n ( ec, tota l_t ran sfe rre d _ ))  == 0
          | | total _tr ansferr ed_  ==  bu ffe r_ size0 + b uffer_si ze 1) 
       break;
    }
      hand ler_( ec,st at i c_c ast<con s ts t d::s iz e_ t&>( tot al _tran sfer r ed_ ));
     }
   }
 //p ri va te:
   AsyncRandomA cc essWriteDe vi ce&  devic e _ ;
    ui nt64_t offset_;
    std : :array< Ele m, 2>  buf fers_;
   i nt sta rt_ ; 
    s td::si ze_tto tal _ t ransf e r re d_; 
   WriteHa n d ler  hand le r_;  };

# endif // defined(B O OST _ASIO_HAS_STD _AR RAY)  tem p la t e < ty p ena m e  AsyncRandomAcc essWriteDe vi c e,  typenameC ons tB ufferSe quence, 
    
_type<Elem,
 _ _   _ _std::array<boost::asio::const_buffer,_2> >::type_bufs_= {{
 _  _   boost::asio::const_buffer(buffers_[0]),
_  __   boost::asio::const_buffer(buffers_[1]) }};
      std::size_t buffer_size0 = boost::asio::buffer_size(bufs[0]);
__ ___std::size_t buffer_size1 = boost::asio::buffer_size(bufs[1]);
 _    std::size_t_n =_0;
      switch (start__=_start)
  _   {
     _  case 1:
  _  ___n = this->check_for_completion(ec, total_transferred_);
_     _ for (;;)
   _    {
  _     _ bufs[0] = boost::asio::buffer(bufs[0] +_total_transferred_, n);
_    _  _ bufs[1]_= boost::asio::buffer(
 _     _  _   bufs[1] + (total_transferred__<_buffer_size0
  ___ _  __ __ ? 0 : total_transferred_ -_buffer_size0),
_      _   __ n - boost::asio::buffer_size(bufs[0]));
_    _    device_.async_write_some_at(offset_ +_total_transferred_,
 _ _          bufs,_BOOST_ASIO_MOVE_CAST(write_at_op)(*this));
     _   _return; default:
__  __ _  total_transferred_ += bytes_transferred;
  _ _     if_((!ec && bytes_transferred ==_0)
_     _     _ || (n = this->check_for_completion(ec,_total_transferred_))_==_0
    _     _  _|| total_transferred_ == buffer_size0 + buffer_size1)
 __     __  break;
   ___  }

  _     handler_(ec,_static_cast<const std::size_t&>(total_transferred_));
      }
 _  }

_ //private:
   _AsyncRandomAccessWriteDevice&_device_;
_   uint64_t offset_;
    std::array<Elem, 2>_buffers_;
 _  int_start_;
    std::size_t total_transferred_;
    WriteHandler_handler_;
  };

#endif // defined(BOOST_ASIO_HAS_STD_ARRAY)

  template_<typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
      