Deprecated Typedef

I have a few TypeDefs that I want to denounce. I do this to maintain backward compatibility with existing code. Is there an elegant (or maybe not very elegant) solution? I would like it to be platform independent, but if there is only a Visual Studio solution, that will do too.

+7
source share
2 answers

In MSVC ++, you can discard typedef as follows:

 typedef __declspec(deprecated) int myint; 

The MSVC ++ compiler generates a warning that myint out of date!

And if you want the compiler to generate a specific message when compiling an obsolete typedef, do the following:

 typedef __declspec(deprecated("myint is deprecated, so most likely in the next version this myint will be missing")) int myint; 
+11
source

If one-time simple code changes are allowed, you can simply move the typedef to the deprecated namespace, requiring the use of using namespace deprecated at points that use typedef.

If this is not an option, it may be possible to come up with a template that generates a warning when creating the instance, but I do not know how to generate such a warning:

 template <class T> class TypedefHolder; template <> class TypedefHolder<int> { typedef int WhateverType; // Something that induces a compile warning. }; 

therefore instead of:

 typedef int WhateverType; 

he becomes:

 typedef TypedefHolder<int>::WhateverType WhateverType; 
+4
source

All Articles