Opened 7 years ago

Last modified 7 years ago

#11748 new Feature Requests

boost::asio::buffer() overload for string_ref and const char pointer (c-string)

Reported by: oliora@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.57.0 Severity: Optimization
Keywords: buffer Cc:

Description

There are many overloads of boost::asio::buffer() including ones for std::string and POD array, but there are no overloads for const char * and for boost::basic_string_ref<char, ...>. I propose to add such overloads.

Attachments (1)

boost_patch (809 bytes ) - added by ps06756@… 7 years ago.
Patch for handling const char *

Download all attachments as: .zip

Change History (4)

comment:1 by ps06756@…, 7 years ago

Why can't we use the constructor for void* ? There is no need for separate constructor for const char*

by ps06756@…, 7 years ago

Attachment: boost_patch added

Patch for handling const char *

comment:2 by oliora@…, 7 years ago

I meant ctor which accepts const char * without the length and calls strlen() internally:

const_buffers_1 buffer(const char* s) {
    return buffer(s, std::strlen(s));
}

comment:3 by oliora@…, 7 years ago

Ctor for string_ref:

template<class Traits>
inline const_buffers_1 buffer(const boost::basic_string_ref<char, Traits>& s) {
    return buffer(s.data(), s.size());
}

P.S. In previous example I forgot inline.

Note: See TracTickets for help on using tickets.