简体   繁体   English

在类成员初始化器列表中初始化向量的元组

[英]Initialize a tuple of vectors in a class member initializer list

I have a data structure: 我有一个数据结构:

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>>;

That I would like to initialize in a default constructor: 我想在默认构造函数中初始化:

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
};

The above code works in Apple LLVM version 7.3.0 (clang-703.0.29), but fails in GCC 5.2 with a ton of template compiler goo: 上面的代码在Apple LLVM版本7.3.0(clang-703.0.29)中有效,但是在带有大量模板编译器goo的GCC 5.2中失败:

../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,

(The code in question is https://github.com/acgetchell/CDT-plusplus/blob/functional/src/S3Triangulation.h starting on line 467.) (有问题的代码是从467行开始的https://github.com/acgetchell/CDT-plusplus/blob/functional/src/S3Triangulation.h 。)

I looked at initializer lists, but those don't work: 我查看了初始化器列表,但这些列表不起作用:

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})
        } {}

Suggestions on how to do this and make GCC happy? 有关如何做到这一点并使GCC开心的建议?

The best solution is to write a proper struct or class instead of abusing std::tuple . 最好的解决方案是编写适当的结构或类,而不是滥用std::tuple For example: 例如:

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)
    {
        // ...
    }
};

This makes your code clearer by having descriptive names for each field, rather than later doing .get<2>() etc. And it lets you make proper constructors with whatever arguments you may need. 通过为每个字段使用描述性名称,而不是稍后再执行.get<2>()等,这可以使代码更清晰。它使您可以使用所需的任何参数来构造适当的构造函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在类的成员初始化器列表中初始化std :: tuple - Initialize std::tuple in member initializer list of a class 成员初始化列表:从返回元组的函数初始化两个成员 - Member initializer list: initialize two members from a function returning a tuple 如何在成员初始值设定项列表之外初始化类成员 - How to initialize class member outside the member initializer list 如何在C ++类的初始化列表中初始化member-struct? - How to initialize member-struct in initializer list of C++ class? 类成员初始化程序使用错误检查初始化ifstream? - Class member initializer to initialize ifstream with error check? 如何在成员初始值设定项列表中初始化数组 - How to initialize an array in the member initializer list 为什么不能在派生类的构造函数初始化列表中初始化基类的数据成员? - Why can't Initialize the data member of base class in the constructor initializer list of derived class? 我想在组合/整体 class 的成员初始化程序列表中初始化一个“部分”数组 class - I want to initialize an array of "part" class in member initializer list of composed/whole class 在variadic模板类的构造函数中初始化元组成员 - Initialize tuple member in constructor of variadic template class 尝试使用initializer_list初始化类的成员值时编译错误 - Compile error with initializer_list when trying to use it to initialize member value of class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM