Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何将fusion容器大小限制扩展到50以上?_C++_Boost_Boost Fusion - Fatal编程技术网

C++ 如何将fusion容器大小限制扩展到50以上?

C++ 如何将fusion容器大小限制扩展到50以上?,c++,boost,boost-fusion,C++,Boost,Boost Fusion,我想生成具有50个以上元素的boost fusion类型序列。的内容似乎表明宏BOOST\u FUSION\u not\u USE\u PREPROCESSED\u FILES可能会以某种方式影响此限制 我创建了以下简单的程序,它将int推回到boost::fusion::vector类型上指定的次数,然后将结果转换为向量(这会触发错误) #包括 #包括 #包括 模板 结构回推 {

我想生成具有50个以上元素的
boost fusion
类型序列。的内容似乎表明宏
BOOST\u FUSION\u not\u USE\u PREPROCESSED\u FILES
可能会以某种方式影响此限制

我创建了以下简单的程序,它将
int
推回到
boost::fusion::vector
类型上指定的次数,然后将结果转换为向量(这会触发错误)

#包括
#包括
#包括
模板
结构回推
{                                                                                  
使用type=typename PushBack::type;
};                                                                                 
模板
结构回推
{                                                                                  
使用类型=序列;
};                                                                                 
int main()
{                                                                                  
使用NullVector=boost::fusion::vector;
使用Sequence=boost::fusion::result_of::as_vector::type;//此行将触发错误
序列s;
返回0;
}                          
当我使用
-D BOOST\u FUSION\u not\u USE\u PREPROCESSED\u FILES-D FUSION\u MAX\u VECTOR\u SIZE=100运行此程序时,我得到了大量的错误,大致如下所示:

…/boost/fusion/container/generation/make_vector.hpp:105:25:错误:“vector51”未命名类型 …/boost/fusion/container/generation/make_vector.hpp:105:25:错误:“vector52”未命名类型 …/boost/fusion/container/generation/make_vector.hpp:105:25:错误:“vector…”未命名类型


显然我做得不对。如何将此限制延长到超过50?我需要至少150个…

在我看来,预处理的文件只是一个编译时间优化

在这种情况下,您可能希望(?)大胆地去以前没有人去过的地方,并且:

  • 编辑该文件中的限制:

    namespace boost { namespace fusion
    {
        struct vector_tag;
        struct fusion_sequence_tag;
        struct random_access_traversal_tag;
    
    // expand vector41 to vector50
    #define BOOST_PP_FILENAME_1 <boost/fusion/container/vector/detail/vector_n.hpp>
    #define BOOST_PP_ITERATION_LIMITS (41, 100)
    #include BOOST_PP_ITERATE()
    
    }}
    
    namespace boost{namespace fusion
    {
    结构向量标签;
    结构融合\序列\标签;
    结构随机访问遍历标记;
    //将vector41展开为vector50
    #定义BOOST\u PP\u文件名\u 1
    #定义BOOST\u PP\u迭代\u限制(41100)
    #包括BOOST_PP_ITERATE()
    }}
    
  • 以类似的方式添加更多标题,例如a
    vector60.hpp
    vector70.hpp
    。。。把它放在适当的地方


我还没有测试过这一点,但值得一试这是一个两步的方法,首先在编译标志中定义:
BOOST\u MPL\u CFG\u NO\u PREPROCESSED\u HEADERS
,然后用
-DBOOST\u MPL\u LIMIT\u VECTOR\u size=50-DFUSION\u MAX\u VECTOR\u size=50设置所需的大小(最接近10)

编辑:

您确实运气不好,在标题中,即使您不使用预处理的标题,看起来这段代码将其限制为50个:

#if (FUSION_MAX_VECTOR_SIZE > 40)
#include <boost/fusion/container/vector/vector50.hpp>
#endif
\if(融合最大向量大小>40)
#包括
#恩迪夫
这才是真正愚蠢的事情:

#define BOOST_PP_FILENAME_1 <boost/fusion/container/vector/detail/vector_n.hpp>
#define BOOST_PP_ITERATION_LIMITS (41, 50)
#include BOOST_PP_ITERATE()

}}
#定义BOOST_PP_文件名_1
#定义BOOST_PP_迭代_限制(41,50)
#包括BOOST_PP_ITERATE()
}}
嗯。。我认为除了“修补”上面的代码之外,没有其他方法

EDIT2:好吧,如果有黑客的意愿,显然有一种方法(无需修改boost),它确实有一个巨大的免责声明-正确测试,编译,你可以访问超过50个元素,这就是我将提供的所有保证

#include <iostream>

#define BOOST_MPL_LIMIT_VECTOR_SIZE 50
#define FUSION_MAX_VECTOR_SIZE 60

// This sets us up with mpl vector up to 50
#include <boost/mpl/vector.hpp>

