why async_read_until() stores delimiter as std::string internally?

Viewed 29

my question is about the theoretical explanation, because asio usually puts the user in charge of buffer lifetimes. so why in the case of async_read_until(string_view delim) asio copies the delimiter allocating memory for this using std::string?

1 Answers

I think it is for legacy support. The actual implementation defines the argument type as BOOST_ASIO_STRING_VIEW_PARAM which in places where there exists no string_view will take std::string const&.

That's step one. Here you could argue that it would be nicer if move-semantics were applied, but that would make it hard to get the required implicit conversions to std::string for types that are compatible but not actually std::string&&.

All in all, it's a compromise that is likely to go away in the future when older platforms/compilers are dropped.

Related