Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I am trying to code C++ STL vector, list, queue, pq, map, etc. But i dont know how to start..

141 views
Skip to first unread message

唐彬

unread,
Dec 27, 2017, 10:50:35 AM12/27/17
to
where can i find the code or tutorial to learn from, which can better my coding style and let me learn more about how they work?
thx a lot

woodb...@gmail.com

unread,
Dec 27, 2017, 11:15:30 AM12/27/17
to
On Wednesday, December 27, 2017 at 9:50:35 AM UTC-6, 唐彬 wrote:
> where can i find the code or tutorial to learn from, which can better my coding style and let me learn more about how they work?
> thx a lot

https://www.cprogramming.com/tutorial/c++-tutorial.html

A book would probably be a good idea.


Brian
Ebenezer Enterprises
http://webEbenezer.net

Paavo Helde

unread,
Dec 27, 2017, 3:28:02 PM12/27/17
to
On 27.12.2017 18:15, woodb...@gmail.com wrote:
> On Wednesday, December 27, 2017 at 9:50:35 AM UTC-6, 唐彬 wrote:
>> where can i find the code or tutorial to learn from, which can better my coding style and let me learn more about how they work?
>> thx a lot
>
> https://www.cprogramming.com/tutorial/c++-tutorial.html

Congrats Brian, you have found a (hopefully rare) C++ tutorial which
seems to contain *no* mention of std::vector, std::list, etc, despite
what OP asked for!

It is possible to learn C++ starting from high-level containers like
std::vector and leave the legacy C pointer and raw array quirks until
later. There was a good book "Accelerated C++" doing exactly this, but
it is now a bit out-dated.

Some quick googling surprisingly revealed that a pretty thorough
introduction level overview can be found in wikipedia, see e.g. from
https://en.wikipedia.org/wiki/Standard_Template_Library

Probably there are better resources somewhere...

hth
Paavo


James R. Kuyper

unread,
Dec 27, 2017, 3:57:36 PM12/27/17
to
On 12/27/2017 03:27 PM, Paavo Helde wrote:
> On 27.12.2017 18:15, woodb...@gmail.com wrote:
>> On Wednesday, December 27, 2017 at 9:50:35 AM UTC-6, 唐彬 wrote:
>>> where can i find the code or tutorial to learn from, which can better my coding style and let me learn more about how they work?
>>> thx a lot
>>
>> https://www.cprogramming.com/tutorial/c++-tutorial.html
>
> Congrats Brian, you have found a (hopefully rare) C++ tutorial which
> seems to contain *no* mention of std::vector, std::list, etc, despite
> what OP asked for!

Go up one level: <https://www.cprogramming.com/tutorial.html> contains a
section titled "C++ Standard Template Library (STL) tutorials", with
five links underneath. I'm not, in any way, endorsing this web site.

Ian Collins

unread,
Dec 27, 2017, 4:14:34 PM12/27/17
to
Why oh why do tutorial still use that obsolete term (STL)?

--
Ian.

Mr Flibble

unread,
Dec 27, 2017, 4:57:16 PM12/27/17
to
To wind pedants up of course.

/Flibble

Bonita Montero

unread,
Dec 28, 2017, 5:56:17 AM12/28/17
to
There you can download a good book on the C++ standard-library:
http://bit.ly/2C2o0yr

woodb...@gmail.com

unread,
Dec 28, 2017, 11:30:05 AM12/28/17
to
On Wednesday, December 27, 2017 at 2:28:02 PM UTC-6, Paavo Helde wrote:
> On 27.12.2017 18:15, woodb...@gmail.com wrote:
> >
> > https://www.cprogramming.com/tutorial/c++-tutorial.html
>
> Congrats Brian, you have found a (hopefully rare) C++ tutorial which
> seems to contain *no* mention of std::vector, std::list, etc, despite
> what OP asked for!

I think it's becoming more obvious that on-line code
generation is the way things have to be.

That's my explanation for the little vultures here that
want to see me fall.



Brian
Ebenezer Enterprises - Enjoying programming again.
http://webEbenezer.net

Mr Flibble

unread,
Dec 28, 2017, 12:51:16 PM12/28/17
to
On 28/12/2017 16:29, woodb...@gmail.com wrote:
> On Wednesday, December 27, 2017 at 2:28:02 PM UTC-6, Paavo Helde wrote:
>> On 27.12.2017 18:15, woodb...@gmail.com wrote:
>>>
>>> https://www.cprogramming.com/tutorial/c++-tutorial.html
>>
>> Congrats Brian, you have found a (hopefully rare) C++ tutorial which
>> seems to contain *no* mention of std::vector, std::list, etc, despite
>> what OP asked for!
>
> I think it's becoming more obvious that on-line code
> generation is the way things have to be.
>
> That's my explanation for the little vultures here that
> want to see me fall.

Another explanation is that you are simply deluded. This explanation I
find more likely.

/Flibble

woodb...@gmail.com

unread,
Dec 28, 2017, 1:15:02 PM12/28/17
to
Another vulture heard from.


