Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Melzzzzz <mel@zzzzz.invalid> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: The C Containers Library |
| Date | 2012-07-31 00:24 +0200 |
| Organization | None |
| Message-ID | <jv71jd$tjo$2@solani.org> (permalink) |
| References | (2 earlier) <5012A4F5.4030107@verizon.net> <bb206f71-6858-4c61-81e9-4c3a896bdbe0@googlegroups.com> <23b52937-3996-454b-9772-b67d5c24ad0f@googlegroups.com> <0.29b0df52ac290f7f3314.20120728172347BST.874norn9bg.fsf@bsb.me.uk> <6cb90e08-0540-4882-8874-cdd14cda50d3@googlegroups.com> |
On Mon, 30 Jul 2012 13:40:04 -0700 (PDT)
Malcolm McLean <malcolm.mclean5@btinternet.com> wrote:
> בתאריך יום שבת, 28 ביולי 2012 17:23:47 UTC+1, מאת Ben Bacarisse:
> > Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
> >
> > > But actually the result was the reverse. I think it was because
> > > STL made the syntax for just declaring an array and stepping
> > > through it too cumbersome.
> >
> >
> > What's so cumbersome? For example:
> >
> >
> > vector<int> ia = {1, 2, 3, 4, 5, 6, 7, 8};
> >
> > for (int i = 0; i < ia.size(); i++)
> >
> > cout << ia[i] << "\n";
> >
> >
> >
> > The C version is *more* cumbersome in my option.
> >
> Toy examples never show up C++'s problems. Language designers aren't
> totally stupid, and everything in C++ has some sort of point. However
> what you often find is that it only works if all the surrounding code
> is C primitives.
>
> In fact the code will end up like this
>
>
> template <class numeric, class output>
> void printintegers(output &out)
> {
> vector<numeric> ia;
> for(int i = 1; i < 9; i++)
> ia.pushback( numeric(i) );
> for(int i =0; i< ia.size(); i++)
> out << ia[i];
> }
>
Following is compilable, working code:
#include <iostream>
#include <vector>
#include <algorithm>
template <class numeric>
void printintegers(std::ostream &out)
{
std::vector<numeric> ia = {1,2,3,4,5,6,7,8};
for(auto i : ia)
out << i <<" ";
out<<'\n';
std::for_each(ia.begin(),ia.end(),[&out](numeric& n){out<<n<<" ";});
out<<'\n';
}
struct Int{
int i;
Int(int i):i(i){}
friend std::ostream& operator<<(std::ostream& os, Int& i)
{
os << i.i;
return os;
}
};
int main()
{
printintegers<Int>(std::cout);
}
> Preconditions: output must be a writable class which overloads the <<
> operator with numericals castable to a string using the (String)
> operator. numeric must be a type which accepts an integer as a
> constructor.
Done.
>
> You need code to dance around the type system and to carefully
> document everything, because it's just possible to get every numeric
> to work with every writabble stream, but only just.
Why? We have ostream class for that?
--
drwx------ 2 bmaxa bmaxa 4096 Jul 31 00:05 .
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-08 21:53 +0200
Re: The C Containers Library aftnix <aftnix@gmail.com> - 2012-07-26 13:13 -0700
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-26 22:31 +0200
Re: The C Containers Library lawrence.jones@siemens.com - 2012-07-28 17:46 -0400
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-29 02:05 +0200
Re: The C Containers Library lawrence.jones@siemens.com - 2012-07-30 14:48 -0400
Re: The C Containers Library Phil Bradby <nospam@nospam.com> - 2012-08-01 21:00 +0000
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-08-01 23:18 +0200
Re: The C Containers Library Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-02 00:48 -0700
Re: The C Containers Library James Kuyper <jameskuyper@verizon.net> - 2012-08-02 07:00 -0400
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-08-02 13:27 +0200
Re: The C Containers Library Quentin Pope <qp19433@hotmail.NOSPAM.com> - 2012-08-02 20:27 +0000
Re: The C Containers Library Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-02 05:13 -0700
Re: The C Containers Library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-08-02 14:26 -0700
Re: The C Containers Library Kenneth Brody <kenbrody@spamcop.net> - 2012-08-03 10:47 -0400
Re: The C Containers Library Noob <root@localhost> - 2012-07-29 09:58 +0200
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-07-30 00:31 -0600
Re: The C Containers Library Noob <root@localhost> - 2012-07-30 09:45 +0200
Re: The C Containers Library Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-07-30 02:10 -0700
Re: The C Containers Library lawrence.jones@siemens.com - 2012-07-30 14:54 -0400
Re: The C Containers Library James Kuyper <jameskuyper@verizon.net> - 2012-07-26 16:52 -0400
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-26 22:56 +0200
Re: The C Containers Library pacman@kosh.dhis.org (Alan Curry) - 2012-07-26 22:29 +0000
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-27 01:50 +0200
Re: The C Containers Library pacman@kosh.dhis.org (Alan Curry) - 2012-07-27 22:28 +0000
Re: The C Containers Library Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-07-29 06:31 -0700
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-07-30 00:26 -0600
Re: The C Containers Library Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-07-30 02:21 -0700
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-08-02 02:27 -0600
Re: The C Containers Library Rui Maciel <rui.maciel@gmail.com> - 2012-08-02 16:43 +0100
Re: The C Containers Library Ansel <lateknightdev@gmail.com> - 2012-08-02 17:07 -0700
Re: The C Containers Library Rui Maciel <rui.maciel@gmail.com> - 2012-08-03 22:21 +0100
Re: The C Containers Library Ansel <lateknightdev@gmail.com> - 2012-08-03 15:43 -0700
Re: The C Containers Library Anders Wegge Keller <wegge@wegge.dk> - 2012-08-04 06:32 +0200
Re: The C Containers Library Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-04 01:52 -0700
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-08-04 22:36 -0600
Re: The C Containers Library Anders Wegge Keller <wegge@wegge.dk> - 2012-08-05 08:36 +0200
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-08-05 01:28 -0600
Re: The C Containers Library Anders Wegge Keller <wegge@wegge.dk> - 2012-08-05 11:31 +0200
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-08-05 03:48 -0600
Re: The C Containers Library Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-04 03:41 -0700
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-27 01:55 +0200
Re: The C Containers Library wkaras@yahoo.com - 2012-07-26 13:45 -0700
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-26 22:53 +0200
Re: The C Containers Library wkaras@yahoo.com - 2012-07-26 18:46 -0700
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-27 10:59 +0200
Re: The C Containers Library gwowen <gwowen@gmail.com> - 2012-07-27 03:39 -0700
Re: The C Containers Library wkaras@yahoo.com - 2012-07-27 11:34 -0700
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-27 11:04 +0200
Re: The C Containers Library W Karas <wkaras@yahoo.com> - 2012-07-27 13:10 -0700
Re: The C Containers Library wkaras@yahoo.com - 2012-07-26 18:54 -0700
Re: The C Containers Library James Kuyper <jameskuyper@verizon.net> - 2012-07-27 10:25 -0400
Re: The C Containers Library wkaras@yahoo.com - 2012-07-27 11:28 -0700
Re: The C Containers Library James Kuyper <jameskuyper@verizon.net> - 2012-07-27 15:17 -0400
Re: The C Containers Library wkaras@yahoo.com - 2012-07-27 13:00 -0700
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-29 02:02 +0200
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-07-28 22:08 -0600
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-29 08:46 +0200
Re: The C Containers Library pacman@kosh.dhis.org (Alan Curry) - 2012-07-29 07:43 +0000
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-29 09:59 +0200
Re: The C Containers Library Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-07-29 06:43 -0700
Re: The C Containers Library pacman@kosh.dhis.org (Alan Curry) - 2012-07-29 17:27 +0000
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-29 20:56 +0200
Re: The C Containers Library pacman@kosh.dhis.org (Alan Curry) - 2012-07-30 00:07 +0000
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-07-30 00:07 -0600
Re: The C Containers Library Keith Thompson <kst-u@mib.org> - 2012-07-29 11:58 -0700
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-29 22:06 +0200
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-29 22:23 +0200
Re: The C Containers Library Melzzzzz <mel@zzzzz.invalid> - 2012-07-30 00:13 +0200
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-07-30 00:13 -0600
Re: The C Containers Library Keith Thompson <kst-u@mib.org> - 2012-07-30 01:10 -0700
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-07-30 02:57 -0600
Re: The C Containers Library Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-07-30 15:47 +0000
Re: The C Containers Library Keith Thompson <kst-u@mib.org> - 2012-07-30 13:01 -0700
Re: The C Containers Library Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-07-30 04:53 -0700
Re: The C Containers Library Keith Thompson <kst-u@mib.org> - 2012-07-30 13:04 -0700
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-08-02 02:11 -0600
Re: The C Containers Library James Kuyper <jameskuyper@verizon.net> - 2012-08-02 06:52 -0400
Re: The C Containers Library James Kuyper <jameskuyper@verizon.net> - 2012-08-02 06:46 -0400
Re: The C Containers Library Rui Maciel <rui.maciel@gmail.com> - 2012-07-30 00:41 +0100
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-30 09:45 +0200
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-07-29 23:05 -0600
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-07-29 22:52 -0600
Re: The C Containers Library Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-07-30 04:56 -0700
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-08-02 02:07 -0600
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-30 17:49 +0200
Re: The C Containers Library Rui Maciel <rui.maciel@gmail.com> - 2012-07-28 09:17 +0100
Re: The C Containers Library W Karas <wkaras@yahoo.com> - 2012-07-28 15:17 -0700
Re: The C Containers Library Rui Maciel <rui.maciel@gmail.com> - 2012-07-29 11:10 +0100
Re: The C Containers Library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-07-28 06:51 -0700
Re: The C Containers Library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-07-28 17:23 +0100
Re: The C Containers Library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-07-30 13:40 -0700
Re: The C Containers Library Melzzzzz <mel@zzzzz.invalid> - 2012-07-31 00:24 +0200
Re: The C Containers Library Melzzzzz <mel@zzzzz.invalid> - 2012-07-31 00:05 +0200
Re: The C Containers Library Rui Maciel <rui.maciel@gmail.com> - 2012-07-31 00:53 +0100
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-07-31 09:24 +0200
Re: The C Containers Library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-08-02 14:45 -0700
Re: The C Containers Library Rui Maciel <rui.maciel@gmail.com> - 2012-08-03 22:31 +0100
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-08-04 00:01 +0200
Re: The C Containers Library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-08-03 23:45 +0100
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-08-04 22:47 -0600
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-08-04 22:41 -0600
Re: The C Containers Library Rui Maciel <rui.maciel@gmail.com> - 2012-08-07 10:24 +0100
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-08-07 15:30 +0200
Re: The C Containers Library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-08-07 15:35 +0100
Re: The C Containers Library Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 12:40 -0700
Re: The C Containers Library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-08 00:07 +0100
Re: The C Containers Library Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 17:31 -0700
Re: The C Containers Library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-08 03:14 +0100
Re: The C Containers Library Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-08 05:22 -0700
Re: The C Containers Library Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 12:36 -0700
Re: The C Containers Library Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-08 02:26 -0700
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-08-08 17:25 +0200
Re: The C Containers Library 88888 Dihedral <dihedral88888@googlemail.com> - 2012-08-03 16:04 -0700
Re: The C Containers Library SG <s.gesemann@gmail.com> - 2012-08-04 04:52 -0700
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-08-04 18:42 +0200
Re: The C Containers Library Ike Naar <ike@faeroes.freeshell.org> - 2012-08-04 19:17 +0000
Re: The C Containers Library Ike Naar <ike@faeroes.freeshell.org> - 2012-08-04 19:22 +0000
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-08-04 22:14 +0200
Re: The C Containers Library jacob navia <jacob@spamsink.net> - 2012-08-05 00:15 +0200
Re: The C Containers Library Ike Naar <ike@faeroes.freeshell.org> - 2012-08-04 23:13 +0000
Re: The C Containers Library "Ansel" <tinker454@trytospammenowloser.com> - 2012-08-04 22:53 -0600
csiph-web