c++ - BOOST_FUSION_ADAPT_ADT找不到设置方法

标签 c++ boost boost-fusion

我正在尝试将BOOST_FUSION_ADAPT_ADT应用于类,如下所示:

class XY {
private:
    std::string x; // lhs
    std::list<std::list<std::string>> y;

public:
    std::list<std::list<std::string>> const &getY() const {
        return y;
    }

    void setY(std::list<std::list<std::string>> const &y) {
        this->y = y;
    }

    std::string const &getX() const { return x; }

    void setX(std::string const &x) { this->x = x; }
};
但是,我收到以下错误,我无法完全弄清楚出什么问题了。
xxxxxxxxxxxxxxx: error: no matching function for call to ‘Rule::setY(const std::__cxx11::basic_string<char>&)’
                        (std::list<std::list<std::string>> const&, std::list<std::list<std::string>> const&, obj.getY(), obj.setY(val))
                                                                                                                         ^
xxxxxxxxxxxxxxx: note: candidate: void Rule::setY(const std::__cxx11::list<std::__cxx11::list<std::__cxx11::basic_string<char> > >&)
     void setY(std::list<std::list<std::string>> const &y) {

最佳答案

您不播种您如何使用它。但是,当我尝试时没有问题:
Live On Compiler Explorer

#include <boost/fusion/adapted.hpp>
#include <boost/fusion/include/copy.hpp>
#include <string>
#include <list>
#include <fmt/ranges.h>
using namespace std::string_literals;
using Lists = std::list<std::list<std::string> >;

class XY {
  private:
    std::string x;
    Lists y;

  public:
    void setY(Lists       const& y) { this->y = y; }
    void setX(std::string const& x) { this->x = x; }

    [[nodiscard]] Lists       const& getY() const { return y; }
    [[nodiscard]] std::string const& getX() const { return x; }
};

BOOST_FUSION_ADAPT_ADT(XY,
        (obj.getX(), obj.setX(val))
        (obj.getY(), obj.setY(val))
    )

int main() {
    XY test;
    boost::fusion::copy(
        std::make_tuple("hello", Lists { {"world"s, "bye"s}, {"world"s} }),
        test);

    fmt::print("{}\n{}\n",
            test.getX(),
            test.getY());
}
版画
hello
{{"world", "bye"}, {"world"}}

关于c++ - BOOST_FUSION_ADAPT_ADT找不到设置方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63033995/

相关文章:

c++ - 我的数组是导致 CPU 和内存快速增加的原因吗?

c++ - 将 C 风格字符串与 C++ 字符串混合时的优化

c++ - 我的 Boost Phoenix lambda 有什么问题?

c++ - 在容器( vector )上以循环方式循环的最佳方法是什么?

c++ - 如何在模板类中为 `` boost::array_view`` 创建 typedef

c++ - 如何从 spirit 语义规则绑定(bind)/调用存储在 fusion::vector 中的 boost::function?

c++ - 在 C++ 中的 1 行上创建一个数组

c++ - 为什么流继续阅读并且不会到达eof?

c++ - 使用Boost Spirit X3解析具有交替标记的Selector结构

c++ - 实现一个对象目录:boost::any、boost::variant,或者?