Can a compiler automatically detect pure functions without the type information about purity?

Sure, you can detect pure functions in some cases. For instance, int f(int x) { return x*2; } can be detected as pure with simple static analysis. The difficulty is doing this in general, and detecting interfaces which use “internal” state but are externally pure is basically impossible. GCC does have the warning options -Wsuggest-attribute=pure … Read more

Metaprogramming in C++ and in D

The two biggest things that help template metaprogramming in D are template constraints and static if – both of which C++ could theoretically add and which would benefit it greatly. Template constraints allow you to put a condition on a template that must be true for the template to be able to be instantiated. For … Read more