This question is on ease of use.
I have a class template with member template function eval_sub
that is only used within the member function eval
. While arguable to remove eval_sub
, it helps eval
‘s ease-of-read that eval_sub
exists like so. However, I dislike eval_sub
‘s visiblity upon collapse of eval
‘s definition — because eval_sub
is only relevant for eval
.
template<int n>
struct A{
double x;
template<int k> void eval_sub(){
x+=exp(k);
}
void eval(){
[this]<std::size_t... k>(std::index_sequence<k...>){ (eval_sub<k>(), ...); }(std::make_index_sequence<n>{});
}
};
Question: How do I hide eval_sub
within the scope of eval
?
What I tried:
- auto lambda works obviously but I refuse it for several reasons. 1) auto is inexplicit. 2) Explitisation is unhelpful not because of language illness in pointer lingo but because of the overarching fact that such pointer (a.k.a. the “lambda”) is never needed. Case in point is that I do not need to put
eval_sub
‘s address into a variable just in order to call it. Rather is the auto lambda a jailbreak to just prevent the compiler from refusing a function definition within a function scope. - putting a struct static in front of
eval_sub
destroys the member-function characterization, in that before every attribute access withineval_sub
I’d now have to grab a handle of A’sthis
, which obliterates utility.
How do you approach this common problem? My present solution is that I live with the annoyance upon scope collapse of reading about 10 class members when really there should be only about three.
user23311233 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.