S
Sean Dettrick
I am wondering if it is possible to increment an integer at compile
time using template<int N> (or by any other method, e.g. compiler
directives etc), across multiple source files.
This may sound crazy, but I wish to build a string array (which
requires no user maintenance) of source file RCS version numbers!
The idea is, I would like to be print the beggers out or operate on
them at run time if I feel like it, by using a (maintenance free) loop.
By maintenance free, I mean that in each source file I would like to
be able to refer to some integer, say RCS::N, which is automatically
different in every source file, without the user having to specify
it (except for an initial value).
i.e. I would like to be able to have a set of files like this:
// rcs.h:
#include <string>
namespace RCS{
const int Nfiles_max=20; // max number of source files
string[Nfiles_max] Version; // to hold RCS version numbers of source files
int N;
template<int N> some_handy_way_to_increment_N_at_compile_time{};
};
// fileA.cpp:
// if fileA.cpp is compiled first, want RCS::N to have the value 0.
#include "rcs.h"
RCS::Version[RCS::N] = "$Revision$"
/* ... stuff ... */
// fileB.cpp:
// if fileB.cpp is compiled second, want RCS::N to have the value 1.
#include "rcs.h"
RCS::Version[RCS::N] = "$Revision$"
/* ... different stuff ... */
// fileC.cpp:
// if fileC.cpp is compiled third, want RCS::N to have the value 2.
#include "rcs.h"
RCS::Version[RCS::N] = "$Revision$"
int main(){
for (int i=0; i<RCS::Nfiles_max; i++ ) cout << RCS::Version << endl;
if ( RCS::Version[0] != RCS::Version[1] ) cout << "version mismatch!" << endl;
}
Any ideas on this?
I presume it is impossible, but hope to be pleasantly surprised.
Thanks in advance,
Sean Dettrick
time using template<int N> (or by any other method, e.g. compiler
directives etc), across multiple source files.
This may sound crazy, but I wish to build a string array (which
requires no user maintenance) of source file RCS version numbers!
The idea is, I would like to be print the beggers out or operate on
them at run time if I feel like it, by using a (maintenance free) loop.
By maintenance free, I mean that in each source file I would like to
be able to refer to some integer, say RCS::N, which is automatically
different in every source file, without the user having to specify
it (except for an initial value).
i.e. I would like to be able to have a set of files like this:
// rcs.h:
#include <string>
namespace RCS{
const int Nfiles_max=20; // max number of source files
string[Nfiles_max] Version; // to hold RCS version numbers of source files
int N;
template<int N> some_handy_way_to_increment_N_at_compile_time{};
};
// fileA.cpp:
// if fileA.cpp is compiled first, want RCS::N to have the value 0.
#include "rcs.h"
RCS::Version[RCS::N] = "$Revision$"
/* ... stuff ... */
// fileB.cpp:
// if fileB.cpp is compiled second, want RCS::N to have the value 1.
#include "rcs.h"
RCS::Version[RCS::N] = "$Revision$"
/* ... different stuff ... */
// fileC.cpp:
// if fileC.cpp is compiled third, want RCS::N to have the value 2.
#include "rcs.h"
RCS::Version[RCS::N] = "$Revision$"
int main(){
for (int i=0; i<RCS::Nfiles_max; i++ ) cout << RCS::Version << endl;
if ( RCS::Version[0] != RCS::Version[1] ) cout << "version mismatch!" << endl;
}
Any ideas on this?
I presume it is impossible, but hope to be pleasantly surprised.
Thanks in advance,
Sean Dettrick