This does not compile under gcc-4.4: converting to 'std::tuple<>' from
initializer list would use explicit constructor. Is it conformant
anyway? Thanks.
{
typedef std::tuple<s_, int> t_;
typedef std::vector<t_> v_;
v_ v = {
{ "a", 1 },
{ "b", 2 },
{ "c", 3 },
{ "d", 4 },
{ "e", 5 }
};
}
What's "s_"?
V
--
I do not respond to top-posted replies, please don't ask
Sorry,
typedef std::string s_;
Hi
Sorry for late feedback. Your code doesn't compile under g++ 4.6.0
too,
and I don't know it is standard conformance or not,
but if you have tuple with two 2 arguments you can use pair, actually
the following code is compiled and run:
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#include <iterator>
#include <iostream>
typedef std::string s_;
typedef std::pair<s_, int> p_;
typedef std::vector<p_> v_;
v_ v = { { "a", 1},
{ "b", 2}
};
int main()
{
using namespace std;
for (v_::size_type sz = 0; sz < v.size(); ++sz) {
cout << "{ " << v[sz].first << ", " << v[sz].second << "}" <<
'\n';
}
return 0;
}
I try to find the reason behind tuple and initializer list
HTH,
-- Saeed Amrollahi
I study the C++ standard document and asked your question
from C++ committee members.
You can't use initializer lists
with tuple because, tuple constructors are explicit, but the pair
constructors are not. You have to use the make_tuple function:
typedef std::vector<std::tuple<std::string, int>> v_;
v_ v = {
std::make_tuple("a", 1),
std::make_tuple("b", 2)
};
HTH,
-- Saeed Amrollahi