Search code examples
c++boostboost-fusion

C++: BOOST_FUSION_ADAPT_STRUCT Error When Using fusion::at


In the Boost.Fusion documentation it says that BOOST_FUSION_ADAPT_STRUCT makes a struct a fully compatible Boost.Fusion random access sequence.
I tried the following:

#include <iostream>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/at.hpp>

struct Str {
    int i;
    float j;
};

BOOST_FUSION_ADAPT_STRUCT(
    Str,
    (int, i)
    (float, j)
)

int main() {
    Str s;
    boost::fusion::at<0>(s) = 1;
}

And I received an error from the compiler saying "no matching function for call to at(Str&)".
The compiler I'm using is g++.
What am I doing wrong?
Thanks in advance.


Solution

  • boost::fusion::at<boost::mpl::int_<0>>(s) = 1;
    

    Because N must be an MPL integral constant

    Boost::fusion::at