2007-01-10 00:08:41 +00:00
|
|
|
|
2007-03-18 20:00:59 +00:00
|
|
|
// Copyright 2006-2007 Daniel James.
|
2007-01-10 00:08:41 +00:00
|
|
|
// 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)
|
|
|
|
|
|
|
|
// This file implements a locale aware case insenstive equality predicate and
|
|
|
|
// hash function. Unfortunately it still falls short of full
|
|
|
|
// internationalization as it only deals with a single character at a time
|
|
|
|
// (some languages have tricky cases where the characters in an upper case
|
|
|
|
// string don't have a one-to-one correspondence with the lower case version of
|
|
|
|
// the text, eg. )
|
|
|
|
|
|
|
|
#if !defined(BOOST_HASH_EXAMPLES_CASE_INSENSITIVE_HEADER)
|
|
|
|
#define BOOST_HASH_EXAMPLES_CASE_INSENSITIVE_HEADER
|
|
|
|
|
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
|
|
|
#include <boost/functional/hash.hpp>
|
|
|
|
|
|
|
|
namespace hash_examples
|
|
|
|
{
|
|
|
|
struct iequal_to
|
|
|
|
: std::binary_function<std::string, std::string, bool>
|
|
|
|
{
|
|
|
|
iequal_to() {}
|
|
|
|
explicit iequal_to(std::locale const& l) : locale_(l) {}
|
|
|
|
|
|
|
|
template <typename String1, typename String2>
|
|
|
|
bool operator()(String1 const& x1, String2 const& x2) const
|
|
|
|
{
|
Merged revisions 41822-41992,41994-42101 via svnmerge from
https://svn.boost.org/svn/boost/branches/unordered/dev
........
r41822 | danieljames | 2007-12-07 12:51:54 +0000 (Fri, 07 Dec 2007) | 5 lines
Change the macros to meet boost guidelines.
I should really have done this before the review. At least it'll give them
something to say.
........
r41928 | danieljames | 2007-12-09 19:23:27 +0000 (Sun, 09 Dec 2007) | 1 line
Add some parameters to standalone documentation build.
........
r41929 | danieljames | 2007-12-09 19:24:07 +0000 (Sun, 09 Dec 2007) | 1 line
An extra rehash test for inserting a range.
........
r41930 | danieljames | 2007-12-09 19:24:52 +0000 (Sun, 09 Dec 2007) | 1 line
get_for_erase can be static because all the required information is in the iterator.
........
r41931 | danieljames | 2007-12-09 19:31:00 +0000 (Sun, 09 Dec 2007) | 1 line
ADL doesn't seem to be working properly on Visual C++ 7.1 when calling swap, so workaround this in the compile tests.
........
r41932 | danieljames | 2007-12-09 19:44:46 +0000 (Sun, 09 Dec 2007) | 1 line
Try to make the erase exception requirements a little clearer.
........
r41933 | danieljames | 2007-12-09 19:52:50 +0000 (Sun, 09 Dec 2007) | 1 line
Hopefully clearer comparison of accessors for comparison/hash function objects.
........
r41943 | danieljames | 2007-12-10 00:03:53 +0000 (Mon, 10 Dec 2007) | 1 line
Fix a typo.
........
r41951 | danieljames | 2007-12-10 11:08:02 +0000 (Mon, 10 Dec 2007) | 1 line
Use the locale in the case insensitive comparison, I really should add a test for this.
........
r41994 | danieljames | 2007-12-13 00:26:05 +0000 (Thu, 13 Dec 2007) | 3 lines
Hervé Brönnimann's improved explanation of the formula for avoiding
invalidating iterators.
........
r41995 | danieljames | 2007-12-13 00:30:46 +0000 (Thu, 13 Dec 2007) | 4 lines
Explicity use the classic locale in the case insensitive example. I could make
the locale a member, but that would make the example longer. Also, this would be
a good place to put a note about the need for constant function objects.
........
r41996 | danieljames | 2007-12-13 00:31:55 +0000 (Thu, 13 Dec 2007) | 1 line
Pull the point examples out into test files - fixing a few bugs in the process.
........
r41997 | danieljames | 2007-12-13 00:41:30 +0000 (Thu, 13 Dec 2007) | 3 lines
A few reference links for boost::hash, it might be better to link to the
first page of the Boost.Hash documentation though.
........
r42092 | danieljames | 2007-12-16 10:07:27 +0000 (Sun, 16 Dec 2007) | 2 lines
Fix some typos, and use American spelling.
........
r42093 | danieljames | 2007-12-16 10:11:00 +0000 (Sun, 16 Dec 2007) | 1 line
Small documentation tweak.
........
r42096 | danieljames | 2007-12-16 10:17:03 +0000 (Sun, 16 Dec 2007) | 1 line
Fix some reference documentation errors.
........
r42097 | danieljames | 2007-12-16 10:28:08 +0000 (Sun, 16 Dec 2007) | 1 line
Document the explicit constructors.
........
r42098 | danieljames | 2007-12-16 10:47:13 +0000 (Sun, 16 Dec 2007) | 1 line
Try to make the active issues and proposals a little clearer - including more obvious links to the relevant papers.
........
r42099 | danieljames | 2007-12-16 10:52:30 +0000 (Sun, 16 Dec 2007) | 1 line
Fix some complexity errors in the comparison table.
........
r42100 | danieljames | 2007-12-16 10:59:45 +0000 (Sun, 16 Dec 2007) | 1 line
Use Mapped instead of T in the documentation.
........
r42101 | danieljames | 2007-12-16 11:06:16 +0000 (Sun, 16 Dec 2007) | 1 line
Remove hard-coded length of prime numbers.
........
[SVN r42187]
2007-12-19 23:09:09 +00:00
|
|
|
return boost::algorithm::iequals(x1, x2, locale_);
|
2007-01-10 00:08:41 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
std::locale locale_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ihash
|
2007-11-16 00:35:34 +00:00
|
|
|
: std::unary_function<std::string, std::size_t>
|
2007-01-10 00:08:41 +00:00
|
|
|
{
|
|
|
|
ihash() {}
|
|
|
|
explicit ihash(std::locale const& l) : locale_(l) {}
|
|
|
|
|
|
|
|
template <typename String>
|
2007-11-16 00:35:34 +00:00
|
|
|
std::size_t operator()(String const& x) const
|
2007-01-10 00:08:41 +00:00
|
|
|
{
|
|
|
|
std::size_t seed = 0;
|
|
|
|
|
|
|
|
for(typename String::const_iterator it = x.begin();
|
|
|
|
it != x.end(); ++it)
|
|
|
|
{
|
|
|
|
boost::hash_combine(seed, std::toupper(*it, locale_));
|
|
|
|
}
|
|
|
|
|
|
|
|
return seed;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
std::locale locale_;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|