Richard

unread,
Dec 28, 2017, 1:28:53 PM12/28/17
to
[Please do not mail me a copy of your followup]

=?UTF-8?B?5ZSQ5b2s?= <tb731...@gmail.com> spake the secret code
<92e272a5-2791-4e95...@googlegroups.com> thusly:

>where can i find the code or tutorial to learn from, which can better my
>coding style and let me learn more about how they work?

It is unclear if you are asking how to *implement* std::vector, etc.,
or if you are asking how to *use* the standard library.

For the latter, I recommend Nicolai Josuttis' book "The C++ Standard
Library: A Tutorial and Reference" (2nd ed.)
<http://amzn.to/2DsmXnv>

For the former, I would recommend any basic book on algorithms and
data structures. There are plenty of these as they are core computer
science and not specific to C++.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>

Vir Campestris

unread,
Dec 29, 2017, 3:49:36 PM12/29/17
to
On 28/12/2017 18:28, Richard wrote:
> [Please do not mail me a copy of your followup]
>
> =?UTF-8?B?5ZSQ5b2s?= <tb731...@gmail.com> spake the secret code
> <92e272a5-2791-4e95...@googlegroups.com> thusly:
>
>> where can i find the code or tutorial to learn from, which can better my
>> coding style and let me learn more about how they work?
>
> It is unclear if you are asking how to *implement* std::vector, etc.,
> or if you are asking how to *use* the standard library.
>
> For the latter, I recommend Nicolai Josuttis' book "The C++ Standard
> Library: A Tutorial and Reference" (2nd ed.)
> <http://amzn.to/2DsmXnv>
>
> For the former, I would recommend any basic book on algorithms and
> data structures. There are plenty of these as they are core computer
> science and not specific to C++.
>
I'd second Josuttis.

But if you value your sanity do NOT attempt to study the actual code.
Every implementation I have seen has efficiency at execution time first,
speed of compilation second, and readability not even on the list.

Andy

Richard

unread,
Dec 29, 2017, 7:27:51 PM12/29/17
to
[Please do not mail me a copy of your followup]

Vir Campestris <vir.cam...@invalid.invalid> spake the secret code
<p269oh$igm$2...@dont-email.me> thusly:

>But if you value your sanity do NOT attempt to study the actual code.
>Every implementation I have seen has efficiency at execution time first,
>speed of compilation second, and readability not even on the list.

Yeah, it's pretty hard to read, particularly since all their internal
identifiers are splat blasted with leading _'s because those are the
portions of the identifier space reserved for the implementation.

Jorgen Grahn

unread,
Dec 31, 2017, 7:01:57 AM12/31/17
to
On Thu, 2017-12-28, Richard wrote:
> [Please do not mail me a copy of your followup]
>
> =?UTF-8?B?5ZSQ5b2s?= <tb731...@gmail.com> spake the secret code
> <92e272a5-2791-4e95...@googlegroups.com> thusly:
>
>>where can i find the code or tutorial to learn from, which can better my
>>coding style and let me learn more about how they work?
>
> It is unclear if you are asking how to *implement* std::vector, etc.,
> or if you are asking how to *use* the standard library.

Yes, it's unclear.

> For the latter, I recommend Nicolai Josuttis' book "The C++ Standard
> Library: A Tutorial and Reference" (2nd ed.)
> <http://amzn.to/2DsmXnv>
>
> For the former, I would recommend any basic book on algorithms and
> data structures. There are plenty of these as they are core computer
> science and not specific to C++.

Well ... it seems to me that implementing e.g. std::list is 50% about
understanding the general concept of linked lists, and 50% about
fitting it into the C++ language and its concept of containers.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Bonita Montero

unread,
Jan 1, 2018, 1:42:13 PM1/1/18
to
> ..., and readability not even on the list.

That's serious issue. I'm trying to avoid to trace into
the standard-library of VC++. It looks like ASCII-garbage.

woodb...@gmail.com

unread,
Jan 1, 2018, 11:20:47 PM1/1/18
to
I have the same priorities in terms of run time and compile
time. It's the compile time priority that causes me to
minimize blank spaces. One man's trash is another man's
treasure.

Ian Collins

unread,
Jan 2, 2018, 1:48:21 AM1/2/18
to
On 01/02/2018 05:20 PM, woodb...@gmail.com wrote:
> On Monday, January 1, 2018 at 12:42:13 PM UTC-6, Bonita Montero wrote:
>>> ..., and readability not even on the list.
>>
>> That's serious issue. I'm trying to avoid to trace into
>> the standard-library of VC++. It looks like ASCII-garbage.
>
> I have the same priorities in terms of run time and compile
> time. It's the compile time priority that causes me to
> minimize blank spaces. One man's trash is another man's
> treasure.

You do post some utter nonsense, but that is impressive even for you...

--
Ian.

Real Troll

