Quote:Original post by mfawcett
Quote:Original post by NotAYakk
You can't even implement a compile_time factorial calculator using their system. No loops or recursion is allowed. :(
Well, you can, only it would be a class, not a function, but I understand what you are saying.
*** Source Snippet Removed ***
That's using the template system.
The template system is sufficiently powerful(tm), it just has annoying syntax to get at the sufficiently powerful capabilities, which sucks.
I want to write clean C style code that has no side effects, feed it compile-time determined inputs, and have it generate compile-time determined outputs.
For example:
static const int my_int = numeric_limits<int>::max ();
you can "fix" this by using enums for max:
enum{ my_int = numeric_limits<int>::max };
assuming that numeric_limits was written "correctly".
But that isn't what I want.
I want:
compile_time int max( int, int ) { return a>b?a:b; }compile_time int min( int a, int b) { return a<b?a:b; }compile_time int bound( int bottom, int value, int top ) { return max(bottom, min(value, top) ); }compile_time int factorial( int n ) { if (n==0) return 1; return n*factorial(n-1); }compile_time double sin( double radians ); // in a .cpp file somewherecompile_time double cos( double radians ); // in a .cpp file somewherecompile_time double tan( double radians ); // in a .cpp file somewherecompile_time double sqrt( double src ); // in a .cpp file somewhere
at the very least. On top of this, it would be nice to have:
void do_stuff( compile_time int n );
which
forces the caller to pass a compile_time value to the function. Such a parameter can be used internally like any other compile-time-determined value.
Of course, I ain't respecting how hard it is to write a compiler when I ask for these sorts of things. :)