std::tuple 和类型 cartesian_product<unsigned N_n, unsigned ... N_nm1>

std::tuple and a type cartesian_product<unsigned N_n, unsigned ... N_nm1>

以下代码无法编译,但我没有发现错误(我不理解消息错误)。

我的基本模板类型 'int_mod_N' 是一个从 0 到 'N' 的整数,一个整数模块 'N'(表示循环群的元素)。这很容易,我构建了一个以基数 'B' 表示的整数库,其中数字为 'int_mod_N',整数表示为 'std::basic_strings< int_mod_N >'。有用。

有问题的是我需要表示 'n' 集合的笛卡尔积元素的类型,对于它们中的每一个整数模块一个常量整数 'N_i'.

在数学上,我想表示 Z_Nn x ... x Z_N1 的元素,只有加法组。

下一个代码无法编译。

#include <tuple>

#include "int_mod_N_t.hpp"

template<   
        unsigned N_n,unsigned ... N_nm1
    >
struct elem_set_t : 
                public
                decltype(
                    std::tuple_cat(
                        std::tuple< int_mod_N_t<N_n> >{},
                        elem_set_t< N_nm1 ... >{}
                    )
                )
{};

template<unsigned N_n,unsigned N_nm1>
struct elem_set_t<N_n,N_nm1> :
        public
        std::tuple< 
                int_mod_N_t<N_n> , 
                int_mod_N_t<N_nm1> 
        >
{};

template<unsigned N_n>
struct elem_set_t<N_n> :
        public
        std::tuple< 
            int_mod_N_t<N_n> 
        > 
{};

编译器(g++ 7.2.0)的错误信息是

In file included from /tuplas_y_tipos/main.cpp:3:0: /tuplas_y_tipos/elem_set_t.hpp: In instantiation of 'struct elem_set_t<2, 2, 2>': /tuplas_y_tipos/main.cpp:8:20: required from here /tuplas_y_tipos/elem_set_t.hpp:10:21: error: no matching function for call to 'tuple_cat(std::tuple >, elem_set_t<2, 2>)' std::tuple_cat( ~~~~~~~~~~~~~~^ std::tuple< int_mod_N_t >{}, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ elem_set_t< N_nm1 ... >{} ~~~~~~~~~~~~~~~~~~~~~~~~~ ) ~ In file included from /tuplas_y_tipos/elem_set_t.hpp:1:0, from /tuplas_y_tipos/main.cpp:3: c:\mingw\include\c++.2.0\tuple:1575:5: note: candidate: template constexpr typename std::__tuple_cat_result<_Tpls ...>::__type std::tuple_cat(_Tpls&& ...) tuple_cat(_Tpls&&... __tpls) ^~~~~~~~~ c:\mingw\include\c++.2.0\tuple:1575:5: note: template argument deduction/substitution failed: c:\mingw\include\c++.2.0\tuple:1572:31: error: no type named 'type' in 'struct std::enable_if' template elem_set_t<2,2,2> elem; ^~~~ make.exe[1]: * [tuplas_y_tipos.mk:97: Debug/main.cpp.o] Error 1 make.exe: * [Makefile:5: All] Error 2 make.exe[1]: Leaving directory '/tuplas_y_tipos' ====1 errors, 6 warnings====

我完全不建议从 std::tuple 继承,为此,您不需要。

template <unsigned ... N_ns>
using elem_set_t = std::tuple<int_mod_N_t<N_ns>...>;

如果你有一些方法,你应该有一个元组数据成员,而不是基础 class

template <unsigned ... N_ns>
struct elem_set_t 
{
    std::tuple<int_mod_N_t<N_ns>...> data;
    // other members
}