diff --git a/doc/samples/tutorial.cpp b/doc/samples/tutorial.cpp new file mode 100644 index 0000000..b11609b --- /dev/null +++ b/doc/samples/tutorial.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include +#include + +//[ get_hashes +template +std::vector get_hashes(Container const& x) +{ + std::vector hashes; + std::transform(x.begin(), x.end(), std::back_inserter(hashes), + boost::hash()); + + return hashes; +} +//] + +int main() { + std::vector values; + values.push_back(10); + values.push_back(20); + + std::vector hashes = get_hashes(values); + assert(hashes[0] = boost::hash()(values[0])); + assert(hashes[1] = boost::hash()(values[1])); +} diff --git a/doc/tutorial.qbk b/doc/tutorial.qbk index f91f173..234b759 100644 --- a/doc/tutorial.qbk +++ b/doc/tutorial.qbk @@ -3,6 +3,9 @@ / 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) ] +[quickbook 1.7] +[import samples/tutorial.cpp] + [def __multi-index-short__ [@boost:/libs/multi_index/doc/index.html Boost.MultiIndex]] @@ -39,15 +42,7 @@ To use [classref boost::hash] directly, create an instance and call it as a func For an example of generic use, here is a function to generate a vector containing the hashes of the elements of a container: - template - std::vector get_hashes(Container const& x) - { - std::vector hashes; - std::transform(x.begin(), x.end(), std::insert_iterator(hashes), - ``[classref boost::hash]``()); - - return hashes; - } +[get_hashes] [endsect]