In C++98/C++03, there are no pure/const function keywords in the language.
-
Has this changed in C++0x?
-
If so, is it possible to set such a flag even on function objects (
std::function)? So I can pass some function pointer or lambda functions and additional give the information that it is a pure/const function? The called function may have an optimized execution path for such a function. -
Is there some way to check if a given function is pure/const? I.e. for example, if there is such flag on
std::functionas described above, I probably could just check that flag. But maybe there is even a more general way.
If it has not changed, why not? I think it might be quite useful to have such a support.
Are there any open proposals about it?
No. There is a
constexprbut it means compile time constant. If its parameters areconstexprstoo then it’s executed at compile time, but it’s a regular function otherwise. Since they must be defined in the same translation unit and consist of a single return statement they probably will be inlined and the above optimization will be performed. It can’t be used to provide the compiler information about externally linked function.Actually I don’t think you need it. The language is already too big, and the programmer can easily rewrite this code to be more efficient based on her knowledge anyway. Unlike
restrictit doesn’t provide any info that can’t be expressed by other means.I haven’t seen any committee papers on that topic.