What is the simplest and least obtrusive way to indicate to the compiler, whether by means of compiler options, #define
s, typedef
s, or templates, that every time I say T
, I really mean T const
? I would prefer not to make use of an external preprocessor. Since I don't use the mutable
keyword, that would be acceptable to repurpose to indicate mutable state.
Edit: Since the intent of this was mistaken entirely (and since I wasn't around for a few hours to clarify), let me explain. In essence, I just want to know what systems are available for manipulating the type system at compile time. I don't care if this creates nonstandard, bad, unmaintainable, useless code. I'm not going to use it in production. It's just a curiosity.
Potential (suboptimal) solutions so far:
// I presume redefinition of keywords is implementation-defined or illegal.
#define int int const
#define ptr * const
int i(0);
int ptr j(&i);
typedef int const Int;
typedef int const* const Intp;
Int i(0);
Intp j(&i);
template<class T>
struct C { typedef T const type; typedef T const* const ptr; };
C<int>::type i(0);
C<int>::ptr j(&i);