TITLE: restricting constant template arguments (Newsgroups: comp.lang.c++,gnu.g++.help, 6 Oct 99) [ This shows a technique that relies on compilers enforcing that multiple definitions for typedef must be the same. -adc ] FREEMAN: Andy Freeman > I'd like to define a template for functions which must have constant > arguments. ("Must" comes from another use of the code that uses > these functions.) KUEHL: Dietmar Kuehl That one is easy: Pass the arguments as template arguments: template struct tassert { typedef int assertion; }; template <> struct tassert {}; struct foo { template int f() { typedef typename tassert<(H > S && H >= L && L > 0)>::assertion failed; return H + L + S; } }; int main() { foo f; return f.f<5, 2, 3>(); } This also turns the assertions into compile time assertions. [snip]