Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: The C Containers library |
| Date | 2015-11-01 10:57 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87r3ka6l7c.fsf@bsb.me.uk> (permalink) |
| References | <n14lk4$hmh$1@dont-email.me> |
jacobnavia <jacob@jacob.remcomp.fr> writes:
> I posted yesterday a pointer to a pure C package, that allows any C
> programmer to enjoy the samelevel of abstraction than C++.
<snip>
> I post again the two examples and ask for a real discussion here,
> instead of pointing to details.
<snip>
> ------------------------------------------------------
> #include <vector>
> #include <fstream>
> #include <algorithm>
> #include <iterator>
> #include <string>
>
> using namespace std;
>
> int main(int argc,char* argv[])
> {
> char* file = argv[2]; // input file name
> char* ofile = argv[3]; // output file name
(Odd numbers. I changed this 1 and 2 to make testing more obvious.)
> vector<string> buf;
>
> fstream fin(file, ios::in);
> string d;
> while(getline(fin, d)) buf.push_back(d); //add line to buf
> sort(buf.begin(), buf.end());
> fstream fout(ofile, ios::out);
> copy(buf.begin(), buf.end(), ostream_iterator<string>(fout,"\n"));
>
> }
> --------------------------------------------------
>
> The C solution
>
> -------------------------------------------------
> #include <containers.h>
>
> int main(void)
> {
> strCollection *myData =
> istrCollection.CreateFromFile("mydata.txt");
> istrCollection.Sort(myData);
> istrCollection.WriteToFile(myData,"mySortedData.txt");
(and I replaced the the wired in names by argv[1] and argv[2] to make
the testing simpler.)
> return 0;
> }
> -------------------------------------------------
These don't show the same level of abstraction. The C++ uses a more
abstract collection (vector) than the C code does -- the C version has
the type of the elements wired into to the code. The same level of
abstraction would need a string type, and a generic collection type that
can use it.
That's very hard in C which is, I think, why you introduced the specific
generalisation of a strCollection.
The C++ also makes use of the very general abstraction of iterators. I
doubt that your collection library permits a copy function to be
implemented that can copy any ordered collection to anything that has a
suitable output iterator. It's not used to much effect here, but it
does illustrate the possibility of some very abstract algorithms.
<snip>
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-01 10:24 +0100
Re: The C Containers library Ian Collins <ian-news@hotmail.com> - 2015-11-01 22:43 +1300
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-01 12:08 +0100
Re: The C Containers library Ian Collins <ian-news@hotmail.com> - 2015-11-02 10:46 +1300
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-01 23:10 +0100
Re: The C Containers library gazelle@shell.xmission.com (Kenny McCormack) - 2015-11-01 10:57 +0000
Re: The C Containers library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-01 10:57 +0000
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-01 03:30 -0800
Re: The C Containers library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-01 16:36 +0000
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-01 10:04 -0800
Re: The C Containers library Ian Collins <ian-news@hotmail.com> - 2015-11-02 07:23 +1300
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-01 13:25 -0800
Re: The C Containers library supercat@casperkitty.com - 2015-11-01 15:44 -0800
Re: The C Containers library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-01 23:50 +0000
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-02 01:19 -0800
Re: The C Containers library Ian Collins <ian-news@hotmail.com> - 2015-11-02 22:33 +1300
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-02 02:04 -0800
Re: The C Containers library Keith Thompson <kst-u@mib.org> - 2015-11-01 12:04 -0800
Re: The C Containers library Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-01 15:41 -0500
Re: The C Containers library Keith Thompson <kst-u@mib.org> - 2015-11-01 13:26 -0800
Re: The C Containers library Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-01 16:50 -0500
csiph-web