在 http 服务器示例的 request_handler 中删除了复制和赋值构造函数

Deleted copy and assignment constructors in request_handler of the http server example

为什么在request_handler in the ASIO http server example中删除了复制和赋值构造函数?这是保存查找的header:

class request_handler
{
public:
  request_handler(const request_handler&) = delete;
  request_handler& operator=(const request_handler&) = delete;

  /// Construct with a directory containing files to be served.
  explicit request_handler(const std::string& doc_root);

  /// Handle a request and produce a reply.
  void handle_request(const request& req, reply& rep);

private:
  /// The directory containing the files to be served.
  std::string doc_root_;

  /// Perform URL-decoding on a string. Returns false if the encoding was
  /// invalid.
  static bool url_decode(const std::string& in, std::string& out);
};

如果有的话,似乎唯一的字段 doc_root_ 可以设为 const 并且默认构造函数可以在需要时执行?该代码实际上并未复制已发布示例中的处理程序。但是,我正在探索我的代码中的可能性,如果我遗漏了一些非常基本的东西,那将是很好的理解。

这是有道理的,因为复制 doc_root_ 可能会导致额外的内存分配。这意味着对于每个新的 connection,它会将 request_handler 复制到连接,从而进行内存分配(如果 SSO 不适用于 string 当然)。

如果我能避免不必要的分配,我肯定会这样做,如果 request_handler 没有存储任何 connection 特定数据。

注意:如果它不能完全回答问题,我准备将其作为评论移动。