pass template object to function

I am using several histogram objects (from boos::histogram). I would like to pass these histograms to a function, to handle my program output outside my main.cpp.


1
2
3
4
// init histogram and axis
auto ax1 = boost::histogram::axis::regular<>(n_h_bins,xvalue_l, xvalue_r, "x");
auto ax2 = boost::histogram::axis::regular<>(n_v_bins,yvalue_l, yvalue_u, "y");
auto h = boost::histogram::make_histogram(ax1, ax2);


I wish to define a function that I can call as func(arguments).
so I define something like

void func(urgh! what do I put here???)

what shall I use as argument list?
I'd rather just template the arguments and let duck typing do its magic.
1
2
3
4
template <class T>
void func(T histogram){
   //...
}
it does work fine.
As a simple curiosity, how do I make sure that T implements the required methods?
I know the compiler will check it for me t compile time, but let's say I wish to include this in a library...
As a simple curiosity, how do I make sure that T implements the required methods?

Write a constraint:
https://www.stroustrup.com/good_concepts.pdf
https://en.cppreference.com/w/cpp/language/constraints
Last edited on
Topic archived. No new replies allowed.