C preprocessor is not smart enough to do it on its own. If you are only interested in #include , you just need to collapse your own tool (in, say, Perl) to process the source files, expanding the #include lines that interest you and are ignored by the rest.
This script is a prefix for uninteresting header lines with // Ignored :
#!/usr/bin/perl use warnings; use strict; my @uninteresting = qw(iostream vector map); my $uninteresting = join '|', @uninteresting; while (<>) { s%(#include <(?:$uninteresting)>)%
Now you can do:
cat sourcefile.cpp | perl ignore-meh.pl | g++ -E
And if you want to get really fantasy:
#!/usr/bin/perl use warnings; use strict; while (<>) { s%// Ignored (#include <[^>]+>)%$1%; print; }
Now you can do:
cat sourcefile.cpp | perl ignore-meh.pl | g++ -E | perl restore-meh.pl
source share