123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|654|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> C++ Class, Week 8

Sun, 22 Nov 2009, 15:05
Afr0
This week in the official Socoder C++ class has been about templates.

Challenges

1. Create a vector that stores a set of vectors that each store a set of integers.
2. Create a template class called Store that stores an array of T (where T is the template parameter).
3. Create an iterator, called random_iterator, that uses another iterator to iterate through a container in random order.
4. Name three places where you can get quick information about the components of the standard library (not including this book).

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Fri, 27 Nov 2009, 11:10
Phoenix
I'm not really part of the class, but seeing as no one has posted anything, I might as well answer.

1. std::vector<std::vector<int>>
2.
3.

4.
www.cplusplus.com/reference/stl/
www.sgi.com/tech/stl/table_of_contents.html
www.boost.org/doc/libs/1_41_0
Well, Boost isn't part of the standard library. But why does the book ask for three sites anyway?

Am I the only one who finds these exercises a bit stupid?

|edit| And as a funny little pedantic detail, question 2 is phrased erroneously. 'Template class' should be 'class template'. You'd expect a book to get it right, though... |edit|
Sun, 29 Nov 2009, 12:43
Afr0
1. std::vector<std::vector<int>>
2.


-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sun, 29 Nov 2009, 15:23
Cower
I got bored, so here's a probably incorrect and overkill answer for #2:

Mon, 30 Nov 2009, 09:47
Phoenix
Maybe overkill, but nonetheless a better answer. Exception specifications are however, as far as I know, deprecated or de facto deprecated.

Edited my snippet to be less stupidly abusive of STL algorithms, and to use a more conventional way of iterating.
Mon, 30 Nov 2009, 16:16
Cower
Are they deprecated? I never actually use C++ exceptions, so I just threw them in there 'cause I wanted there to be some sort of error so you don't end up writing where you shouldn't be.
Tue, 01 Dec 2009, 10:19
Phoenix
C++ Standards Committee We're still looking at deprecating exception specifications. Our current feeling is that we will deprecate them except for the ways of saying a function doesn't throw at all (e.g., the new noexcept feature, [which is] still being reviewed).

Exceptions won't be deprecated, though. Only the stuff after the function parameter lists.