Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7065 > unrolled thread
| Started by | er <er.ci.2020@gmail.com> |
|---|---|
| First post | 2011-06-22 10:15 -0700 |
| Last post | 2011-06-25 07:01 -0700 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.c++
C++0x - nested initializer lists? er <er.ci.2020@gmail.com> - 2011-06-22 10:15 -0700
Re: C++0x - nested initializer lists? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-06-23 09:55 -0400
Re: C++0x - nested initializer lists? er <er.ci.2020@gmail.com> - 2011-06-23 08:03 -0700
Re: C++0x - nested initializer lists? Saeed Amrollahi <amrollahi.saeed@gmail.com> - 2011-06-25 01:25 -0700
Re: C++0x - nested initializer lists? Saeed Amrollahi <amrollahi.saeed@gmail.com> - 2011-06-25 07:01 -0700
| From | er <er.ci.2020@gmail.com> |
|---|---|
| Date | 2011-06-22 10:15 -0700 |
| Subject | C++0x - nested initializer lists? |
| Message-ID | <f4bf2d41-a959-47e4-a6f5-6945c63f9b4a@gc3g2000vbb.googlegroups.com> |
Hi,
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 }
};
}
[toc] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2011-06-23 09:55 -0400 |
| Message-ID | <itvglc$9f7$1@dont-email.me> |
| In reply to | #7065 |
On 6/22/2011 1:15 PM, er wrote:
> 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
[toc] | [prev] | [next] | [standalone]
| From | er <er.ci.2020@gmail.com> |
|---|---|
| Date | 2011-06-23 08:03 -0700 |
| Message-ID | <55eeaedf-5d00-40e6-b3d1-b2d7bd848d38@v11g2000prk.googlegroups.com> |
| In reply to | #7081 |
> What's "s_"? > > V > -- > I do not respond to top-posted replies, please don't ask Sorry, typedef std::string s_;
[toc] | [prev] | [next] | [standalone]
| From | Saeed Amrollahi <amrollahi.saeed@gmail.com> |
|---|---|
| Date | 2011-06-25 01:25 -0700 |
| Message-ID | <9ef07bf1-ef21-4a54-a885-148cd83b0fb3@x3g2000yqj.googlegroups.com> |
| In reply to | #7065 |
On Jun 22, 8:15 pm, er <er.ci.2...@gmail.com> wrote:
> Hi,
>
> 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 }
> };
> }
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
[toc] | [prev] | [next] | [standalone]
| From | Saeed Amrollahi <amrollahi.saeed@gmail.com> |
|---|---|
| Date | 2011-06-25 07:01 -0700 |
| Message-ID | <a4de01e8-e86c-4b87-abc6-d5dcc029c9b9@j31g2000yqe.googlegroups.com> |
| In reply to | #7065 |
On Jun 22, 8:15 pm, er <er.ci.2...@gmail.com> wrote:
> Hi,
>
> 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 }
> };
> }
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web