google / benchmark

A microbenchmark support library
Apache License 2.0
8.94k stars 1.62k forks source link

Use std::function in ComputeStatistics() #1609

Closed Tasemo closed 1 year ago

Tasemo commented 1 year ago

Uses std::function instead of function pointers for the callback provided with ComputeStatistics(), if C++11 is used. This allows for greater flexibility as the user can use closures, member functions, bind expressions, etc. This should be a non API breaking change as std::function implicitly stores function pointers as well.

Closes #1604. Instead of a dedicated function, all the values can now be aggregated by the user. This should be the easier change.

LebedevRI commented 1 year ago

I'm not sure this is that simple.

If library is used (not compiled!) by C++03 code, object compute_ in Statistics type would be a pointer, but once Statistics is passed into the library's internals, it will silently become a different Statistics type, one where compute_ object is suddenly a std::function. But std::function was never constructed?

Tasemo commented 1 year ago

Ah you are right, good catch. I'll be using my fork then until support for C++03 is dropped (it has been 20 years).