Skip to content

Commit

Permalink
Synced chapter09 recipes 5 and 6
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin committed Jun 17, 2017
1 parent e771732 commit c299e8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
20 changes: 12 additions & 8 deletions Chapter09/05_bimap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,24 @@ int main() {


std::cout << "Left:\n";
typedef name_id_type::left_const_iterator left_const_iterator;
for (left_const_iterator it = name_id.left.begin(),
iend = name_id.left.end();
it!= iend;

typedef name_id_type::left_const_iterator left_const_iterator;
const left_const_iterator lend = name_id.left.end();

for (left_const_iterator it = name_id.left.begin();
it!= lend;
++it)
{
std::cout << it->first << " <=> " << it->second << '\n';
}

std::cout << "\nRight:\n";

typedef name_id_type::right_const_iterator right_const_iterator;
for (right_const_iterator it = name_id.right.begin(),
iend = name_id.right.end();
it!= iend;
const right_const_iterator rend = name_id.right.end();

for (right_const_iterator it = name_id.right.begin();
it!= rend;
++it)
{
std::cout << it->first << " <=> " << it->second << '\n';
Expand Down Expand Up @@ -89,6 +93,6 @@ typedef boost::bimap<
void example2() {
hash_name_id_type name_id;



}
9 changes: 5 additions & 4 deletions Chapter09/06_multiindex/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ inline bool operator < (const person& p1, const person& p2) {
template <std::size_t IndexNo, class Indexes>
void print(const Indexes& persons) {
std::cout << IndexNo << ":\n";

typedef typename Indexes::template nth_index<
IndexNo
>::type::const_iterator const_iterator_t;
Expand Down Expand Up @@ -60,7 +61,7 @@ void example_main() {
boost::multi_index::identity<person>
>,

// IDs are not unique, but we do not need then ordered
// IDs are not unique, but we do not need them ordered
boost::multi_index::hashed_non_unique<
boost::multi_index::member<
person, std::size_t, &person::id_
Expand All @@ -85,11 +86,11 @@ void example_main() {

indexes_t persons;

// Inserting values
// Inserting values:
persons.insert(person(1, "John Snow", 185, 80));
persons.insert(person(2, "Vasya Pupkin", 165, 60));
persons.insert(person(3, "Antony Polukhin", 183, 70));
// Same person as "Antony Polukhin"
// Same person as "Antony Polukhin".
persons.insert(person(3, "Anton Polukhin", 182, 70));

print<0>(persons);
Expand All @@ -105,7 +106,7 @@ void example_main() {
)) != persons.end()
);

// Won' compile
// Won't compile:
//assert(persons.get<0>().find("John Snow")->id_ == 1);

typedef indexes_t::nth_index<0>::type::const_iterator const_iterator_t;
Expand Down

0 comments on commit c299e8a

Please sign in to comment.