Generating a Static Map Efficiently
<p>I'm writing a simple parser in C++ that works using a map of string 'triggers' to 'handler' function pointers, my question is what would be the most 'static' and efficient method of implementing generation and access to the map?</p>

<p>I first considered a method, e.g. <code>Parser::add_handler</code>, that would add the trigger/handler to the parser's map, but, as far as I know, this would need to be executed every time the program was ran whilst the data is known at compile time.  (Although on the plus side, they would only need executed once, and not for each instantiated Parser.)</p>

<p>I then thought of using a virtual method, e.g. <code>Parser::get_handlers</code> in Parser that would be implemented in derived classes to return the handler map for that parser.  This seems like a more nicely encapsulated solution although it would require a virtual function call for every created instance of the parser, with at least one call to the parser's map-generating function.</p>

<p>Using the latter approach seems preferable at the moment, but it still leaves the map to be generated dynamically on each execution, is there away to avoid this?</p>
