Boost Histogram: Fast multidimensional histogram, convenient interface for C++14
github.com
github.com
auto h = make_histogram(
axis::regular<>(6, -1.0, 2.0, "x")
);
// fill histogram
auto data = { -10, -0.4, 1.1, 0.3, 1.3 };
std::for_each(data.begin(), data.end(), std::ref(h));
I would have to Google what std::ref does again, and then I have to understand why it is used, etc. The code is short and readable, but understanding it still takes time. for (double x : { -10, -0.4, 1.1, 0.3, 1.3 })
h(x);
Shorter, better.This would be a lot more readable without the deduced return type and if it had a named function for the fill that could be called from a lambda or bound function.
It's funny how we never hear Ocaml or Haskell programmers complaining about type inference.
Here is an example which demonstrates the usefulness of labels: https://raw.githubusercontent.com/boostorg/histogram/develop...
The design choice of using operator() or a fill() method was hotly debated. In the bigger picture of things, operator() is better because then 1D histogram have the same fill syntax as the accumulators from Boost::accumulators.
I can't recall the last time I saw someone use std::ref. Maybe once in the past 5 years, and I think I deleted it after I fixed something else. One of the good things about C++ is that you don't have to use all of it (in fact, you probably should not use all of it).
template <typename... Args> void foo( Args&&... args ) {
whiz( std::forward<Args>( args )... );
}
...
int i = 5;
double k = 2.3;
foo( std::ref( i ), k ); // take i by ref, k by value
I've also seen it a lot with std::thread, and basically anything else that takes a callable/functor where the developer chose not to use lambda's with reference captures.Would agree that it isn't a major language feature, but I would expect competent developers to at least know about it and why you would want to/have to use it (if they had worked with a compiler that had >=C++11 support).
I agree that not needing to use all of C++ is one of the best things about it. (Opt-in vs opt-out.)
We even provide a tool to help with that: https://www.boost.org/doc/libs/1_70_0/tools/bcp/doc/html/ind...
boost::histogram currently depends directly on 8 other boost libraries, but some of those (e.g. boost::variant) pull in a huge number of other libraries, so in total it is 29. I am working on reducing the dependencies in the upcoming versions.