Search code examples
c++boostboost-fusion

How do I extend the fusion container size limits beyond 50?


I want to generate boost fusion type sequences with more than 50 elements. The contents of boost/fusion/container/vector/vector50.hpp seems to suggest that a macro BOOST_FUSION_DONT_USE_PREPROCESSED_FILES might be used to affect this limit somehow.

I have created the following simple program which pushes back an int onto a boost::fusion::vector type for a specified number of times, and then converts the result to a vector (which triggers the error).

#include <boost/fusion/container.hpp>                                              
#include <boost/fusion/algorithm.hpp>                                              

#include <type_traits>                                                             

template <typename Sequence, int N>                                                
struct PushBack                                                                    
{                                                                                  
    using type = typename PushBack<typename boost::fusion::result_of::push_back<Sequence, int>::type, N-1>::type;
};                                                                                 

template <typename Sequence>                                                       
struct PushBack<Sequence, 0>                                                       
{                                                                                  
    using type = Sequence;                                                         
};                                                                                 

int main()                                                                         
{                                                                                  
    using NullVector = boost::fusion::vector<>;                                    
    using Sequence = boost::fusion::result_of::as_vector<typename PushBack<NullVector, 20>::type>::type; // this line triggers the error

    Sequence s;                                                                    
    return 0;                                                                      
}                          

When I run this with -D BOOST_FUSION_DONT_USE_PREPROCESSED_FILES -D FUSION_MAX_VECTOR_SIZE=100 I get a flood of errors that look roughly like this:

.../boost/fusion/container/generation/make_vector.hpp:105:25: error: ‘vector51’ does not name a type .../boost/fusion/container/generation/make_vector.hpp:105:25: error: ‘vector52’ does not name a type .../boost/fusion/container/generation/make_vector.hpp:105:25: error: ‘vector...’ does not name a type

Clearly I'm not doing it right. How do I extend this limit past 50? I need at least 150...


Solution

  • It does not appear to be possible to extend this limit without either hacking into boost or using the boost wave preprocessor, neither of which are feasible options for me. The only real solution here is to adapt std::tuple to use mpl features and use that instead of fusion containers. This answer shows exactly how to do that:

    https://stackoverflow.com/a/15865204/1613983