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);
template<class T> using c = T const;
used asc<int> a = 1.; c<int>* b = &a;
– Herculieconst
. They don't understand whyconst
should be used pervasively. I am given to understand that the important new programming language Rust makes storageconst
by default, variable only by special declaration. That is the right thing to do, in my view. For readers who don't understand this, try taking 1000 lines of C++ code and puttingconst
everywhere possible. You will discover that most symbols are naturallyconst
. – Viva