我想知道如何將這樣的C++ 11代碼翻譯成Boost + visual studio 2008:多維數組的創建和迭代通過它,以防其某些集合的一部分?如何將std :: array C++ 11操作轉換爲Boost + VS08?
這裏有雲:
#include <iostream>
#include <array>
#include <vector>
#include <set>
typedef size_t cell_id; // row * COLS + col
template <typename T> struct area
{
T value;
std::vector<cell_id> cells;
};
template <typename T, size_t Rows, size_t Cols>
std::vector<area<T> > getareas(const std::array<std::array<T, Cols>, Rows>& matrix)
{
std::vector<area<T> > areas;
return areas;
}
int main(){
typedef std::array<int, 3> row;
std::array<row, 4> matrix = {
row { 1 , 2, 3, },
row { 1 , 3, 3, },
row { 1 , 3, 3, },
row { 100, 2, 1, },
};
auto areas = getareas(matrix);
std::cout << "areas detected: " << areas.size() << std::endl;
for (const auto& area : areas)
{
std::cout << "area of " << area.value << ": ";
for (auto pt : area.cells)
{
int row = pt/3, col = pt % 3;
std::cout << "(" << row << "," << col << "), ";
}
std::cout << std::endl;
}
}
它magicallyappeared,改變所有std::array
到boost::array
不夠=(
#include <iostream>
#include <array>
#include <vector>
#include <set>
#include <boost/array.hpp>
typedef size_t cell_id; // row * COLS + col
template <typename T> struct area
{
T value;
std::vector<cell_id> cells;
};
template <typename T, size_t Rows, size_t Cols>
std::vector<area<T> > getareas(const boost::array<boost::array<T, Cols>, Rows>& matrix)
{
std::vector<area<T> > areas;
return areas;
}
int main(){
typedef boost::array<int, 3> row;
boost::array<row, 4> matrix = {
row { 1 , 2, 3, },
row { 1 , 3, 3, },
row { 1 , 3, 3, },
row { 100, 2, 1, },
};
auto areas = getareas(matrix);
std::cout << "areas detected: " << areas.size() << std::endl;
for (const auto& area : areas)
{
std::cout << "area of " << area.value << ": ";
for (auto pt : area.cells)
{
int row = pt/3, col = pt % 3;
std::cout << "(" << row << "," << col << "), ";
}
std::cout << std::endl;
}
}
boost::array<row, 4> matrix = ...
部分給出了像20級一樣不同的錯誤sintax ...
所以我想知道什麼是正確的翻譯?
嘿嘿 - 很好的問題:)我承認,代碼:) – sehe