Update [listing]s to become proper source code blocks

This commit is contained in:
Christian Mazakas
2022-02-08 12:00:47 -08:00
parent 8d820ee7d0
commit cb233af718
6 changed files with 27 additions and 26 deletions

View File

@@ -6,6 +6,7 @@
:source-highlighter: rouge
:nofooter:
:sectlinks:
:source-language: c++
:leveloffset: +1

View File

@@ -5,7 +5,7 @@
Say you have a point class, representing a two dimensional location:
[listing]
[source]
----
class point
{
@@ -24,7 +24,7 @@ public:
and you wish to use it as the key for an unordered_map. You need to customise the hash for this structure. To do this we need to combine the hash values for x and y. The function `boost::hash_combine` is supplied for this purpose:
[listing,subs="+quotes,+macros"]
[source]
----
class point
{
@@ -50,7 +50,7 @@ Full code for this example is at link:../../examples/point.cpp[/libs/container_h
[NOTE]
====
When using `boost::hash_combine` the order of the calls matters.
[listing,subs="+quotes,+macros"]
[source]
----
std::size_t seed = 0;
boost::hash_combine(seed, 1);
@@ -58,7 +58,7 @@ boost::hash_combine(seed, 2);
----
results in a different seed to:
[listing,subs="+quotes,+macros"]
[source]
----
std::size_t seed = 0;
boost::hash_combine(seed, 2);
@@ -71,7 +71,7 @@ If you are calculating a hash value for data where the order of the data doesn't
To calculate the hash of an iterator range you can use `boost::hash_range`:
[listing,subs="+quotes,+macros"]
[source]
----
std::vector<std::string> some_strings;
std::size_t hash = boost::hash_range(some_strings.begin(), some_strings.end());

View File

@@ -7,7 +7,7 @@
If you have a structure `library::book`, where each book is uniquely defined by its member `id`:
[listing]
[source]
----
namespace library
{
@@ -29,7 +29,7 @@ namespace library
Then all you would need to do is write the function `library::hash_value`:
[listing,subs="+quotes,+macros"]
[source]
----
namespace library
{
@@ -43,7 +43,7 @@ namespace library
And you can now use `boost::hash` with book:
[listing,subs="+quotes,+macros"]
[source]
----
library::book knife(3458, "Zane Grey", "The Hash Knife Outfit");
library::book dandelion(1354, "Paul J. Shanley",

View File

@@ -9,7 +9,7 @@ On a strictly standards compliant compiler, an overload defined in the `boost` n
Let's say we have a simple custom type:
[list,subs="+quotes,+macros"]
[source]
----
namespace foo
{
@@ -33,7 +33,7 @@ On a compliant compiler, when `hash_value` is called for this type, it will look
So first move the member function out of the class:
[listing,subs="+quotes,+macros"]
[source]
----
namespace foo
{
@@ -63,7 +63,7 @@ Unfortunately, I couldn't declare `hash_value` as a friend, as some compilers do
For compilers which don't support ADL, `hash_value` needs to be defined in the `boost` namespace:
[listing]
[source]
----
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
namespace boost

View File

@@ -9,7 +9,7 @@ For the full specification, see section 6.3 of the http://www.open-std.org/jtc1/
Defines `boost::hash`, and helper functions.
[listing,subs="+quotes,+macros"]
[source]
----
namespace boost {
template<typename T> struct hash;
@@ -125,7 +125,7 @@ namespace boost {
==== Synopsis
[listing,subs="+quotes,+macros"]
[source]
----
// #include <boost/container_hash/hash.hpp>
@@ -137,7 +137,7 @@ struct hash : public std::unary_function<T, std::size_t> {
==== Description
[listing]
[source]
----
std::size_t operator()(T const& val) const;
----
@@ -161,7 +161,7 @@ Throws:: Only throws if `hash_value(T)` throws.
=== Synopsis
[listing]
[source]
----
// #include <boost/container_hash/hash.hpp>
@@ -172,7 +172,7 @@ struct hash<T> {
=== Description
[listing]
[source]
----
std::size_t operator()(T const val) const;
----
@@ -189,7 +189,7 @@ Throws:: Doesn't throw
=== hash_combine
[listing]
[source]
----
template<typename T>
void hash_combine(size_t &, T const&);
@@ -214,7 +214,7 @@ Throws:: Only throws if `hash_value(T)` throws. Strong exception safety, as long
=== hash_range
[listing]
[source]
----
template<typename It>
std::size_t hash_range(It, It);
@@ -228,7 +228,7 @@ Calculate the combined hash value of the elements of an iterator range.
[horizontal]
Effects:: For the two argument overload:
+
[listing,subs="+quotes,+macros"]
[source]
----
size_t seed = 0;
@@ -241,7 +241,7 @@ return seed;
+
For the three arguments overload:
+
[listing,subs="+quotes,+macros"]
[source]
----
for(; first != last; ++first)
{
@@ -265,7 +265,7 @@ Throws:: Only throws if `hash_value(std::iterator_traits<It>::value_type)` throw
=== hash_value
[listing]
[source]
----
std::size_t hash_value(bool val);
std::size_t hash_value(char val);
@@ -357,7 +357,7 @@ Returns::
|`std::pair<A, B>`
a|
[listing]
[source]
----
size_t seed = 0;
hash_combine(seed, val.first);
@@ -368,7 +368,7 @@ return seed;
|`std::tuple<T...>`
a|
[listing]
[source]
----
size_t seed = 0;
hash_combine(seed, get<0>(val));

View File

@@ -7,7 +7,7 @@ When using a hash index with link:../../../multi_index/index.html[Boost.MultiInd
If your standard library supplies its own implementation of the unordered associative containers and you wish to use `boost::hash`, just use an extra template parameter:
[listing,subs="+quotes,+macros"]
[source]
----
std::unordered_multiset<int, boost::hash<int> >
set_of_ints;
@@ -20,7 +20,7 @@ std::unordered_map<int, std::string, boost::hash<int> > map_int_to_string;
To use `boost::hash` directly, create an instance and call it as a function:
[listing,subs="+quotes,+macros"]
[source]
----
#include <boost/container_hash/hash.hpp>
@@ -34,7 +34,7 @@ int main()
For an example of generic use, here is a function to generate a vector containing the hashes of the elements of a container:
[listing,subs="+quotes,+macros"]
[source]
----
template <class Container>
std::vector<std::size_t> get_hashes(Container const& x)