mardi 30 avril 2019

How to tell if expression is evaluated at compile time or runtime?

I have a rather big Map object and I want to have a separate list that has the keys sorted. This will be used in many other source files of my poject.

The question is about how do I know when a decalaration/definition is a compile time job. Where should I look to find if this is the case? I mean how to tell?

In the following example, is the list in the source file a compile time job or it happens at runtime?

Also, is there a way that I make the sorting operation at compile time?

// global.h    
extern QMap<int, QString> G_MAP;
extern QList<int> G_MAP_SKEYS_SORTED; 

// global.cpp
QMap<int, QString> G_MAP = { /* some data */ };
QList<int> G_MAP_SKEYS_SORTED = G_MAP.keys();

// main.cpp
int mian() {
  // Somewhere I do the sort
  std::sort(G_ListRegistersSorted.begin(), G_ListRegistersSorted.end());
}

Aucun commentaire:

Enregistrer un commentaire