Hi Dominique,
Dominique Pelle wrote:
This following program shows many allocations coming
from boost::split(..., boost::is_any_of(",")):
When using boost::is_any_of(","), there are 7 dynamic allocations
per loop iteration whereas when using the lambda predicate,
there are 0 dynamic allocation per loop as shown below:
See this thread from 2008:
https://lists.boost.org/Archives/boost//2008/02/133396.php
There are some benchmarks in my reply here:
https://lists.boost.org/Archives/boost//2008/02/133415.php
I observed that C's strcspn was one of the better choices,
but it could be beaten for search sets known at compile time
with this:
template <char c0> bool is_any_of(char c) {
return (c==c0);
}
template <char c0, char c1> bool is_any_of(char c) {
return (c==c0) || is_any_of<c1>(c);
}
template <char c0, char c1, char c2> bool is_any_of(char c) {
return (c==c0) || is_any_of<c1,c2>(c);
}
etc.
(Yes, I was writing that before variadic templates!)
I don't know if boost::is_any_of has changed in the 14 years
since then, but your observation suggests not.
Regards, Phil.
_______________________________________________
Boost-users mailing list
[email protected]
https://lists.boost.org/mailman/listinfo.cgi/boost-users