jeudi 1 janvier 2015

what's wrong with following pack expansion?


constexpr int ipow(int x, int n) {
return (n > 0) ? x * ipow(x, n - 1): 1;
}
template <char c>
constexpr int b3_helper() {
static_assert(c < '3', "not a ternary digit");
return c - '0';
}
template <char c, char... chars>
constexpr int b3_helper() {
static_assert(c < '3', "not a ternary digit");
return ipow(3, sizeof...(chars)) * (c - '0') + b3_helper<chars...>();
}
template <char... chars>
constexpr int operator"" _b3() {
return b3_helper<chars...>();
}
int main(){
int i = 201_b3;
return 0;
}


the compiler says



call to 'b3_helper' is ambiguous" at line 12;



how can I fix it? I find this problem when I learn the C++ programming language 4th. at page 560


Aucun commentaire:

Enregistrer un commentaire