• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            兔子的技術(shù)博客

            兔子

               :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              202 Posts :: 0 Stories :: 43 Comments :: 0 Trackbacks

            留言簿(10)

            最新評論

            閱讀排行榜

            評論排行榜

            轉(zhuǎn)自:http://grantren.javaeye.com/blog/221457

            boost::multi_array
            一言以概之,boost::multi_array就是N維數(shù)組。boost::multi_array可以看作STL容器類的擴(kuò)展,可以和STL相關(guān)算法一起工作。
            在STL中,N維數(shù)組可以通過std::vector<std::vector<...> >類似的方法來模擬,相比而言,boost::multi_array更高效,更直觀。

            例程1:

             1 #include <cassert>   
             2 #include "boost/multi_array.hpp"   
             3 #include "boost/cstdlib.hpp"   
             4   
             5 int main () {   
             6   // Create a 3D array that is 3 x 4 x 2   
             7   typedef boost::multi_array<double3> array;   
             8   array A(boost::extents[3][4][2]);   
             9   // Assign a value to an element in the array   
            10   A[0][0][0= 3.14;   
            11   assert(A[0][0][0== 3.14);   
            12   return boost::exit_success;   
            13 }  
            14 

            例程2:

             1 #include <cassert>   
             2 #include "boost/multi_array.hpp"   
             3 #include "boost/array.hpp"   
             4 #include "boost/cstdlib.hpp"   
             5   
             6 int main () {   
             7   // Create a 3D array that is 3 x 4 x 2   
             8   boost::array<int3> shape = {{ 342 }};   
             9   boost::multi_array<double3> A(shape);   
            10   // Assign a value to an element in the array   
            11   A[0][0][0= 3.14;   
            12   assert(A[0][0][0== 3.14);   
            13   return boost::exit_success;   
            14 }  
            15 


            例程3:

             1 #include <iostream>   
             2 #include "boost/multi_array.hpp"   
             3 #include "boost/array.hpp"   
             4 #include "boost/cstdlib.hpp"   
             5   
             6 template <typename Array>   
             7 void print(std::ostream& os, const Array& A) {   
             8   typename Array::const_iterator i;   
             9   os << "[";   
            10   for (i = A.begin(); i != A.end(); ++i) {   
            11     print(os, *i);   
            12     if (boost::next(i) != A.end())   
            13       os << ',';   
            14   }   
            15   os << "]";   
            16 }   
            17   
            18 void print(std::ostream& os, const double& x) {   
            19   os << x;   
            20 }   
            21   
            22 int main() {   
            23   typedef boost::multi_array<double2> array;   
            24   double values[] = {   
            25     012,   
            26     345    
            27   };   
            28   const int values_size = 6;   
            29   array A(boost::extents[2][3]);   
            30   A.assign(values,values + values_size);   
            31   print(std::cout, A);   
            32   return boost::exit_success;   
            33 }  
            34 
            posted on 2009-09-28 10:18 會飛的兔子 閱讀(1971) 評論(0)  編輯 收藏 引用 所屬分類: C++庫,組件
            久久精品国产免费观看| 亚洲中文字幕久久精品无码喷水| 久久99精品久久久久久久不卡| 亚洲精品乱码久久久久66| 色综合久久久久无码专区| 久久精品天天中文字幕人妻| 亚洲欧美精品伊人久久| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 一本久久知道综合久久| 青青草国产精品久久久久| 亚洲欧美国产精品专区久久| 99久久国产热无码精品免费| 久久人人爽人人澡人人高潮AV| 久久久久久久免费视频| 91精品国产91久久久久久青草| 亚洲欧美日韩中文久久| 性做久久久久久久久久久| 国产一级持黄大片99久久| 中文字幕久久久久人妻| 伊人久久大香线蕉综合5g| 久久er热视频在这里精品| 亚洲国产精品无码久久| 亚洲第一永久AV网站久久精品男人的天堂AV| av无码久久久久久不卡网站| 亚洲国产欧洲综合997久久| 中文成人无码精品久久久不卡| 久久天天躁狠狠躁夜夜2020| 国产精品日韩深夜福利久久| 久久免费小视频| 久久国产精品99精品国产987| 久久久久久人妻无码| 久久精品九九亚洲精品| 国产精品9999久久久久| 国产精品久久自在自线观看| 久久青青草原综合伊人| 国产午夜久久影院| 国产精品免费久久久久久久久| 99久久国产免费福利| 开心久久婷婷综合中文字幕| 青青热久久国产久精品| 99精品国产99久久久久久97|