简体   繁体   中英

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.

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

Because N must be an MPL integral constant

Boost::fusion::at

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM