diff options
Diffstat (limited to 'libs/flyweight/example')
-rw-r--r-- | libs/flyweight/example/composite.cpp | 15 | ||||
-rw-r--r-- | libs/flyweight/example/html.cpp | 34 |
2 files changed, 12 insertions, 37 deletions
diff --git a/libs/flyweight/example/composite.cpp b/libs/flyweight/example/composite.cpp index 8dcb2d716..1395f412d 100644 --- a/libs/flyweight/example/composite.cpp +++ b/libs/flyweight/example/composite.cpp @@ -1,6 +1,6 @@ /* Boost.Flyweight example of a composite design. * - * Copyright 2006-2010 Joaquin M Lopez Munoz. + * Copyright 2006-2014 Joaquin M Lopez Munoz. * 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) @@ -47,12 +47,10 @@ typedef flyweight<list_impl> list; /* list_impl must be hashable to be used by flyweight: If a * node is a std::string, its hash resolves to that of the string; - * if it is a vector of nodes, we compute the hash by combining - * the *addresses* of the stored flyweights' associated values: this is - * consistent because flyweight equality implies equality of reference. - * Using this trick instead of hashing the node values themselves - * allow us to do the computation without recursively descending down - * through the entire data structure. + * if it is a vector of flyweight nodes, we combine their corresponding + * hash values. As hashing a flyweight does not involve actually hashing + * its pointed-to value, the resulting computation does not recursively + * descend down the entire data structure. */ struct list_hasher:boost::static_visitor<std::size_t> @@ -68,8 +66,7 @@ struct list_hasher:boost::static_visitor<std::size_t> std::size_t res=0; for(list_elems::const_iterator it=elms.begin(),it_end=elms.end(); it!=it_end;++it){ - const list_impl* p=&it->get(); - boost::hash_combine(res,p); + boost::hash_combine(res,*it); } return res; } diff --git a/libs/flyweight/example/html.cpp b/libs/flyweight/example/html.cpp index a428f1e64..1fa6d34c0 100644 --- a/libs/flyweight/example/html.cpp +++ b/libs/flyweight/example/html.cpp @@ -1,6 +1,6 @@ /* Boost.Flyweight example of flyweight-based formatted text processing. * - * Copyright 2006-2008 Joaquin M Lopez Munoz. + * Copyright 2006-2014 Joaquin M Lopez Munoz. * 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) @@ -26,33 +26,6 @@ namespace std{using ::exit;using ::tolower;} using namespace boost::flyweights; -/* See the portability section of Boost.Hash at - * http://boost.org/doc/html/hash/portability.html - * for an explanation of the ADL-related workarounds. - */ - -namespace boost{ -#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) -namespace flyweights{ -#endif - -/* We hash the various flyweight types used in the program hashing - * a *pointer* to their contents: this is consistent as equality of - * flyweights implies equality of references. - */ - -template<typename T> -std::size_t hash_value(const flyweight<T>& x) -{ - boost::hash<const T*> h; - return h(&x.get()); -} - -#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) -} /* namespace flyweights */ -#endif -} /* namespace boost */ - /* An HTML tag consists of a name and optional properties of the form * name1=value1 ... namen=valuen. We do not need to parse the properties * for the purposes of the program, hence they are all stored in @@ -70,6 +43,11 @@ bool operator==(const html_tag_data& x,const html_tag_data& y) return x.name==y.name&&x.properties==y.properties; } +/* See the portability section of Boost.Hash at + * http://boost.org/doc/html/hash/portability.html + * for an explanation of the ADL-related workarounds. + */ + #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) namespace boost{ #endif |