2016-04-26 242 views
0

我有一個數據結構:初始化向量的元組類成員初始化列表

using Delaunay = CGAL::Delaunay_triangulation_3<K, Tds>; 
using Cell_handle = Delaunay::Cell_handle; 
using Vertex_handle = Delaunay::Vertex_handle; 
using Edge_handle = std::tuple<Cell_handle, std::uintmax_t, std::uintmax_t>; 
using geometry_tuple = std::tuple<std::vector<Cell_handle>, 
           std::vector<Cell_handle>, 
           std::vector<Cell_handle>, 
           std::vector<Edge_handle>, 
           std::uintmax_t, 
           std::vector<Vertex_handle>>; 

,我想在一個默認的構造函數來初始化:

struct SimplicialManifold { 
/// Default constructor with proper initialization 
SimplicialManifold() 
     : triangulation{std::make_unique<Delaunay>()}, 
     geometry{std::make_tuple(0, 0, 0, 0, 0, 0)} {} 

std::unique_ptr<Delaunay> triangulation; 
///< std::unique_ptr to the Delaunay triangulation 

geometry_tuple geometry; 
///< The geometric structure of the triangulation 
}; 

上面的代碼工作在Apple LLVM V7.3.0(clang-703.0.29),但在GCC 5.2中失敗,帶有大量模板編譯器goo:

../src/S3Triangulation.h: In constructor ‘SimplicialManifold::SimplicialManifold()’../src/S3Triangulation.h:493:55: error: no matching function for call to 
‘std::tuple<std::vector<CGAL::CCC_internal::CCC_iterator<CGAL::Concurrent_compact_container<CGAL::Triangulation_cell_base_with_info_3<long unsigned int, CGAL::Epick, CGAL::Triangulation_cell_base_3<CGAL::Epick, CGAL::Triangulation_ds_cell_base_3<CGAL::Triangulation_data_structure_3<CGAL::Triangulation_vertex_base_with_info_3<long unsigned int, CGAL::Epick, CGAL::Triangulation_vertex_base_3<CGAL::Epick, CGAL::Triangulation_ds_vertex_base_3<void> > >, CGAL::Triangulation_cell_base_with_info_3<long unsigned int, CGAL::Epick, CGAL::Triangulation_cell_base_3<CGAL::Epick, CGAL::Triangulation_ds_cell_base_3<void> > >, CGAL::Parallel_tag> > > >, tbb::scalable_allocator<CGAL::Triangulation_cell_base_with_info_3<long unsigned int, CGAL::Epick, CGAL::Triangulation_cell_base_3<CGAL::Epick, CGAL::Triangulation_ds_cell_base_3<CGAL::Triangulation_data_structure_3<CGAL::Triangulation_vertex_base_with_info_3<long unsigned int, CGAL::Epick, CGAL::Triangulation_vertex_base_3<CGAL::Epick, CGAL::Triangulation_ds_vertex_base_3<void> > >, CGAL::Triangulation_cell_base_with_info_3<long unsigned int, CGAL::Epick, CGAL::Triangulation_cell_base_3<CGAL::Epick, CGAL::Triangulation_ds_cell_base_3<void> > >, CGAL::Parallel_tag> > > > > >, false>, std::allocator<CGAL::CCC_internal::CCC_iterator<CGAL::Concurrent_compact_container<CGAL::Triangulation_cell_base_with_info_3<long unsigned int, CGAL::Epick, CGAL::Triangulation_cell_base_3<CGAL::Epick, 

(有問題的代碼是https://github.com/acgetchell/CDT-plusplus/blob/functional/src/S3Triangulation.h開始上線467)

我看着初始化列表,但是這些不工作:如何做到這一點,讓GCC快樂

geometry{std::initializer_list<std::vector<Cell_handle>, 
       std::vector<Cell_handle>, 
       std::vector<Cell_handle>, 
       std::vector<Edge_handle>, 
       std::uintmax_t, 
       std::vector<Vertex_handle>>({0, 0, 0, 0, 0, 0}) 
     } {} 

建議?

+0

你用-std = C++ 11標誌編譯過嗎? – bashrc

+0

是的,實際上使用-std = C++ 1y –

+2

'tuple'值 - 無論如何都初始化它的元素,所以這是多餘的。 –

回答

3

最好的解決方案是寫一個合適的結構或類而不是濫用std::tuple。例如:

struct geometry_tuple 
{ 
    std::array<std::vector<Cell_handle>, 3> cells; 
    std::vector<Edge_handle> edges; 
    std::uintmax_t max; 
    std::vector<Vertex_handle> vertexes; 

    geometry_tuple() 
     : max(0) 
    { 
     // ... 
    } 
}; 

這使得您的代碼具有描述性的名稱爲每個字段,而不是以後做.get<2>()等。它可以讓你與你可能需要的任何參數的構造函數正確清晰。

+1

這是_definitely_正確的路要走。 – Charles