One option is to use something like this...
It's quite ugly workaround but is also pretty easy to replace it once the initializer list will be available to you.
Otherwise known as boost::assign::list_of().
One option is to use something like this...
It's quite ugly workaround but is also pretty easy to replace it once the initializer list will be available to you.
Otherwise known as boost::assign::list_of().
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
typedef std::vector<std::string> StringList;
StringList &operator<<(StringList &a, const std::string s)
{
a.push_back(s);
return a;
}
void func(const StringList &s);
void f()
{
func(StringList() << "one" << "two" << "three");
}
This sort of thing is used a lot in Qt, although QVector and QList have built-in << operators. The above should work in principle though, but might be better to wrap std::vector<std::string> inside a StringList class.
there is also a rather native solution for strings in a string, by sealing strings upon a common denominator
int vrbcnt=GetVerbs("|go|done|big");
you can proceduraly create the parameter.
there is also a rather native solution for strings in a string, by sealing strings upon a common denominator
Possible, but I wouldn't recommend it, unless there is a parsing solution that I'm unaware of. If you have to parse it manually, its a pain compared to the vector
void function(const std::vector<std::string>& vStrings)
{
for(auto& str : vStrings)
{
// do stuff
}
}
void function(const std::string& strValues)
{
const auto strCopy = strValues; // we can't modify the incoming string, so copy is necessary, unless we want to store current-position, which makes things even more complicated
auto seperator = strCopy.find("|");
while(seperator != std::string::npos)
{
const auto nextSeperator = strCopy.find("|");
const auto strValue = strCopy.substr(seperator+1, nextSeperator - (seperator + 1));
// do stuff with value
strCopy.erase(seperator);
seperator = strCopy.find("|");
}
if(!strCopy.empty())
{
// do stuff in case eigther there is no seperator or there is still something left - dublicate code incoming!
}
}
I cringe everytime I even have to think about writing something like that... I do believe that there is some logic error in my code though that fixing would require even more code (it is just an example, sue me ;) ).
EDIT: In a less serious manner, this reminds me of Stringly typed (7.), and I personally (seriously again) would not recommend to fall back to parsing values in and out of strings unless you absolutely have to.
I'm guessing you're using Visual Studio. VS <2013 doesn't have initializer lists.Possible i don't have latest c++11?
I am out dated ... 99$ for 2013 upgrade, too broke ATM for that.
I will make do with horrible syntax.
You can get the Visual Studio 2013 Expess edition for free if it fits your needs. You only have to register your email after 30 days to continue free usage for unlimited period.
I'm guessing you're using Visual Studio. VS <2013 doesn't have initializer lists.Possible i don't have latest c++11?
I am out dated ... 99$ for 2013 upgrade, too broke ATM for that.
I will make do with horrible syntax.
You can get the Visual Studio 2013 Expess edition for free if it fits your needs. You only have to register your email after 30 days to continue free usage for unlimited period.
thx!
The Wanderer - Lost in time:
http://en.sfml-dev.org/forums/index.php?topic=14563.msg102482#msg102482