Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2008-03-24 11:26:15


Author: danieljames
Date: 2008-03-24 11:26:15 EDT (Mon, 24 Mar 2008)
New Revision: 43824
URL: http://svn.boost.org/trac/boost/changeset/43824

Log:
Move the introduction example into a cpp file, so it can be tested. Fix a bug and also avoid side-effects in asserts (thanks to Graham Mark for pointing issues these out).
Added:
   branches/unordered/trunk/libs/unordered/doc/src_code/intro.cpp (contents, props changed)
Text files modified:
   branches/unordered/trunk/libs/unordered/doc/intro.qbk | 20 +++-----------------
   1 files changed, 3 insertions(+), 17 deletions(-)

Modified: branches/unordered/trunk/libs/unordered/doc/intro.qbk
==============================================================================
--- branches/unordered/trunk/libs/unordered/doc/intro.qbk (original)
+++ branches/unordered/trunk/libs/unordered/doc/intro.qbk 2008-03-24 11:26:15 EDT (Mon, 24 Mar 2008)
@@ -84,32 +84,18 @@
 The containers are used in a similar manner to the normal associative
 containers:
 
- #include <``[headerref boost/unordered_map.hpp]``>
- #include <cassert>
-
- int main()
- {
- boost::unordered_map<std::string, int> x;
- x["one"] = 1;
- x["two"] = 2;
- x["three"] = 3;
-
- assert(x["one"] == 1);
- assert(x["missing"] == 0);
- }
+[import src_code/intro.cpp]
+[intro_example1_2]
 
 But since the elements aren't ordered, the output of:
 
- BOOST_FOREACH(map::value_type i, x) {
- std::cout<<i.first<<","<<i.second<<"\n";
- }
+[intro_example1_3]
 
 can be in any order. For example, it might be:
 
     two,2
     one,1
     three,3
- missing,0
 
 To store an object in an unordered associative container requires both an
 key equality function and a hash function. The default function objects in

Added: branches/unordered/trunk/libs/unordered/doc/src_code/intro.cpp
==============================================================================
--- (empty file)
+++ branches/unordered/trunk/libs/unordered/doc/src_code/intro.cpp 2008-03-24 11:26:15 EDT (Mon, 24 Mar 2008)
@@ -0,0 +1,30 @@
+
+// Copyright 2006-2008 Daniel James.
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+//[intro_example1_1
+#include <boost/unordered_map.hpp>
+#include <boost/foreach.hpp>
+#include <cassert>
+#include <iostream>
+//]
+
+int main() {
+//[intro_example1_2
+ typedef boost::unordered_map<std::string, int> map;
+ map x;
+ x["one"] = 1;
+ x["two"] = 2;
+ x["three"] = 3;
+
+ assert(x.at("one") == 1);
+ assert(x.find("missing") == x.end());
+//]
+
+//[intro_example1_3
+ BOOST_FOREACH(map::value_type i, x) {
+ std::cout<<i.first<<","<<i.second<<"\n";
+ }
+//]
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk