Click here to Skip to main content
12,949,083 members (62,155 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 15 Jan 2012

Usage of '_HAS_CPP0X' macro in Visual C++ compiler

, 16 Jan 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Usage of '_HAS_CPP0X' macro in Visual C++ compiler
Take a scenario where we are coding in Microsoft's Visual Studio VC++ 16.0 compiler
(which supports many of the C++11 features). We want to take advantage of these new features and at the same time the code should not break with older VC++ versions (which has no C++11 support).
This tip shows a possible way of doing it.


It's simple.

Starting from Visual Studio's VC++ 16.0 version compiler, we have a macro '_HAS_CPP0X', which can be utilized for this purpose. Here are a few examples:

void SomeFunction(int i){ } 
void SomeFunction(char* ch) { } 
void main()
        // Example 1
#ifdef _HAS_CPP0X
	SomeFunction(nullptr); // Take the advantage of nullptr
	SomeFunction((char*)NULL); // Hmmm...we have to go for typecasting
       // Example 2
         struct M { double x; };
	double pi = 3.14;
	const M* m = new M();
#ifdef _HAS_CPP0X
	decltype( (m->x) ) piRef = pi; // Let the compiler decide its type
	double& piRef = pi;
        // Example 3
        map< int, map<int,int> > _Map;
#ifdef _HAS_CPP0X
	auto itr1 = _Map.cbegin(); // no need for typing drudgery
	map<int, map<int,int>>::const_iterator itr1 = _Map.begin(); 

We can cook up many more examples.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Lakamraju Raghuram
Software Developer
India India

Did my masters from IIT-M in Advanced Manufacturing Technology and working mainly on C++ in CAD domain from 2004 onwards.

You may also be interested in...


Comments and Discussions

GeneralRe: To specify my previous comment: In example 1, the only purp... Pin
Stefan_Lang24-Jan-12 5:05
memberStefan_Lang24-Jan-12 5:05 
GeneralRe: While in principle I agree, I doubt a client will force you ... Pin
Stefan_Lang24-Jan-12 4:03
memberStefan_Lang24-Jan-12 4:03 
GeneralThere's an error in the very last line that contains actual ... Pin
Stefan_Lang24-Jan-12 3:50
memberStefan_Lang24-Jan-12 3:50 
GeneralIn my opinion, if you still need to use older compiler that ... Pin
Maximilien16-Jan-12 5:14
memberMaximilien16-Jan-12 5:14 
GeneralRe: I am very much in-line with this opinion, life without pre-p... Pin
Lakamraju Raghuram16-Jan-12 5:56
memberLakamraju Raghuram16-Jan-12 5:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170524.1 | Last Updated 16 Jan 2012
Article Copyright 2012 by Lakamraju Raghuram
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid