Skip to content

Comment on Libraries in C++ for ACMparent

Comments

Aside from the author's habit of putting spaces after angle brackets and parenthesis, it's standard looking code. It's pretty busy looking, but then again, there's a lot going on:

- A generic type T is introduced into the scope of this member function.

- The template parameter MAXN is a compile time constant that is part of the type of the data structure.

- This is the count member function of the class BST, which is paramaterized on the types mentioned above.

- count does not modify any instance variables of BST.

- The parameter x is passed by constant reference.

- count's return type is int.

- The actual value returned is 1 if find(x) evaluates to true, and 0 if find(x) evaluates to false.

You learn to look for what you need to know when reading the code. Also, it's also worth noting that this code is most decidedly C++ only. C programmers may hate this code.

Thanks for the summary. This is my code. I've since switched to using "Bst" instead of "BST" for class names. I've also stopped putting spaces inside parentheses and angle brackets. Although I still think that code looks better with the spaces, I realize that most people don't format it that way, and I'm fine going with the popular convention.

This really sucks for angle brackets though. Compare

vector<pair<int, string> > blah;

to

vector< pair< int, string > > blah;

I actually prefer the first one, since it's the closest that C++03 will allow to what I want. In C++0x, you will be able to say

  vector<pair<int, string>> blah;
And the parser will recognize >> as the end of two template calls, and not the stream operator.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.