#include <iostream>
#if __has_include(<iostream>) == 0
#define INCLUDED_IOSTREAM_AGAIN true
#include <iostream>
#else
#define INCLUDED_IOSTREAM_AGAIN false
#endif
int main()
{
if (INCLUDED_IOSTREAM_AGAIN)
{
std::cout << "Included again." << std::endl;
}
else
{
std::cout << "Did not included again." << std::endl;
}
return 0;
}
// Output: Did not included again.
Reference: https://en.wikipedia.org/wiki/C%2B%2B17
Tuesday, October 17, 2017
C++17: __has_include
C++17 added a macro that takes a header file name as an argument, and returns 1 if it was included already, and 0 if it was not. Here is an example:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment