c++ - Initialize static const std::map during compile time? -


i have table in c++ program , have initialize @ beginning of program using this:

static const map<string, int> m; m["a"] = 1; m["b"] = 2; ... 

i wondering if there anyway can make initialization process happen @ compile time rather run time? understand has small impact of performance program. curious in scope of current c++11/14/17 semantic possible or not.

no, can't initialize std::map data in compile time!

however, can use "fancier" initializer if prefer, can have data in const std::map, in case trying do.

static const map<string, int> m = {     { "a", 1 },     { "b", 2 } }; 

but again, not initialize std::map in compile time. behind scenes, std::map job in runtime.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -