]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/unordered/examples/case_insensitive.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / unordered / examples / case_insensitive.hpp
CommitLineData
7c673cae
FG
1
2// Copyright 2006-2009 Daniel James.
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6// This file implements a locale aware case insenstive equality predicate and
7// hash function. Unfortunately it still falls short of full
8// internationalization as it only deals with a single character at a time
9// (some languages have tricky cases where the characters in an upper case
10// string don't have a one-to-one correspondence with the lower case version of
11// the text, eg. )
12
13#if !defined(BOOST_HASH_EXAMPLES_CASE_INSENSITIVE_HEADER)
14#define BOOST_HASH_EXAMPLES_CASE_INSENSITIVE_HEADER
15
16#include <boost/algorithm/string/predicate.hpp>
17#include <boost/functional/hash.hpp>
18
19namespace hash_examples
20{
21 struct iequal_to
7c673cae
FG
22 {
23 iequal_to() {}
24 explicit iequal_to(std::locale const& l) : locale_(l) {}
25
26 template <typename String1, typename String2>
27 bool operator()(String1 const& x1, String2 const& x2) const
28 {
29 return boost::algorithm::iequals(x1, x2, locale_);
30 }
31 private:
32 std::locale locale_;
33 };
34
35 struct ihash
7c673cae
FG
36 {
37 ihash() {}
38 explicit ihash(std::locale const& l) : locale_(l) {}
39
40 template <typename String>
41 std::size_t operator()(String const& x) const
42 {
43 std::size_t seed = 0;
44
45 for(typename String::const_iterator it = x.begin();
46 it != x.end(); ++it)
47 {
48 boost::hash_combine(seed, std::toupper(*it, locale_));
49 }
50
51 return seed;
52 }
53 private:
54 std::locale locale_;
55 };
56}
57
58#endif