Asio v 1.11。该文档说basic_stream_socket::get_io_service()成员函数已被弃用,get_executor()必须改用。但后者executor不返回io_service。
如何获取对io_servicesocket使用的对象的引用来构造另一个?
对于std::any和std::variant我们拥有的功能,要求有关当前包含值的对象,这回nullptr如果请求不能成立时(就像dynamic_cast做):
template<class ValueType>
const ValueType *any_cast(const any *operand);
template<class ValueType>
ValueType *any_cast(any *operand);
Run Code Online (Sandbox Code Playgroud)
和
template <class T, class... Types>
std::add_pointer_t<T> get_if(variant<Types...> *pv);
template <class T, class... Types>
std::add_pointer_t<const T> get_if(const variant<Types...> *pv);
Run Code Online (Sandbox Code Playgroud)
两者都将指针作为参数。为什么?它效率不高。实现每次都检查参数是否不是nullptr。请问nullptr参数使得任何意义可言?
此函数可以是类成员或将引用作为参数(名称可能略有不同)。这种次优设计的原因是什么?只是模拟dynamic_cast界面?
从C++ 11开始,我们就有了移动语义.在下面的示例中,将使用move-constructor(或复制elision),而不是像C++ 98中那样使用copy-constructor,而无需任何额外的工作.
std::string f()
{
std::string res;
...
return res; // <- move is used here instead of copy
}
Run Code Online (Sandbox Code Playgroud)
但是这个案子怎么样?
std::string f()
{
std::optional<std::string> res;
...
return *res; // <-- will the std::string value be moved??
}
Run Code Online (Sandbox Code Playgroud)
或者一个人必须写这样的东西?
std::string f()
{
std::optional<std::string> res;
...
return *std::move(res);
}
Run Code Online (Sandbox Code Playgroud)