Is there any way to reduce the number of times you have to write:

template<typename T>

for a bunch of functions all using the same template parameters?

i.e., something like this:

template<typename T>
namespace my_functions_using_T {

T function_do_something(const T & t);

void function_do_something_else(T & t);
}


(besides making them all methods of a class... which seems heavy handed...?)

Edited 6 Years Ago by Kikazaru: anticipation of obvious answer...

Is there any way to reduce the number of times you have to write:

template<typename T>

for a bunch of functions all using the same template parameters?

i.e., something like this:

template<typename T>
namespace my_functions_using_T {

T function_do_something(const T & t);

void function_do_something_else(T & t);
}


(besides making them all methods of a class... which seems heavy handed...?)

Nope. Don't be that lazy.

You can calculate the last 10 digits of each term in the sequence and add them up.

To calculate the last ten digits of n^n do this:

unsigned long result[1000];
for(n=1; n<1000; n++) {
result[n] = 1;
for(i=0; i<n; i++)
result = (result * n) % 10;
}

better check the bounds in the loops... I didn't bother.

There's probably a cooler way, but this shouldn't take too long to compute.

Man... what the hell am I doing... I tried to reply to a question that was shown below...

Anyway, thanks for the answer.

Laziness is a virtue! :)

It seems rather remiss not to provide for this functionality, since you can end up with template definitions all over the place making things hard to figure out...

This article has been dead for over six months. Start a new discussion instead.