Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Assuming i have some function template f1:
C++
template<typename f2>
int f1(int i, int j) throw() {
  return i + j + f2(i, j);
}

is there way to determine if 'f2(i, j)' can be a constexpr. (no matter it is a func. or a functor) and so mark 'f1' as a constexpr. too?

What I have tried:

I am thinking of using SFINAE here some how, but didn't find how to detect constexpr. using type traits.
Posted
Updated 2-Jul-16 8:20am
Comments
[no name] 3-Jul-16 9:17am    
Why do you want to do this. Are you trying to force f1 to be computed at compile time if f2 is a constexpr. What assumptions are you making?

1 solution

As Is understand the constexpr it is a compile time qualifier, so you MUST declare f2 also as constexpr.
C++
template <constexpr typename="" f2="">
constexpr int f1(int i, int j) throw() {
  return i + j + f2(i, j);
}</constexpr>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900