]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/unordered/doc/src_code/dictionary.cpp
2 // Copyright 2006-2007 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)
6 #include <boost/unordered_map.hpp>
7 #include <boost/detail/lightweight_test.hpp>
8 #include <boost/algorithm/string/predicate.hpp>
9 #include "../../examples/fnv1.hpp"
11 //[case_insensitive_functions
13 : std::binary_function
<std::string
, std::string
, bool>
15 bool operator()(std::string
const& x
,
16 std::string
const& y
) const
18 return boost::algorithm::iequals(x
, y
, std::locale());
23 : std::unary_function
<std::string
, std::size_t>
25 std::size_t operator()(std::string
const& x
) const
30 for(std::string::const_iterator it
= x
.begin();
33 boost::hash_combine(seed
, std::toupper(*it
, locale
));
42 //[case_sensitive_dictionary_fnv
43 boost::unordered_map
<std::string
, int, hash::fnv_1
>
47 BOOST_TEST(dictionary
.empty());
49 dictionary
["one"] = 1;
50 BOOST_TEST(dictionary
.size() == 1);
51 BOOST_TEST(dictionary
.find("ONE") == dictionary
.end());
53 dictionary
.insert(std::make_pair("ONE", 2));
54 BOOST_TEST(dictionary
.size() == 2);
55 BOOST_TEST(dictionary
.find("ONE") != dictionary
.end() &&
56 dictionary
.find("ONE")->first
== "ONE" &&
57 dictionary
.find("ONE")->second
== 2);
59 dictionary
["One"] = 3;
60 BOOST_TEST(dictionary
.size() == 3);
61 BOOST_TEST(dictionary
.find("One") != dictionary
.end() &&
62 dictionary
.find("One")->first
== "One" &&
63 dictionary
.find("One")->second
== 3);
65 dictionary
["two"] = 4;
66 BOOST_TEST(dictionary
.size() == 4);
67 BOOST_TEST(dictionary
.find("Two") == dictionary
.end() &&
68 dictionary
.find("two") != dictionary
.end() &&
69 dictionary
.find("two")->second
== 4);
72 //[case_insensitive_dictionary
73 boost::unordered_map
<std::string
, int, ihash
, iequal_to
>
77 BOOST_TEST(idictionary
.empty());
79 idictionary
["one"] = 1;
80 BOOST_TEST(idictionary
.size() == 1);
81 BOOST_TEST(idictionary
.find("ONE") != idictionary
.end() &&
82 idictionary
.find("ONE") == idictionary
.find("one"));
84 idictionary
.insert(std::make_pair("ONE", 2));
85 BOOST_TEST(idictionary
.size() == 1);
86 BOOST_TEST(idictionary
.find("ONE") != idictionary
.end() &&
87 idictionary
.find("ONE")->first
== "one" &&
88 idictionary
.find("ONE")->second
== 1);
90 idictionary
["One"] = 3;
91 BOOST_TEST(idictionary
.size() == 1);
92 BOOST_TEST(idictionary
.find("ONE") != idictionary
.end() &&
93 idictionary
.find("ONE")->first
== "one" &&
94 idictionary
.find("ONE")->second
== 3);
96 idictionary
["two"] = 4;
97 BOOST_TEST(idictionary
.size() == 2);
98 BOOST_TEST(idictionary
.find("two") != idictionary
.end() &&
99 idictionary
.find("TWO")->first
== "two" &&
100 idictionary
.find("Two")->second
== 4);
102 return boost::report_errors();