boost array

boost::array is similar to std::array, which was added to the standard library with C++11. With boost::array, an array can be created that exhibits the same properties as a C array. In addition, boost::array conforms to the requirements of C++ containers, which makes handing such an array as easy as handling any other container.

#include <boost/array.hpp>
#include <string>
#include <algorithm>
#include <iostream>

int main() {
  boost::array<std::string, 3> a;
  a[0] = "cat";
  a.at(1) = "shark";
  *a.rbegin() = "spider";

  std::sort(a.begin(), a.end());

  for (const std::string& s: a) {
    std::cout << s << std::endl;
  }

  std::cout << a.size() << std::endl;
  std::cout << a.max_size() << std::endl;
  return 0;
}

using boost::array is fairly simple and needs no additional explanation since the member functions called the same meaning as their counterparts from std::vector.

posted @ 2019-06-13 16:02  c++11  阅读(431)  评论(0编辑  收藏  举报