In my project there is need to append initializer list at runtime.
I have figured the way to have initializer_list std::initializer_list<std::pair<std::string, std::string>> at runtime in my project, but not able to figure out way to append this list if user passing multiple no. of pairs.
dummy code implementation of that part is below:
#include <iostream>
#include <string.h>
#include <initializer_list>
#define __FILENAME__ strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__
#define S1(x) #x
#define S2(x) S1(x)
#define LOCATION std::string(__FILENAME__) + ":" + std::string(S2(__LINE__)) + ":" + std::string(__PRETTY_FUNCTION__)
#define ATTR_PAIR std::pair<std::string, std::string>("Log.Details",LOCATION)
int main()
{
std::string s = "op";
std::string s1 = "de";
std::string s2 = "en";
auto pa = std::make_pair(s,s1);
auto pb = std::make_pair(s,s2);
auto list = {pb,pa};
std::initializer_list<std::pair<std::string, std::string>> L({list}) ;
std::initializer_list<std::pair<std::string, std::string>> I = {ATTR_PAIR,*(L .begin()),*(L.begin()+1)}; //is there any generic way to append this with as much pairs user passes in list
for(auto it=I.begin();it!=I.end();++it)
{
std::cout<<(it->first)<<std::endl;
std::cout<<(it->second)<<std::endl;
}
}
my need is to append initializer I with as much pair I have in list . code which I wrote here, I have passed (L.begin()+1) to have 2nd pair. Is there any other generic way to do so???