dimanche 25 avril 2021

Reflect changes in file, read with preprocessor macros

I am trying to build a simple logic, where i read a file and make some decisions based on the value in file. As far as I know I can not read a file using std library with constexpr function. I am using preprocessor macro to do that. Currently the file contains only a number 1001. Once the code is compiled and I run it I get the 2 as expected. But if I change the file to 1000 then run without recompiling the output is still 2.

I am familiar with build process and what is happening here.

Is there a way to reflect the changes in the file without recompiling it again. I am open to any suggestions or workaround, I would really appreciate it. I can use only C++11

#include <iostream>

constexpr const int ID = 
#include "file.txt" 
;

constexpr unsigned short int getRDOF()
{
    return  ID == 1000 ? 1:2;    
}
constexpr unsigned short int DOF_ = getRDOF();

int main()
{
    std::cout << "DOF_ : " << DOF_ << std::endl;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire