Topic: literal arrays
Author: stefan_nospam_@slapeta.com (Stefan Slapeta)
Date: Sat, 10 Apr 2004 17:20:58 +0000 (UTC) Raw View
David Abrahams wrote:
> Unless I'm misunderstanding your idea, I am really surprised that
> you're proposing it in light of N1509 and N1511 from the post-Kona
> mailing
N1509 merges two different ideas (sequence constructors and sequence
expressions) - which could be discussed separately - into one proposal.
I think there is not much to say against sequence expressions / array
literals in general.
There is just one thing about it which confuses me (I also mentioned it
on the lib-reflector): the proposal says that it should not be possible
to deduce arrays from literals. Currently this IS possible (without
literals, of course) and I still don't understand why this should not
also be valid code for literals:
template <typename T, std::size_t SIZE>
void f (const T (&)[SIZE])
{
}
int main()
{
int a[] = { 1, 2, 3 };
f (a);
f ( { 1, 2, 3 } ); // <- currently invalid
}
I see some danger with existing code after introducing sequence
constructors because it's possible that they exist somewhere yet and
have a different meaning afterwards.
I'm not sure if it would be better just to use the same deduction
concept like above also for constructors!
Stefan
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dave@boost-consulting.com (David Abrahams)
Date: Mon, 12 Apr 2004 18:43:44 +0000 (UTC) Raw View
stefan_nospam_@slapeta.com (Stefan Slapeta) writes:
> David Abrahams wrote:
>
>> Unless I'm misunderstanding your idea, I am really surprised that
>> you're proposing it in light of N1509 and N1511 from the post-Kona
>> mailing
>
> N1509 merges two different ideas (sequence constructors and
> sequence expressions) - which could be discussed separately -
> into one proposal.
>
> I think there is not much to say against sequence expressions /
> array literals in general.
There is. N1603 doesn't support those, but it is a much more general
solution for the same problem that yields *lots* of other benefits
along the way.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: nesotto@cs.auc.dk ("Thorsten Ottosen")
Date: Mon, 5 Apr 2004 02:26:48 +0000 (UTC) Raw View
Hi Francis,
"Francis Glassborow" <francis@robinton.demon.co.uk> wrote in message
news:0Rku02FZo+bAFwET@robinton.demon.co.uk...
>
> Before I write a paper proposing the following extension to C++ I wonder
> what other readers may think of it.
>
> Currently we allow literal arrays of (const) char in C++ ("Hello"). We
> also allow intialisers for arrays. For example:
>
> int a[] = {1, 2, 3, 4};
>
> However there is no syntax for an array literal of any type other than
> char. This results in various problems, the most notable being that the
> only collection that can be initilaised with a literals is an array. We
> can write:
>
> int a[] = {1, 2, 3, 4};
> std::vector<int> avec(a, a+3);
>
> but we always have to write that pesky definition of a. It would seem so
> much tidier to write:
>
> std::vector<int> avec = {1, 2, 3, 4};
>
> or even:
>
> std::vector<int> avec({1, 2, 3, 4});
with the small library I currently have under review at boost, we can write
std::vector<int> avec;
avec += 1,2,3,4;
std::map<string,int> amap;
assign( amap )("foo",1)("bar",2);
br
Thorsten
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: francis@robinton.demon.co.uk (Francis Glassborow)
Date: Mon, 5 Apr 2004 15:31:01 +0000 (UTC) Raw View
In article <u3c7j8und.fsf@boost-consulting.com>, David Abrahams
<dave@boost-consulting.com> writes
>francis@robinton.demon.co.uk (Francis Glassborow) writes:
>
>> Before I write a paper proposing the following extension to C++ I
>> wonder what other readers may think of it.
>>
>> Currently we allow literal arrays of (const) char in C++ ("Hello"). We
>> also allow intialisers for arrays. For example:
>>
>> int a[] = {1, 2, 3, 4};
>>
>> However there is no syntax for an array literal of any type other than
>> char.
>
><snip>
>
>> I guess there will need to be quite a bit of polish added but does
>> anyone have any serious reservations about the idea?
>
>Unless I'm misunderstanding your idea, I am really surprised that
>you're proposing it in light of N1509 and N1511 from the post-Kona
Actually those were pre-Kona and I am a little surprised that there has
been no follow-up since Kona (probably why I completely forgot them in
tyhe context of my unifying intialisation syntax/semantics)
>mailing, and N1603 from the pre-Sydney mailing which IMO solves those
>problems in a more elegant and general way.
I am sort of unconvinced that variadic templates have much impact here,
though if they do this should be made clearer as the proposal is one of
those that needs very strong motivation (variadic anything is fraught
with problems IMHO)
> Haven't you been present
>for all these EWG discussions?
I think so but sometimes new things push down my memory of older ones:-)
>
>BTW, Francis, just in case: posting April fools' hoaxes to moderated
>newsgroups doesn't always work out because posts can be delayed ;-)
Ah... but like magazine publishing a degree of latitude has to be
added:-)
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dave@boost-consulting.com (David Abrahams)
Date: Tue, 6 Apr 2004 04:01:27 +0000 (UTC) Raw View
francis@robinton.demon.co.uk (Francis Glassborow) writes:
>>> I guess there will need to be quite a bit of polish added but does
>>> anyone have any serious reservations about the idea?
>>
>>Unless I'm misunderstanding your idea, I am really surprised that
>>you're proposing it in light of N1509 and N1511 from the post-Kona
>
> Actually those were pre-Kona and I am a little surprised that there
> has been no follow-up since Kona (probably why I completely forgot
> them in tyhe context of my unifying intialisation syntax/semantics)
>
>>mailing, and N1603 from the pre-Sydney mailing which IMO solves those
>>problems in a more elegant and general way.
>
> I am sort of unconvinced that variadic templates have much impact
> here, though if they do this should be made clearer as the proposal is
> one of those that needs very strong motivation
I agree that it should be in the proposal, but I thought Jaako at
least made it very clear in his presentation at the EWG meeting in
Sydney that variadic templates can solve the same issues as N1509 and
N1511 are attempting to address.
> (variadic anything is fraught with problems IMHO)
Very FUDdy. I'b laffig so hard I forgod how da cry.
>> Haven't you been present for all these EWG discussions?
>
> I think so but sometimes new things push down my memory of older
> ones:-)
It's only been a about week ;-)
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: francis@robinton.demon.co.uk (Francis Glassborow)
Date: Wed, 7 Apr 2004 01:52:04 +0000 (UTC) Raw View
In article <uad1qgu14.fsf@boost-consulting.com>, David Abrahams
<dave@boost-consulting.com> writes
>It's only been a about week ;-)
Yes but I've had a WG14 meeting during that week:-) And I have to admit
that my mind tends to switch off when templates take centre stage.
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: stefan_nospam_@slapeta.com (Stefan Slapeta)
Date: Sat, 10 Apr 2004 16:09:12 +0000 (UTC) Raw View
David Abrahams wrote:
> Unless I'm misunderstanding your idea, I am really surprised that
> you're proposing it in light of N1509 and N1511 from the post-Kona
> mailing
N1509 merges two different ideas (sequence constructors and sequence
expressions) - which could be discussed separately - into one proposal.
I think there is not much to say against sequence expressions / array
literals in general.
There is just one thing about it which confuses me (I also mentioned it
on the lib-reflector): the proposal says that it should not be possible
to deduce arrays from literals. Currently this IS possible (without
literals, of course) and I still don't understand why this should not
also be valid code for literals:
template <typename T, std::size_t SIZE>
void f (const T (&)[SIZE])
{
}
int main()
{
int a[] = { 1, 2, 3 };
f (a);
f ( { 1, 2, 3 } ); // <- currently invalid
}
I see some danger with existing code after introducing sequence
constructors because it's possible that they exist somewhere yet and
have a different meaning afterwards.
I'm not sure if it would be better just to use the same deduction
concept like above also for constructors!
Stefan
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: francis@robinton.demon.co.uk (Francis Glassborow)
Date: Sun, 4 Apr 2004 17:25:37 +0000 (UTC) Raw View
Before I write a paper proposing the following extension to C++ I wonder
what other readers may think of it.
Currently we allow literal arrays of (const) char in C++ ("Hello"). We
also allow intialisers for arrays. For example:
int a[] = {1, 2, 3, 4};
However there is no syntax for an array literal of any type other than
char. This results in various problems, the most notable being that the
only collection that can be initilaised with a literals is an array. We
can write:
int a[] = {1, 2, 3, 4};
std::vector<int> avec(a, a+3);
but we always have to write that pesky definition of a. It would seem so
much tidier to write:
std::vector<int> avec = {1, 2, 3, 4};
or even:
std::vector<int> avec({1, 2, 3, 4});
My idea is to make {e1, e2, e3, e4} a literal array if e1, e2, e3, e4
are all literals of the same type. Actually I would like to go a step
further and allow such a thing to be a constant array if e1 etc are all
consts of the same type.
I guess there will need to be quite a bit of polish added but does
anyone have any serious reservations about the idea?
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dave@boost-consulting.com (David Abrahams)
Date: Sun, 4 Apr 2004 19:26:56 +0000 (UTC) Raw View
francis@robinton.demon.co.uk (Francis Glassborow) writes:
> Before I write a paper proposing the following extension to C++ I
> wonder what other readers may think of it.
>
> Currently we allow literal arrays of (const) char in C++ ("Hello"). We
> also allow intialisers for arrays. For example:
>
> int a[] = {1, 2, 3, 4};
>
> However there is no syntax for an array literal of any type other than
> char.
<snip>
> I guess there will need to be quite a bit of polish added but does
> anyone have any serious reservations about the idea?
Unless I'm misunderstanding your idea, I am really surprised that
you're proposing it in light of N1509 and N1511 from the post-Kona
mailing, and N1603 from the pre-Sydney mailing which IMO solves those
problems in a more elegant and general way. Haven't you been present
for all these EWG discussions?
BTW, Francis, just in case: posting April fools' hoaxes to moderated
newsgroups doesn't always work out because posts can be delayed ;-)
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]