I\'m testing out user defined literals. I want to make _fac return the factorial of the number.
Having it call a constexpr function works,
I don't know if there's a better way in C++11 to do this than the current accepted answer, but with relaxed constexpr in C++14, you can just write "normal" code:
constexpr unsigned long long int operator "" _fac(unsigned long long int x) {
unsigned long long int result = 1;
for (; x >= 2; --x) {
result *= x;
}
return result;
}
static_assert(5_fac == 120, "!");