英文:
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,您需要做以下更改:
-
移除
#define BOOST_BEAST_USE_STD_STRING_VIEW
,并替换为#define BOOST_NO_CXX17_HDR_STRING_VIEW
,因为在Boost v1.82中已不再使用标准库的std::string_view
。 -
将
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’
   18 | BOOST_PRAGMA_MESSAGE("BOOST_BEAST_USE_STD_STRING_VIEW is deprecated, use BOOST_NO_CXX17_HDR_STRING_VIEW instead");
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: 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<true, boost::beast::http::empty_body, boost::beast::http::basic_fields<std::allocator<char> >
>::set(boost::beast::http::field, std::string_view&)’
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论