unread,
Jan 2, 2018, 12:34:50 PM1/2/18
to
On 27/12/2017 21:14, Ian Collins wrote:
>
> Why oh why do tutorial still use that obsolete term (STL)?
>

Because you didn't bother to tell them directly what they should be
using or for that matter, you should write to them to update their website.

Most websites don't update anything these days because the rate of
change is so rapid that one person's hobby can't keep up with them.

Microsoft has got an army of web editors who are spending all their time
updating their pages but this can't be forever. A time will come when
Microsoft will concentrate sorely on C#


Real Troll

unread,
Jan 2, 2018, 1:25:12 PM1/2/18
to
On 27/12/2017 15:50, 唐彬 wrote:
> where can i find the code or tutorial to learn from, which can better my coding style and let me learn more about how they work?
> thx a lot

You need to provide specific problems for anybody to help you here. You
started with STL but the body is about general coding styles and how to
"learn more".

To give an example, the area of a triangle can be computed as follows:

<!================== Function 01 ==================!>
int AreaofTriangle (int base, int height)
{
return base * height * 1/2;
}

This will work if the dimensions are all integers. What about when
dimensions are in decimals? So you might be tempted to write another
function like so:

<!================== Function 02 ==================!>
double AreaofTriangle2 (double base, double height)
{
return base * height * 1/2;
}

So this will work with numbers like 3.5, 4.5

However, some nit-pickers will come out with some other measurements.

So you could apply a template that can work with most sizes as long as
the logic remains the same as to how to calculate the Area of a
Triangle. So you could use this template:

<!================== Function 03 ==================!>
template <typename T>
T AreaofTriangle3 (T base, T height)
{
return base * height * 1/2;
}


Chris Ahlstrom

unread,
Jan 4, 2018, 6:13:20 AM1/4/18
to
Real Troll wrote this copyrighted missive and expects royalties:

> On 27/12/2017 15:50, 唐彬 wrote:
>> where can i find the code or tutorial to learn from, which can better my coding style and let me learn more about how they work?
>> thx a lot
>
> You need to provide specific problems for anybody to help you here. You
> started with STL but the body is about general coding styles and how to
> "learn more".
>
> To give an example, the area of a triangle can be computed as follows:
>
> <snippage>
>
> So you could apply a template that can work with most sizes as long as
> the logic remains the same as to how to calculate the Area of a
> Triangle. So you could use this template:
>
> <!================== Function 03 ==================!>
> template <typename T>
> T AreaofTriangle3 (T base, T height)
> {
> return base * height * 1/2;
> }

Just use real numbers, dude! :-D

--
You may worry about your hair-do today, but tomorrow much peanut butter will
be sold.

Fred.Zwarts

unread,
Jan 4, 2018, 7:08:52 AM1/4/18
to
"Real Troll" schreef in bericht news:p2gipj$g6h$1...@gioia.aioe.org...
I would think that "base * height / 2" would be sufficient. What is the
added value of the multiplication with 1?

James Kuyper

unread,
Jan 4, 2018, 7:12:25 AM1/4/18
to
On 01/04/2018 05:59 AM, Chris Ahlstrom wrote:
> Real Troll wrote this copyrighted missive and expects royalties:
...
>> So you could apply a template that can work with most sizes as long as
>> the logic remains the same as to how to calculate the Area of a
>> Triangle. So you could use this template:
>>
>> <!================== Function 03 ==================!>
>> template <typename T>
>> T AreaofTriangle3 (T base, T height)
>> {
>> return base * height * 1/2;
>> }
>
> Just use real numbers, dude! :-D

That's precisely what AreaofTriangle3<T> does, when T is a real number
type. Note that while the C++ standard doesn't define what "real number
type" is, the C standard does define what a "real type" is, and it
includes all integer types (C 6.2.5p17). I haven't tracked it down, but
C++ incorporates a of lot of stuff from the C standard by reference; it
might have incorporated that definition as well.

Chris Ahlstrom

unread,
Jan 4, 2018, 8:53:27 AM1/4/18
to
James Kuyper wrote this copyrighted missive and expects royalties:
I was being facetious. Computers cannot implement real numbers. :-)

--
You have a strong appeal for members of your own sex.

Real Troll

unread,
Jan 4, 2018, 12:14:39 PM1/4/18
to
On 04/01/2018 12:08, Fred.Fart wrote:
>
> I would think that "base * height / 2" would be sufficient. What is
> the added value of the multiplication with 1?

To give you something to comment about :)


Vir Campestris

unread,
Jan 4, 2018, 5:54:09 PM1/4/18
to
On 02/01/2018 17:34, Real Troll wrote:
> A time will come when Microsoft will concentrate sorely on C#

That'll hurt :P

Andy

Bonita Montero

unread,
Jan 6, 2018, 4:08:47 PM1/6/18
to
> I have the same priorities in terms of run time and compile
> time. It's the compile time priority that causes me to
> minimize blank spaces. One man's trash is another man's
> treasure.

I'm pretty sure you can insert 500% more whitespace
in your code without any noticeable compile-time drop.
0 new messages