I am working with a library which exposes an interface to work with. One of the functions of this library is like this :
template
void modify()
"Why can't compiler evaluate i
at compile time?"
That would defeat the purpose of templates. Templates are there for the case where the source code looks the same for some set of cases, but the instructions the compiler needs to generate are different each time.
"Is there any other to achieve the objective I am trying to achieve without changing the API interface?"
Yes, look at Boost.MPL.
However I suspect the right answer here is that you want to change the API. It depends on the internals of the modify
function. I know you have it's source, because templates must be defined in headers. So have a look why it needs to know i
at compile time and if it does not, it would be best to replace (or complement if you need to maintain backward compatibility) it with normal function with parameter.