Message from C, C++ discussions
December 2019
— #howtoask
Try phrasing your question like this:
1. Tell us the problem
2. Tell us what you have done so far.
3. Tell us how you got to this point
4. Paste code in pastebin or something similar
5. Wait for beautiful answers
— That doesnt follow steps above but ok
— Not OK.
How someone can help you if you don't specify what is the problem?
Does this code compile?
If not with what error do you get?
Does it work correctly?
If not, what is the result? And what is expected result?
If it does compile, and does work correctly, then what's the problem?
— This
— Why someone who wants to help you should read your mind or guess what you need
— If you want to separate logic for different type parameters, you need to overload or use SFINAE if you want sane function to set of typesif constexpr
allows you to make logic of templated function in one place without making several SFINAE overloads
— Or you can separate logic to some "impl" template functions (without SFINAE logic) and select which function to call in main function with help of if constexpr
— I hope it makes sense
— The program doesnt print the total cost of a function
https://pastebin.com/fpkic6gL
— Likeprivate: TheFunc();
public:
void Func()
{
if constexpr (template_bool_param)
TheFunc();
else
:/ idk
}
Or based on this idea
void Func()
{
static_assert(t_bool_param,
"Func not defined"
);
TheFunc();
}
— Or even more const's 😬
constexpr void Func()
{
static_assert(t_bool_param,
"Func not defined"
);
TheFunc();
}