devxlogo

Initialize STL Containers with Predefined Values

Initialize STL Containers with Predefined Values

This task is quite common task. However, explicit insertion of values can be unacceptable in many cases?like if you need to insert a lot of values.

I’ve found that it’s quite handy to use arrays for this task:

 pair arr[] ={   pair("640x480", 0),   pair("800x600", 1),   pair("1024x800", 2),   pair("1280x1024", 3)};map msi(arr, arr + sizeof(arr)/sizeof(arr[0]));

This technique is easily applied to vectors, sets, etc.

devx-admin

Share the Post: