错误:无法匹配函数调用set(boost::beast::http::field, std::string_view&)’

huangapple go评论58阅读模式
英文:

error: no matching function for call to set(boost::beast::http::field, std::string_view&)’

问题

Legacy code:

#define BOOST_BEAST_USE_STD_STRING_VIEW

std::string_view my_host;
beast::http::request<http::empty_body> my_request;
my_request.set(http::field::host, my_host);

Updated code for boost v1.82:

#define BOOST_NO_CXX17_HDR_STRING_VIEW

std::string my_host;
beast::http::request<http::empty_body> my_request;
my_request.set(http::field::host, my_host);

错误信息:

错误: 无法匹配函数调用:‘boost::beast::http::message<true, boost::beast::http::empty_body, boost::beast::http::basic_fields<std::allocator<char> >>::set(boost::beast::http::field, std::string_view&)’

答案: 为了将遗留代码迁移到Boost v1.82,您需要做以下更改:

  1. 移除 #define BOOST_BEAST_USE_STD_STRING_VIEW,并替换为 #define BOOST_NO_CXX17_HDR_STRING_VIEW,因为在Boost v1.82中已不再使用标准库的 std::string_view

  2. std::string_view my_host; 更改为 std::string my_host;,因为Boost v1.82 不再使用 std::string_view

这些更改应该可以解决您遇到的错误。

英文:
boost_1_82_0/boost/beast/core/string_type.hpp:18:1: note: ‘#pragma message: BOOST_BEAST_USE_STD_STRING_VIEW is deprecated, use BOOST_NO_CXX17_HDR_STRING_VIEW instead’
&#160; &#160;18 | BOOST_PRAGMA_MESSAGE(&quot;BOOST_BEAST_USE_STD_STRING_VIEW is deprecated, use BOOST_NO_CXX17_HDR_STRING_VIEW instead&quot;);

Legacy code:
#define BOOST_BEAST_USE_STD_STRING_VIEW

std::string_view my_host;
beast::http::request&lt;http::empty_body&gt; my_request;
my_request.set(http::field::host, my_host);

Updated code: changes made for boost v1.82
#define BOOST_NO_CXX17_HDR_STRING_VIEW    

Now I see the following errors:

error: no matching function for call to ‘boost::beast::http::message&lt;true, boost::beast::http::empty_body, boost::beast::http::basic_fields&lt;std::allocator&lt;char&gt; &gt;
&gt;::set(boost::beast::http::field, std::string_view&amp;)’

Question> What is the best way to adapt the legacy code and migrate it to the v1.82?

Thank you

答案1

得分: 1

The switch for string_view types is deprecated, as you already know.

The good news is, it is no longer needed. By dropping the deprecated define (BOOST_BEAST_USE_STD_STRING_VIEW) everything should compile.

The reason is that Beast changed to Boost Core's string_view implementation. This one is interoperable with all common string-view implementations (Boost Utility, Boost Core, boost::string_ref, std::string_view).

Source: I implemented the PR for this change before Boost 1.81

英文:

The switch for string_view types is deprecated, as you already know.

The good news is, it is no longer needed. By dropping the deprecated define (BOOST_BEAST_USE_STD_STRING_VIEW) everything should compile.

The reason is that Beast changed to Boost Core's string_view implementation. This one is interoperable with all common string-view implementations (Boost Utility, Boost Core, boost::string_ref, std::string_view).

Source: I implemented the PR for this change before Boost 1.81

huangapple
  • 本文由 发表于 2023年8月4日 02:03:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76830596.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定