forked from boostorg/container_hash
Update [listing]
s to become proper source code blocks
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
:source-highlighter: rouge
|
:source-highlighter: rouge
|
||||||
:nofooter:
|
:nofooter:
|
||||||
:sectlinks:
|
:sectlinks:
|
||||||
|
:source-language: c++
|
||||||
|
|
||||||
:leveloffset: +1
|
:leveloffset: +1
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
Say you have a point class, representing a two dimensional location:
|
Say you have a point class, representing a two dimensional location:
|
||||||
|
|
||||||
[listing]
|
[source]
|
||||||
----
|
----
|
||||||
class point
|
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:
|
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
|
class point
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,7 @@ Full code for this example is at link:../../examples/point.cpp[/libs/container_h
|
|||||||
[NOTE]
|
[NOTE]
|
||||||
====
|
====
|
||||||
When using `boost::hash_combine` the order of the calls matters.
|
When using `boost::hash_combine` the order of the calls matters.
|
||||||
[listing,subs="+quotes,+macros"]
|
[source]
|
||||||
----
|
----
|
||||||
std::size_t seed = 0;
|
std::size_t seed = 0;
|
||||||
boost::hash_combine(seed, 1);
|
boost::hash_combine(seed, 1);
|
||||||
@@ -58,7 +58,7 @@ boost::hash_combine(seed, 2);
|
|||||||
----
|
----
|
||||||
results in a different seed to:
|
results in a different seed to:
|
||||||
|
|
||||||
[listing,subs="+quotes,+macros"]
|
[source]
|
||||||
----
|
----
|
||||||
std::size_t seed = 0;
|
std::size_t seed = 0;
|
||||||
boost::hash_combine(seed, 2);
|
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`:
|
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::vector<std::string> some_strings;
|
||||||
std::size_t hash = boost::hash_range(some_strings.begin(), some_strings.end());
|
std::size_t hash = boost::hash_range(some_strings.begin(), some_strings.end());
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
If you have a structure `library::book`, where each book is uniquely defined by its member `id`:
|
If you have a structure `library::book`, where each book is uniquely defined by its member `id`:
|
||||||
|
|
||||||
[listing]
|
[source]
|
||||||
----
|
----
|
||||||
namespace library
|
namespace library
|
||||||
{
|
{
|
||||||
@@ -29,7 +29,7 @@ namespace library
|
|||||||
|
|
||||||
Then all you would need to do is write the function `library::hash_value`:
|
Then all you would need to do is write the function `library::hash_value`:
|
||||||
|
|
||||||
[listing,subs="+quotes,+macros"]
|
[source]
|
||||||
----
|
----
|
||||||
namespace library
|
namespace library
|
||||||
{
|
{
|
||||||
@@ -43,7 +43,7 @@ namespace library
|
|||||||
|
|
||||||
And you can now use `boost::hash` with book:
|
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 knife(3458, "Zane Grey", "The Hash Knife Outfit");
|
||||||
library::book dandelion(1354, "Paul J. Shanley",
|
library::book dandelion(1354, "Paul J. Shanley",
|
||||||
|
@@ -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:
|
Let's say we have a simple custom type:
|
||||||
|
|
||||||
[list,subs="+quotes,+macros"]
|
[source]
|
||||||
----
|
----
|
||||||
namespace foo
|
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:
|
So first move the member function out of the class:
|
||||||
|
|
||||||
[listing,subs="+quotes,+macros"]
|
[source]
|
||||||
----
|
----
|
||||||
namespace foo
|
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:
|
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
|
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
|
||||||
namespace boost
|
namespace boost
|
||||||
|
@@ -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.
|
Defines `boost::hash`, and helper functions.
|
||||||
|
|
||||||
[listing,subs="+quotes,+macros"]
|
[source]
|
||||||
----
|
----
|
||||||
namespace boost {
|
namespace boost {
|
||||||
template<typename T> struct hash;
|
template<typename T> struct hash;
|
||||||
@@ -125,7 +125,7 @@ namespace boost {
|
|||||||
|
|
||||||
==== Synopsis
|
==== Synopsis
|
||||||
|
|
||||||
[listing,subs="+quotes,+macros"]
|
[source]
|
||||||
----
|
----
|
||||||
// #include <boost/container_hash/hash.hpp>
|
// #include <boost/container_hash/hash.hpp>
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ struct hash : public std::unary_function<T, std::size_t> {
|
|||||||
|
|
||||||
==== Description
|
==== Description
|
||||||
|
|
||||||
[listing]
|
[source]
|
||||||
----
|
----
|
||||||
std::size_t operator()(T const& val) const;
|
std::size_t operator()(T const& val) const;
|
||||||
----
|
----
|
||||||
@@ -161,7 +161,7 @@ Throws:: Only throws if `hash_value(T)` throws.
|
|||||||
|
|
||||||
=== Synopsis
|
=== Synopsis
|
||||||
|
|
||||||
[listing]
|
[source]
|
||||||
----
|
----
|
||||||
// #include <boost/container_hash/hash.hpp>
|
// #include <boost/container_hash/hash.hpp>
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ struct hash<T> {
|
|||||||
|
|
||||||
=== Description
|
=== Description
|
||||||
|
|
||||||
[listing]
|
[source]
|
||||||
----
|
----
|
||||||
std::size_t operator()(T const val) const;
|
std::size_t operator()(T const val) const;
|
||||||
----
|
----
|
||||||
@@ -189,7 +189,7 @@ Throws:: Doesn't throw
|
|||||||
|
|
||||||
=== hash_combine
|
=== hash_combine
|
||||||
|
|
||||||
[listing]
|
[source]
|
||||||
----
|
----
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void hash_combine(size_t &, T const&);
|
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
|
=== hash_range
|
||||||
|
|
||||||
[listing]
|
[source]
|
||||||
----
|
----
|
||||||
template<typename It>
|
template<typename It>
|
||||||
std::size_t hash_range(It, 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]
|
[horizontal]
|
||||||
Effects:: For the two argument overload:
|
Effects:: For the two argument overload:
|
||||||
+
|
+
|
||||||
[listing,subs="+quotes,+macros"]
|
[source]
|
||||||
----
|
----
|
||||||
size_t seed = 0;
|
size_t seed = 0;
|
||||||
|
|
||||||
@@ -241,7 +241,7 @@ return seed;
|
|||||||
+
|
+
|
||||||
For the three arguments overload:
|
For the three arguments overload:
|
||||||
+
|
+
|
||||||
[listing,subs="+quotes,+macros"]
|
[source]
|
||||||
----
|
----
|
||||||
for(; first != last; ++first)
|
for(; first != last; ++first)
|
||||||
{
|
{
|
||||||
@@ -265,7 +265,7 @@ Throws:: Only throws if `hash_value(std::iterator_traits<It>::value_type)` throw
|
|||||||
|
|
||||||
=== hash_value
|
=== hash_value
|
||||||
|
|
||||||
[listing]
|
[source]
|
||||||
----
|
----
|
||||||
std::size_t hash_value(bool val);
|
std::size_t hash_value(bool val);
|
||||||
std::size_t hash_value(char val);
|
std::size_t hash_value(char val);
|
||||||
@@ -357,7 +357,7 @@ Returns::
|
|||||||
|`std::pair<A, B>`
|
|`std::pair<A, B>`
|
||||||
a|
|
a|
|
||||||
|
|
||||||
[listing]
|
[source]
|
||||||
----
|
----
|
||||||
size_t seed = 0;
|
size_t seed = 0;
|
||||||
hash_combine(seed, val.first);
|
hash_combine(seed, val.first);
|
||||||
@@ -368,7 +368,7 @@ return seed;
|
|||||||
|`std::tuple<T...>`
|
|`std::tuple<T...>`
|
||||||
a|
|
a|
|
||||||
|
|
||||||
[listing]
|
[source]
|
||||||
----
|
----
|
||||||
size_t seed = 0;
|
size_t seed = 0;
|
||||||
hash_combine(seed, get<0>(val));
|
hash_combine(seed, get<0>(val));
|
||||||
|
@@ -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:
|
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> >
|
std::unordered_multiset<int, boost::hash<int> >
|
||||||
set_of_ints;
|
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:
|
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>
|
#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:
|
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>
|
template <class Container>
|
||||||
std::vector<std::size_t> get_hashes(Container const& x)
|
std::vector<std::size_t> get_hashes(Container const& x)
|
||||||
|
Reference in New Issue
Block a user