简体   繁体   English

BOOST_FUSION_ADAPT_ADT 找不到设置方法

[英]BOOST_FUSION_ADAPT_ADT not finding setter method

I am trying to apply the BOOST_FUSION_ADAPT_ADT to class as shown below:我正在尝试将 BOOST_FUSION_ADAPT_ADT 应用于 class,如下所示:

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; }
};

However, I am getting the following error, I can't quite figure out what is wrong.但是,我收到以下错误,我无法弄清楚出了什么问题。

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) {

You don't sow how you used it.你不播种你如何使用它。 However, when I try it there is no problem:但是,当我尝试时没有问题:

Live On Compiler Explorer Live On 编译器资源管理器

#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());
}

Prints印刷

hello
{{"world", "bye"}, {"world"}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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