c++boostboost-fusion

How to convert a homogeneous fusion::vector to an (std/boost)::array


I am relatively new to boost, so I believe this is an easy problem:
Given, say a fusion::vector<int, int, int>, I need a good way to turn it into an array<int, 3>.


Solution

  • You can just use the builtin adaption of array<> (std or boost) and copy:

    Live On Coliru

    #include <boost/fusion/include/copy.hpp>
    #include <boost/fusion/include/vector.hpp>
    #include <boost/fusion/adapted/boost_array.hpp>
    #include <boost/array.hpp>
    
    using namespace boost;
    
    int main() {
        fusion::vector<int, int, int> fv(1,2,3);
        array<int, 3> arr;
    
        fusion::copy(fv, arr);
    }