I'm currently writing a program, which shares a lot of template structures in one of the header files. To evaluate those templates, I use some other helper structures, like here:
#define MAX 10
struct function1 {
static constexpr int f(int x) {
return x*(x*x+20);
}
};
struct function2 {
static constexpr int f(int x) {
return (x*x+20);
}
};
// This structure contains supremum of function contained in
// type T, on interval (0, MAX). We're assuming that f(0) is 0
// for each function class passed in T.
template <typename T>
struct supremum {
static constexpr int valueF(int n) {
return n == 0 ? 0 : (T::f(n) > T::f(n-1) ? n : valueF(n-1));
}
static constexpr int value = valueF(MAX);
};
template <typename T1, typename T2>
struct supremums {
static constexpr int s1 = supremum<T1>::value;
static constexpr int s2 = supremum<T2>::value;
};
// Sample struct initialization
supremums<function1, function2> s;
So this is my header file - the problem is that I want to share structure supremums
to users using it , but I don't want to do that with helper structure supremum
. Is there a way to hide supremum
from "the outside"?
Sorry, I just noticed these supremum structures are not valid, but these are only examples on which I wanted to show a specific problem, so their validity is not an issue.