// This adds the missing chunk - you should be able to expand this up to template depth
// This sets up the sequence of vectors (vector1 : T + vector0 etc.
#include <boost/fusion/sequence/intrinsic/begin.hpp>
namespace boost { namespace mpl {

#   define BOOST_PP_ITERATION_PARAMS_1 \
    (3,(51, 60, <boost/mpl/vector/aux_/numbered.hpp>))
#   include BOOST_PP_ITERATE()

}}
// This sets up the specializations
#define AUX778076_SEQUENCE_BASE_NAME vector
#   define AUX778076_SEQUENCE_LIMIT BOOST_MPL_LIMIT_VECTOR_SIZE
#   define AUX778076_SEQUENCE_CONVERT_CN_TO(z,n,TARGET) TARGET(BOOST_PP_CAT(C,n))
#   include <boost/mpl/aux_/sequence_wrapper.hpp>

// Include everuthing up to vector50
#define BOOST_FUSION_DONT_USE_PREPROCESSED_FILES
#include <boost/fusion/container/vector/vector50.hpp>

// Add the missing range
namespace boost
{
namespace fusion
{
struct vector_tag;
#define BOOST_PP_FILENAME_1 <boost/fusion/container/vector/detail/vector_n.hpp>
#define BOOST_PP_ITERATION_LIMITS (51, 60)
#include BOOST_PP_ITERATE()
}
}

// Declare the vector class using the FUSION_MAX_VECTOR_SIZE, as the types themselves have been declared above, all is
// good in the world of fusion
#include <boost/fusion/container/vector/vector.hpp>


// Test access
#include <boost/fusion/sequence/intrinsic/at_c.hpp>


int main()
{

  using Sequence = typename boost::fusion::vector<
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    double,
    std::string,
    std::string
 >;

 Sequence s;

 std::cout << boost::fusion::at_c<51>(s) << std::endl;

}
#包括
#定义BOOST\u MPL\u LIMIT\u VECTOR\u SIZE 50
#定义融合\最大\向量\大小60
//这为我们设置了高达50的mpl向量
#包括
//这将添加缺少的块-您应该能够将其扩展到模板深度
//这将设置向量序列(vector1:T+vector0等)。
#包括
命名空间boost{namespace mpl{
#定义BOOST_PP_迭代_参数_1\
(3,(51, 60, ))
#包括BOOST_PP_ITERATE()
}}
//这就建立了专门化
#定义AUX77076_序列_基_名称向量
#定义AUX778076\序列\限制提升\ MPL\限制\向量\大小
#定义AUX778076_序列_转换_CN_到(z,n,TARGET)目标(BOOST_PP_CAT(C,n))
#包括
//包括最多50个矢量
#定义BOOST\u FUSION\u不使用预处理的\u文件
#包括
//添加缺少的范围
名称空间提升
{
名称空间融合
{
结构向量标签;
#定义BOOST\u PP\u文件名\u 1
#定义BOOST_PP_迭代_限制(51,60)
#包括BOOST_PP_ITERATE()
}
}
//使用FUSION\u MAX\u vector\u SIZE声明vector类,因为上面已经声明了类型本身,所以一切都是正确的
//融合世界中的美好
#包括
//测试访问
#包括
int main()
{
使用Sequence=typename boost::fusion::vector<
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int,
双重的
标准:
#include <iostream>

#define BOOST_MPL_LIMIT_VECTOR_SIZE 50
#define FUSION_MAX_VECTOR_SIZE 60

// This sets us up with mpl vector up to 50
#include <boost/mpl/vector.hpp>

// This adds the missing chunk - you should be able to expand this up to template depth
// This sets up the sequence of vectors (vector1 : T + vector0 etc.
#include <boost/fusion/sequence/intrinsic/begin.hpp>
namespace boost { namespace mpl {

#   define BOOST_PP_ITERATION_PARAMS_1 \
    (3,(51, 60, <boost/mpl/vector/aux_/numbered.hpp>))
#   include BOOST_PP_ITERATE()

}}
// This sets up the specializations
#define AUX778076_SEQUENCE_BASE_NAME vector
#   define AUX778076_SEQUENCE_LIMIT BOOST_MPL_LIMIT_VECTOR_SIZE
#   define AUX778076_SEQUENCE_CONVERT_CN_TO(z,n,TARGET) TARGET(BOOST_PP_CAT(C,n))
#   include <boost/mpl/aux_/sequence_wrapper.hpp>

// Include everuthing up to vector50
#define BOOST_FUSION_DONT_USE_PREPROCESSED_FILES
#include <boost/fusion/container/vector/vector50.hpp>

// Add the missing range
namespace boost
{
namespace fusion
{
struct vector_tag;
#define BOOST_PP_FILENAME_1 <boost/fusion/container/vector/detail/vector_n.hpp>
#define BOOST_PP_ITERATION_LIMITS (51, 60)
#include BOOST_PP_ITERATE()
}
}

// Declare the vector class using the FUSION_MAX_VECTOR_SIZE, as the types themselves have been declared above, all is
// good in the world of fusion
#include <boost/fusion/container/vector/vector.hpp>


// Test access
#include <boost/fusion/sequence/intrinsic/at_c.hpp>


int main()
{

  using Sequence = typename boost::fusion::vector<
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    int,
    double,
    std::string,
    std::string
 >;

 Sequence s;

 std::cout << boost::fusion::at_c<51>(s) << std::endl;

}