

Libraries in C++ for ACM - l0nwlf
http://shygypsy.com/tools/

======
swah
Is this beautiful or ugly to a "C/C++" programmer?

    
    
      template< class T, int MAXN >
      int BST< T, MAXN >::count( const T &x ) const
      {
          return find( x ) ? 1 : 0;
      }

~~~
scott_s
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.

~~~
Abednego
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;

~~~
scott_s
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.

------
neo7
Hi, Can you explain what is all this?

~~~
l0nwlf
These are standard data structures and algorithms coded in C++. Pretty useful
for programming competitions.

~~~
swah
I'm missing something... Are those more useful to competitions than to general
use for some reason?

~~~
jrockway
In general use, you can use real libraries instead. Or, you can choose not to
use C++, which is also a good choice.

~~~
Abednego
"Real libraries"? Hey!

------
lzm
Any other ICPC world finalists on Hacker News?

Stockholm '09 here.

~~~
rfurmani
Prague and Shanghai (Igor, the author, was also at Shanghai)

------
sohilgupta
Awesome work!! Great set of libraries for competitions...

~~~
Abednego
Thanks. I'm glad you find them useful.

------
oostevo
Somebody correct me if I'm wrong, but as far as I can remember from when I was
doing ICPC, I wasn't allowed to bring in anything in electronic format. I
could, however, bring in printed materials.

Have the rules changed? Or are these libraries just for practice problems?

~~~
l0nwlf
You can always bring codes in the form of printouts. And these libraries are
mainly for practice problems on ACM UVA Online Judge.

------
georgecmu
Are you allowed to use STL/BOOST in the competition?

~~~
ideamonk
STL is allowed in all the competitions including TC, ICPC, SPOJ, etc BOOST is
not allowed in any.

~~~
zem
why would boost not be allowed but this guy's libraries be?

~~~
ideamonk
This guy's library can be contained within your submission source code, so it
can be used. BOOST in any case won't be installed or would be kept out of
execution sandbox, on the judge server, so BOOST won't be usable. STL will be
present along the gcc version they use by default. S = Standard in STL :)

