Hi!

According to 
https://www.boost.org/doc/libs/latest/doc/html/boost_asio/reference/read_until/overload16.html

"The default implementation of the is_match_condition type trait evaluates to 
true for function pointers and function objects with a result_type typedef. It 
must be specialised for other user-defined function objects."

On Tuesday, October 28th, 2025 at 15:31, Klebsch, Mario via Boost-users 
<[email protected]> wrote:

> Hello,
> 
> I want to use boost::asio::read_until() and pass a functor as match 
> condition. But I don't get it to compile.
> 
> Here is my source code:
> 
> #include <boost/asio.hpp>
> 
> 
> using namespace boost::asio;
> using iterator = buffers_iteratorstreambuf::const_buffers_type;
> 
> 
> struct completion_functor
> {
> std::pair<iterator, bool> operator()(iterator begin, iterator end) {
> 
> return {};
> }
> };
> completion_functor functor;
> static_assert(is_match_condition<completion_functor>::value, 
> "completion_functor must be match condition");
> 
> static_assert(is_match_condition<decltype(functor)>::value, "functor must be 
> match condition");
> 
> 
> std::pair<iterator, bool> completion_func(iterator begin, iterator end) {
> 
> return functor(begin, end);
> }
> static_assert(is_match_condition<decltype(completion_func)>::value, 
> "completion_func must be match condition");
> 
> 
> 
> auto lambda = [](iterator begin, iterator end) -> std::pair<iterator, bool> {
> 
> return {};
> };
> static_assert(is_match_condition<decltype(lambda)>::value, "lambda must be 
> match condition");
> 
> 
> std::pair<iterator, bool> completion_func2(iterator begin, iterator end) {
> 
> return lambda(begin, end);
> }
> static_assert(is_match_condition<decltype(completion_func2)>::value, 
> "completion_func2 must be match condition");
> 
> 
> 
> int main(int argc, char *argv[])
> {
> io_context ctx;
> ip::tcp::socket s{ctx};
> streambuf buffer;
> 
> read_until(s, buffer, '\n');
> read_until(s, buffer, completion_func);
> read_until(s, buffer, completion_func2);
> // the following calls do not compile
> // read_until(s, buffer, functor);
> // read_until(s, buffer, lambda);
> }
> 
> It seems, that boost::asio::is_match_condition<> does neither accept my 
> lammda-function nor my functor. The only completion handler, that I get 
> accepted, is a classic, free-standing function (and static class member 
> functions, too).
> 
> 
> But in that function, calling the lambda or the functor does not seem to be a 
> problem for the compiler.
> 
> The documentation of read_until describes match_condition as "The function 
> object to be called to determine whether a match exists."
> 
> I would expect lambda functions and functors to be accepted as a function 
> object.
> 
> Do I have an error in the declaration of lambda or 
> completion_functor::operator()?
> 
> Does anybody now, how to get this working?
> 
> I tried boost_1_73_0 and boost_1_88_0 with g++ (Gentoo 14.3.1_p20250801 p4) 
> 14.3.1 20250801 and clang version 20.1.8
> 
> Thanks in advance,
> 
> Klebsch Mario
> Funktion | R&D
> 
> 
> 
> Tel: +49 (0) 531 38 701 718
> Raum: Braunschweig, E20
> 
> 
> 
> Diese E-Mail und die an sie angehängten Dateien sind ausschließlich für 
> Personen oder Institutionen bestimmt, deren Namen oben aufgeführt sind. Sie 
> können Informationen enthalten, die durch das Berufsgeheimnis geschützt sind 
> und deren Weitergabe strengstens untersagt ist. Jede elektronische Nachricht 
> kann geändert werden. ACTIA lehnt jede Verantwortung für diese Nachricht ab. 
> Der Inhalt dieser Nachricht stellt keine Verpflichtung seitens unseres 
> Unternehmens dar. Wenn Sie kein Empfänger sind, weisen wir Sie darauf hin, 
> dass das Lesen, Vervielfältigen oder Verteilen strengstens untersagt ist. Wir 
> bitten Sie daher, uns umgehend über diesen Brief zu informieren und diese 
> Nachricht sowie eventuell beigefügte Unterlagen aus Ihrem Postfach zu 
> löschen. Danke.
> 
> This e-mail and the files attached to it are intended exclusively for persons 
> or institutions whose names are listed above. They may contain information 
> that is protected by professional secrecy and the disclosure of which is 
> strictly prohibited. Any electronic message can be modified. ACTIA declines 
> all responsibility for this message. The content of this message does not 
> represent a commitment on the part of our company. If you are not a 
> recipient, we would like to point out that reading, copying or distribution 
> is strictly prohibited. We therefore ask you to inform us immediately about 
> this letter and to delete this message and any accompanying documents from 
> your mailbox. Thank you.
> 
> 
> 
> _______________________________________________
> Boost-users mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://lists.boost.org/mailman3/lists/boost-users.lists.boost.org/
> Archived at: 
> https://lists.boost.org/archives/list/[email protected]/message/EFS3KB5CF4OT2FHLELO43GRZR4W6RWLY/
_______________________________________________
Boost-users mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://lists.boost.org/mailman3/lists/boost-users.lists.boost.org/
Archived at: 
https://lists.boost.org/archives/list/[email protected]/message/F3RQRD44ZSLIPUCOQEZYO4VZA6CYNEPT/
 

Reply via email to