We are migrating some of our code from c++03 to c++14 and wherever there is some performance gain we want to use c++14 features.Now in one of our projects we are parsing csv based on column names and these column names are declared in one header file like this :
const string ITEM_NAME = "Item Name";
const string ITEM_ID = "Item Id";
There are hundred of constants like this so what I want to know is Is there any significant performace gain if i change above code to something like this :
constexpr string ITEM_NAME = "Item Name";
constexpr string ITEM_ID = "Item Id";
Also is there any limit on number of constexpr that we can have in our binary since they need to be stored in read only memory ?
Does compiler automatically optimize old c++03 code also and place const variables also in read only memory and this effort is not worth ?
using namespace std;in a header or at some extremely broad scope. Risky and will get you in much trouble some places.constexpr string ITEM_NAME = "Item Name";cannot compile in the first place, so no need to worry about significant performance gain.