### Boost Bimap Examples: step_by_step.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example Provides a step-by-step tutorial on using Boost.Bimap. This C++ code guides users through the process of creating and using bimaps incrementally. ```cpp // Content for step_by_step.cpp would go here. ``` -------------------------------- ### Boost Bimap Examples: mighty_bimap.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example Provides examples for using the 'mighty_bimap' feature in Boost.Bimap. This C++ code showcases advanced bimap functionalities. ```cpp // Content for mighty_bimap.cpp would go here. ``` -------------------------------- ### Basic Bimap Initialization and Insertion (C++) Source: https://www.boost.org/doc/libs/latest/libs/bimap/test/test_bimap_ordered Demonstrates the creation of a basic bimap with integer and double types, initializing it with sample data, and testing its functionality. This example uses standard map types for initial data setup. ```cpp #define _CRT_SECURE_NO_DEPRECATE #define _SCL_SECURE_NO_DEPRECATE #include #define BOOST_BIMAP_DISABLE_SERIALIZATION #include // std #include #include #include #include // Set type specifications #include #include // List type specification #include // bimap container #include #include "strong_type.hpp" #include "test_bimap.hpp" struct left_tag {}; struct right_tag {}; void test_bimap() { using namespace boost::bimaps; typedef std::map left_data_type; left_data_type left_data; left_data.insert( left_data_type::value_type(1,0.1) ); left_data.insert( left_data_type::value_type(2,0.2) ); left_data.insert( left_data_type::value_type(3,0.3) ); left_data.insert( left_data_type::value_type(4,0.4) ); typedef std::map right_data_type; right_data_type right_data; right_data.insert( right_data_type::value_type(0.1,1) ); right_data.insert( right_data_type::value_type(0.2,2) ); right_data.insert( right_data_type::value_type(0.3,3) ); right_data.insert( right_data_type::value_type(0.4,4) ); //-------------------------------------------------------------------- { typedef bimap< int, double > bm_type; std::set< bm_type::value_type > data; data.insert( bm_type::value_type(1,0.1) ); data.insert( bm_type::value_type(2,0.2) ); data.insert( bm_type::value_type(3,0.3) ); data.insert( bm_type::value_type(4,0.4) ); bm_type bm; test_set_set_bimap(bm,data,left_data,right_data); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- { typedef bimap < multiset_of< tagged >, multiset_of< tagged >, multiset_of_relation< std::less< _relation > > > bm_type; std::set< bm_type::value_type > data; data.insert( bm_type::value_type(1,0.1) ); data.insert( bm_type::value_type(2,0.2) ); data.insert( bm_type::value_type(3,0.3) ); data.insert( bm_type::value_type(4,0.4) ); bm_type bm; test_multiset_multiset_bimap(bm,data,left_data,right_data); test_tagged_bimap(bm,data); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- { typedef bimap bm_type; std::set< bm_type::value_type > data; data.insert( bm_type::value_type(1,0.1) ); data.insert( bm_type::value_type(2,0.2) ); data.insert( bm_type::value_type(3,0.3) ); data.insert( bm_type::value_type(4,0.4) ); bm_type bm; test_set_set_bimap(bm,data,left_data,right_data); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- { typedef bimap < multiset_of< int, std::greater >, set_of , multiset_of_relation< std::greater< _relation > > > bimap_type; bimap_type b1; b1.insert( bimap_type::value_type(1,"one") ); bimap_type b2( b1 ); BOOST_TEST( b1 == b2 ); BOOST_TEST( ! ( b1 != b2 ) ); BOOST_TEST( b1 <= b2 ); BOOST_TEST( b1 >= b2 ); BOOST_TEST( ! ( b1 < b2 ) ); BOOST_TEST( ! ( b1 > b2 ) ); b1.insert( bimap_type::value_type(2,"two") ); b2 = b1; BOOST_TEST( b2 == b1 ); b1.insert( bimap_type::value_type(3,"three") ); b2.left = b1.left; BOOST_TEST( b2 == b1 ); b1.insert( bimap_type::value_type(4,"four") ); b2.right = b1.right; BOOST_TEST( b2 == b1 ); b1.clear(); b2.swap(b1); BOOST_TEST( b2.empty() && !b1.empty() ); b1.left.swap( b2.left ); ``` -------------------------------- ### Boost Bimap: bimap_and_boost Integration Example Source: https://www.boost.org/doc/libs/latest/libs/bimap/example An example demonstrating the integration of Boost.Bimap with other Boost libraries. This C++ code showcases interoperability within the Boost ecosystem. ```cpp // Content for bimap_and_boost would go here. ``` -------------------------------- ### Boost.Bimap and Boost.PropertyMap Example Source: https://www.boost.org/doc/libs/latest/libs/bimap/example/bimap_and_boost/property_map Demonstrates how to use Boost.Bimap with Boost.PropertyMap, showing insertion of data and retrieval using the property map interface. This example requires the Boost library. ```cpp #define _CRT_SECURE_NO_DEPRECATE #define _SCL_SECURE_NO_DEPRECATE #include #include #include #include #include #include using namespace boost::bimaps; //[ code_bimap_and_boost_property_map template void foo(AddressMap & address_map) { typedef typename boost::property_traits::value_type value_type; typedef typename boost::property_traits::key_type key_type; value_type address; key_type fred = "Fred"; std::cout << boost::get(address_map, fred); } int main() { typedef bimap > Name2Address; typedef Name2Address::value_type location; Name2Address name2address; name2address.insert( location("Fred", "710 West 13th Street") ); name2address.insert( location( "Joe", "710 West 13th Street") ); foo( name2address.left ); return 0; } //] ``` -------------------------------- ### Boost Bimap Examples: tutorial_modify_and_replace.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example A tutorial on modifying and replacing elements within a Boost.Bimap. This C++ code provides practical examples of element manipulation. ```cpp // Content for tutorial_modify_and_replace.cpp would go here. ``` -------------------------------- ### Boost Bimap Examples: simple_bimap.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example Illustrates the basic usage of a simple bimap in Boost.Bimap. This C++ example serves as an introduction to creating and manipulating bimaps. ```cpp // Content for simple_bimap.cpp would go here. ``` -------------------------------- ### Boost Bimap Examples: tagged_simple_bimap.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example Demonstrates the use of tagged bimaps in Boost.Bimap. This C++ example shows how to associate tags with elements for more specific access and manipulation. ```cpp // Content for tagged_simple_bimap.cpp would go here. ``` -------------------------------- ### Boost Bimap Examples: population_bimap.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example Illustrates how to populate a bimap in Boost.Bimap. This C++ example likely covers methods for inserting key-value pairs into the bimap structure. ```cpp // Content for population_bimap.cpp would go here. ``` -------------------------------- ### Boost Bimap Examples: tutorial_range.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example Demonstrates how to use ranges with Boost.Bimap in a tutorial format. This C++ code illustrates iterating over subsets or specific parts of the bimap. ```cpp // Content for tutorial_range.cpp would go here. ``` -------------------------------- ### Boost Bimap: mi_to_b_path Example Source: https://www.boost.org/doc/libs/latest/libs/bimap/example An example related to 'mi_to_b_path' in the context of Boost.Bimap. The specific functionality is not detailed, but it is likely related to path manipulation or mapping within bimaps. ```cpp // Content for mi_to_b_path would go here. ``` -------------------------------- ### Boost Bimap Examples: at_function_examples.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example Demonstrates the usage of the 'at' function in Boost.Bimap, likely for accessing elements using keys. This example is written in C++ and requires the Boost library. ```cpp // Content for at_function_examples.cpp would go here. ``` -------------------------------- ### Boost Bimap Examples: tutorial_info_hook.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example Explains the concept of 'info hooks' in Boost.Bimap through a tutorial. This C++ code likely demonstrates how to use info hooks for custom element processing. ```cpp // Content for tutorial_info_hook.cpp would go here. ``` -------------------------------- ### Boost Bimap Examples: user_defined_names.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example Illustrates how to use user-defined names for bimap views or members in Boost.Bimap. This C++ example enhances code readability and organization. ```cpp // Content for user_defined_names.cpp would go here. ``` -------------------------------- ### Boost Bimap Examples: projection.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example Demonstrates bimap projection in Boost.Bimap. This C++ code shows how to create views or subsets of a bimap based on specific criteria. ```cpp // Content for projection.cpp would go here. ``` -------------------------------- ### C++ Tagged Bimap Example Source: https://www.boost.org/doc/libs/latest/libs/bimap/example/tagged_simple_bimap This example demonstrates how to use Boost.Bimap with tagged elements to create a map where data can be accessed using specific tags. It initializes a bimap to store country names and their ranks, then iterates through the bimap sorted by rank and then by country name. Dependencies include the Boost.Bimap library and standard C++ libraries for input/output. ```cpp #define _CRT_SECURE_NO_DEPRECATE #define _SCL_SECURE_NO_DEPRECATE #include #include struct country {}; struct place {}; int main() { using namespace boost::bimaps; // Soccer World cup. typedef bimap < tagged< std::string, country >, tagged< int , place > > results_bimap; typedef results_bimap::value_type position; results_bimap results; results.insert( position("Argentina" ,1) ); results.insert( position("Spain" ,2) ); results.insert( position("Germany" ,3) ); results.insert( position("France" ,4) ); std::cout << "Countries names ordered by their final position:" << std::endl; /*<< `results.by()` is equivalent to `results.right` >>*/ for( results_bimap::map_by::const_iterator i = results.by().begin(), iend = results.by().end() ; i != iend; ++i ) { /*<< `get` works for each view of the bimap >>*/ std::cout << i->get() << ") " << i->get() << std::endl; } std::cout << std::endl << "Countries names ordered alfabetically along with" "their final position:" << std::endl; /*<< `results.by()` is equivalent to `results.left` >>*/ for( results_bimap::map_by::const_iterator i = results.by().begin(), iend = results.by().end() ; i != iend; ++i ) { std::cout << i->get() << " ends " << i->get() << "º" << std::endl; } return 0; } ``` -------------------------------- ### Main function to run Boost.Bimap serialization test Source: https://www.boost.org/doc/libs/latest/libs/bimap/test/test_bimap_serialization The main function that executes the `test_bimap_serialization` function and reports any errors encountered during the test. This is the entry point for the program. ```cpp #define _CRT_SECURE_NO_DEPRECATE #define _SCL_SECURE_NO_DEPRECATE #include // std #include #include #include #include #include #include #include #include // Boost #include #include // Boost.Bimap #include int main() { test_bimap_serialization(); return boost::report_errors(); } ``` -------------------------------- ### Boost Bimap Soccer Tournament Rankings Example Source: https://www.boost.org/doc/libs/latest/libs/bimap/doc/html/boost_bimap/one_minute_tutorial Complete example demonstrating bimap usage with a soccer tournament dataset. Shows how to insert bidirectional mappings between country names and positions, access data through both left (string-to-int) and right (int-to-string) views, and print sorted results using the generic print_map template function. ```cpp #include #include #include int main() { // Soccer World cup typedef boost::bimap< std::string, int > results_bimap; typedef results_bimap::value_type position; results_bimap results; results.insert( position("Argentina" ,1) ); results.insert( position("Spain" ,2) ); results.insert( position("Germany" ,3) ); results.insert( position("France" ,4) ); std::cout << "The number of countries is " << results.size() << std::endl; std::cout << "The winner is " << results.right.at(1) << std::endl << std::endl; std::cout << "Countries names ordered by their final position:" << std::endl; // results.right works like a std::map< int, std::string > print_map( results.right, ") ", std::cout ); std::cout << std::endl << "Countries names ordered alphabetically along with" "their final position:" << std::endl; // results.left works like a std::map< std::string, int > print_map( results.left, " ends in position ", std::cout ); return 0; } ``` -------------------------------- ### Boost Bimap Examples: standard_map_comparison.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example Compares the performance and functionality of Boost.Bimap with standard C++ maps. This C++ code highlights the advantages of using bimaps in certain scenarios. ```cpp // Content for standard_map_comparison.cpp would go here. ``` -------------------------------- ### Simple Bimap Usage Example in C++ Source: https://www.boost.org/doc/libs/latest/libs/bimap/example/simple_bimap Demonstrates the creation and usage of a simple bidirectional map (bimap) using Boost.Bimap. This example shows how to insert elements, retrieve elements by key from both directions, and iterate over the map's contents. It utilizes `std::string` for keys and `int` for values. ```cpp #define _CRT_SECURE_NO_DEPRECATE #define _SCL_SECURE_NO_DEPRECATE #include #include #include template< class MapType > void print_map(const MapType & map, const std::string & separator, std::ostream & os ) { typedef typename MapType::const_iterator const_iterator; for( const_iterator i = map.begin(), iend = map.end(); i != iend; ++i ) { os << i->first << separator << i->second << std::endl; } } int main() { // Soccer World cup typedef boost::bimap< std::string, int > results_bimap; typedef results_bimap::value_type position; results_bimap results; results.insert( position("Argentina" ,1) ); results.insert( position("Spain" ,2) ); results.insert( position("Germany" ,3) ); results.insert( position("France" ,4) ); std::cout << "The number of countries is " << results.size() << std::endl; std::cout << "The winner is " << results.right.at(1) << std::endl << std::endl; std::cout << "Countries names ordered by their final position:" << std::endl; // results.right works like a std::map< int, std::string > print_map( results.right, ") ", std::cout ); std::cout << std::endl << "Countries names ordered alphabetically along with" "their final position:" << std::endl; // results.left works like a std::map< std::string, int > print_map( results.left, " ends in position ", std::cout ); return 0; } ``` -------------------------------- ### Boost Bimap: Tagged Usage for Readability in C++ Source: https://www.boost.org/doc/libs/latest/libs/bimap/doc/html/boost_bimap/examples/simple_bimap This C++ code showcases Boost.Bimap with tagged types, enhancing the readability of bidirectional maps. It defines custom tags 'country' and 'place' for the string and integer types, respectively. The example demonstrates accessing map views and elements using tags, providing a more semantic way to interact with the bimap. It requires the Boost.Bimap header and the use of Boost.Bimap's namespace. ```cpp #include #include struct country {}; struct place {}; int main() { using namespace boost::bimaps; // Soccer World cup. typedef bimap < tagged< std::string, country >, tagged< int , place > > results_bimap; typedef results_bimap::value_type position; results_bimap results; results.insert( position("Argentina" ,1) ); results.insert( position("Spain" ,2) ); results.insert( position("Germany" ,3) ); results.insert( position("France" ,4) ); std::cout << "Countries names ordered by their final position:" << std::endl; for( results_bimap::map_by::const_iterator i = results.by().begin(), iend = results.by().end() ; i != iend; ++i ) { std::cout << i->get() << ") " << i->get() << std::endl; } std::cout << std::endl << "Countries names ordered alfabetically along with" "their final position:" << std::endl; for( results_bimap::map_by::const_iterator i = results.by().begin(), iend = results.by().end() ; i != iend; ++i ) { std::cout << i->get() << " ends " << i->get() << "º" << std::endl; } return 0; } ``` -------------------------------- ### Boost.Bimap Translator Example in C++ Source: https://www.boost.org/doc/libs/latest/libs/bimap/example/mighty_bimap This C++ code snippet demonstrates how to use Boost.Bimap to create a bidirectional map for translating words between Spanish and English. It defines a `bimap` with tagged `unordered_set_of` for Spanish and English strings, and a `list_of_relation` to allow iteration. The example shows how to add translations, search for words from either language, and display all available translations if a word is not found. It requires the Boost C++ Libraries. ```cpp #define _CRT_SECURE_NO_DEPRECATE #define _SCL_SECURE_NO_DEPRECATE #include #include #include #include #include struct english {}; struct spanish {}; int main() { using namespace boost::bimaps; typedef bimap < unordered_set_of< tagged< std::string, spanish > >, unordered_set_of< tagged< std::string, english > >, list_of_relation > translator; translator trans; trans.push_back( translator::value_type("hola" ,"hello" ) ); trans.push_back( translator::value_type("adios" ,"goodbye" ) ); trans.push_back( translator::value_type("rosa" ,"rose" ) ); trans.push_back( translator::value_type("mesa" ,"table" ) ); std::cout << "enter a word" << std::endl; std::string word; std::getline(std::cin,word); translator::map_by::const_iterator is = trans.by().find(word); if( is != trans.by().end() ) { std::cout << word << " is said " << is->get() << " in English" << std::endl; } else { translator::map_by::const_iterator ie = trans.by().find(word); if( ie != trans.by().end() ) { std::cout << word << " is said " << ie->get() << " in Spanish" << std::endl; } else { std::cout << "No such word in the dictionary" << std::endl; std::cout << "These are the possible translations" << std::endl; for( translator::const_iterator i = trans.begin(), i_end = trans.end(); i != i_end ; ++i ) { std::cout << i->get() << " <---> " << i->get() << std::endl; } } } return 0; } ``` -------------------------------- ### Word Frequency Counter using Boost.Bimap Source: https://www.boost.org/doc/libs/latest/libs/bimap/doc/html/boost_bimap/examples/multiindex_to_bimap_path___hashed_indices Creates a bidirectional map container using Boost.Bimap with multiset_of and unordered_set_of to efficiently track word occurrences and enable lookups by frequency or word string. The example tokenizes text input, counts word appearances, and outputs statistics sorted by occurrence percentage. Requires Boost.Tokenizer for text parsing and supports bidirectional iteration through both occurrence count and word string views. ```cpp #include #include #include #include #include #include #include using namespace boost::bimaps; struct word {}; struct occurrences {}; typedef bimap < multiset_of< tagged, std::greater >, unordered_set_of< tagged< std::string, word> > > word_counter; typedef boost::tokenizer > text_tokenizer; int main() { std::string text= "Relations between data in the STL are represented with maps." "A map is a directed relation, by using it you are representing " "a mapping. In this directed relation, the first type is related to " "the second type but it is not true that the inverse relationship " "holds. This is useful in a lot of situations, but there are some " "relationships that are bidirectional by nature."; // feed the text into the container word_counter wc; text_tokenizer tok(text,boost::char_separator(" \t\n.,;:!?'\"\-")); unsigned int total_occurrences = 0; for( text_tokenizer::const_iterator it = tok.begin(), it_end = tok.end(); it != it_end ; ++it ) { ++total_occurrences; word_counter::map_by::iterator wit = wc.by().insert( word_counter::map_by::value_type(0,*it) ).first; wc.by().modify_key( wit, ++_key); } // list words by frequency of appearance std::cout << std::fixed << std::setprecision(2); for( word_counter::map_by::const_iterator wit = wc.by().begin(), wit_end = wc.by().end(); wit != wit_end; ++wit ) { std::cout << std::setw(15) << wit->get() << ": " << std::setw(5) << 100.0 * wit->get() / total_occurrences << "%" << std::endl; } return 0; } ``` -------------------------------- ### Boost.Bimap: Unconstrained Set of Relation Examples Source: https://www.boost.org/doc/libs/latest/libs/bimap/test/test_bimap_unconstrained Demonstrates the creation and usage of Boost.Bimap with `unconstrained_set_of_relation`. It covers various scenarios including different key types and relation types, insertion of elements, and verification of bimap size. This code requires the Boost library. ```cpp #define _CRT_SECURE_NO_DEPRECATE #define _SCL_SECURE_NO_DEPRECATE #include #include // Boost.Bimap #include #include void test_bimap_unconstrained() { using namespace boost::bimaps; { typedef bimap bm; bm b; b.left.insert( bm::left_value_type(2,34.4) ); b.right.insert( bm::right_value_type(2.2,3) ); } { typedef bimap > bm; bm b; b.insert( bm::value_type(2,34.4) ); BOOST_TEST( b.size() == 1 ); } { typedef bimap, double > bm; bm b; b.right[2.4] = 34; BOOST_TEST( b.right.size() == 1 ); } { typedef bimap, double, right_based > bm; bm b; b.right[2.4] = 34; BOOST_TEST( b.right.size() == 1 ); } { typedef bimap < int, unconstrained_set_of, unconstrained_set_of_relation > bm; bm b; b.left[2] = 34.4; BOOST_TEST( b.left.size() == 1 ); } { typedef bimap < unconstrained_set_of, double, unconstrained_set_of_relation > bm; bm b; b.right[2.4] = 34; BOOST_TEST( b.right.size() == 1 ); } { typedef bimap < unconstrained_set_of, unconstrained_set_of, set_of_relation<> > bm; bm b; b.insert( bm::value_type(1,2.3) ); BOOST_TEST( b.size() == 1 ); } } int main() { test_bimap_unconstrained(); return boost::report_errors(); } ``` -------------------------------- ### Parsing File Relations into Bimap with Boost.Xpressive Source: https://www.boost.org/doc/libs/latest/libs/bimap/doc/html/boost_bimap/bimap_and_boost/boost_libraries_that_work_well_with_boost_bimap Illustrates how Boost.Xpressive can parse a string containing relations and populate a bimap in a concise manner. This example defines regular expressions to match and extract string-integer pairs, constructing bimap value types directly. ```cpp #include #include #include #include #include using namespace boost::xpressive; int main() { typedef bimap< std::string, int > bm_type; bm_type bm; std::string rel_str("one <--> 1 two <--> 2 three <--> 3"); sregex rel = ( (s1= +_w) >> " <--> " >> (s2= +_d) ) [ xp::ref(bm)->*insert( xp::construct(s1, as(s2)) ) ]; sregex relations = rel >> *(+_s >> rel); regex_match(rel_str, relations); assert( bm.size() == 3 ); // Optional: Print the bimap contents to verify for (auto const& pair : bm) { std::cout << pair.first << " <--> " << pair.second << std::endl; } return 0; } ``` -------------------------------- ### Basic Boost.Bimap Set Initialization Source: https://www.boost.org/doc/libs/latest/libs/bimap/test/test_bimap_set_of Demonstrates the basic initialization of set types within Boost.Bimap. It includes necessary includes and uses boost::ignore_unused to suppress compiler warnings for unused type definitions. This is a foundational example for using bimap's set-based structures. ```cpp #include #include #include int main() { typedef boost::bimaps::set_of set_type; typedef boost::bimaps::set_of_relation<> set_type_of_relation; boost::ignore_unused(); boost::ignore_unused(); return 0; } ``` -------------------------------- ### Using Boost.Property_map with Boost.Bimap Source: https://www.boost.org/doc/libs/latest/libs/bimap/doc/html/boost_bimap/bimap_and_boost/boost_libraries_that_work_well_with_boost_bimap Shows how Boost.Bimap can be used with the Boost.Property_map library. This example demonstrates accessing bimap elements as property maps, utilizing `boost::get` to retrieve values associated with keys. ```cpp #include #include #include #include #include // Forward declaration of the function using property map template void foo(AddressMap & address_map); int main() { // Define a bimap where keys are strings (names) and values are multisets of strings (addresses) typedef bimap > Name2Address; typedef Name2Address::value_type location; Name2Address name2address; name2address.insert( location("Fred", "710 West 13th Street") ); name2address.insert( location( "Joe", "710 West 13th Street") ); // Use the left view of the bimap as a property map foo( name2address.left ); return 0; } // Function that utilizes the property map interface template void foo(AddressMap & address_map) { // Deduce the value type and key type from the AddressMap typedef typename boost::property_traits::value_type value_type; typedef typename boost::property_traits::key_type key_type; value_type address; key_type fred = "Fred"; // Use boost::get to retrieve the value associated with the key "Fred" std::cout << "Address for Fred: " << boost::get(address_map, fred) << std::endl; } ``` -------------------------------- ### Usage Example of MultiIndex-based Property Tree Source: https://www.boost.org/doc/libs/latest/libs/bimap/doc/html/boost_bimap/history/multiindex_and_bimap This C++ snippet shows how to use the Boost.MultiIndex-based property tree implementation. It involves loading data from a file using Boost.Serialization and then accessing a value using a string key path. ```C++ ptree_gen::type PT; boost::archive::text_iarchive ia( std::ifstream ifs("filename") ); ia >> PT; string value = get( "a.b.c.d", PT ); ``` -------------------------------- ### Boost.Bimap Basic Usage with Integers Source: https://www.boost.org/doc/libs/latest/libs/bimap/test/compile_fail/test_bimap_info_3 Demonstrates the basic usage of Boost.Bimap with integer keys. It shows how to define a bimap with an integer left key and a list of integers as the right key, and how to insert a value into the bimap. This example is intended for educational purposes to illustrate bimap construction and insertion. ```cpp #define _CRT_SECURE_NO_DEPRECATE #define _SCL_SECURE_NO_DEPRECATE #include // Boost.Bimap #include #include void test_bimap_info_3() { using namespace boost::bimaps; typedef bimap< int, list_of > bm_type; bm_type bm; bm.insert( bm_type::value_type(1,1) ); // fail test { bm.left.info_at(1); } } ``` -------------------------------- ### Boost Bimap Unordered Set Initialization Source: https://www.boost.org/doc/libs/latest/libs/bimap/test/test_bimap_unordered_set_of Demonstrates the initialization of unordered set types within Boost.Bimap. This example shows how to define and use `unordered_set_of` and `unordered_set_of_relation` types. It includes necessary Boost headers and a basic `main` function. ```cpp #include #include #include int main() { typedef boost::bimaps::unordered_set_of set_type; typedef boost::bimaps::unordered_set_of_relation<> set_type_of_relation; boost::ignore_unused(); boost::ignore_unused(); return 0; } ``` -------------------------------- ### Boost.Bimap with Info Hook Example Source: https://www.boost.org/doc/libs/latest/libs/bimap/example/tutorial_info_hook Demonstrates the creation and usage of a bimap with an associated 'info' hook for storing additional data (abstract in this case). It shows insertion, retrieval of values, modification of info, and using info_at for direct info access. Requires Boost.Bimap and standard C++ libraries. ```cpp #define _CRT_SECURE_NO_DEPRECATE #define _SCL_SECURE_NO_DEPRECATE #include #include #include #include #include using namespace boost::bimaps; void tutorial_about_info_hook() { //[ code_tutorial_info_hook_first typedef bimap< multiset_of< std::string >, // author set_of< std::string >, // title with_info< std::string > // abstract > bm_type; typedef bm_type::value_type book; bm_type bm; bm.insert( book( "Bjarne Stroustrup" , "The C++ Programming Language", "For C++ old-timers, the first edition of this book is" "the one that started it all—the font of our knowledge." ) ); // Print the author of the bible std::cout << bm.right.at("The C++ Programming Language"); // Print the abstract of this book bm_type::left_iterator i = bm.left.find("Bjarne Stroustrup"); std::cout << i->info; //] // Contrary to the two key types, the information will be mutable // using iterators. //[ code_tutorial_info_hook_mutable i->info += "More details about this book"; //] // A new function is included in unique map views: info_at(key), that // mimics the standard at(key) function but returned the associated // information instead of the data. //[ code_tutorial_info_hook_info_at // Print the new abstract std::cout << bm.right.info_at("The C++ Programming Language"); //] } ``` -------------------------------- ### Initialize Bimap with Boost.Assign Source: https://www.boost.org/doc/libs/latest/libs/bimap/doc/html/boost_bimap/bimap_and_boost/boost_libraries_that_work_well_with_boost_bimap Demonstrates using Boost.Assign's list_of, insert, push_back, and push_front operators to populate a bimap with multiset and list views. The example shows initializing containers through the main view and individual map views, with special attention to using bm_type::relation instead of bm_type::value_type for proper element handling. ```C++ typedef bimap< multiset_of< int >, list_of< std::string > > bm_type; // We can use assign::list_of to initialize the container. bm_type bm = assign::list_of< bm_type::relation > ( 1, "one" ) ( 2, "two" ) ( 3, "three" ); // The left map view is a multiset, again we use insert assign::insert( bm.left ) ( 4, "four" ) ( 5, "five" ) ( 6, "six" ); // The right map view is a list so we use push_back here // Note the order of the elements in the list! assign::push_back( bm.right ) ( "seven" , 7 ) ( "eight" , 8 ); assign::push_front( bm.right ) ( "nine" , 9 ) ( "ten" , 10 ) ( "eleven", 11 ); // Since it is left_based the main view is a multiset, so we use insert assign::insert( bm ) ( 12, "twelve" ) ( 13, "thirteen" ); ``` -------------------------------- ### Define and Initialize Boost.Bimap Source: https://www.boost.org/doc/libs/latest/libs/bimap/example/step_by_step Demonstrates how to define a bimap with integer keys and string values, and how to initialize it. ```cpp #define _CRT_SECURE_NO_DEPRECATE #define _SCL_SECURE_NO_DEPRECATE #include #include #include #include int main() { typedef boost::bimap< int, std::string > bm_type; bm_type bm; ``` -------------------------------- ### Including Property Map Support Headers for Boost.Bimap Source: https://www.boost.org/doc/libs/latest/libs/bimap/doc/html/boost_bimap/bimap_and_boost/boost_libraries_that_work_well_with_boost_bimap Lists the necessary header files to include when using Boost.Bimap with property map support, specifically for `set` and `unordered_set` views. ```cpp #include #include ``` -------------------------------- ### Boost Bimap Examples: unconstrained_collection.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example Shows examples of using unconstrained collections with Boost.Bimap. This C++ code likely deals with bimap variants that do not enforce uniqueness constraints on keys. ```cpp // Content for unconstrained_collection.cpp would go here. ``` -------------------------------- ### Boost Bimap Examples: repetitions_counter.cpp Source: https://www.boost.org/doc/libs/latest/libs/bimap/example Contains C++ code for counting repetitions using Boost.Bimap. This example likely utilizes bimap's properties to efficiently track occurrences of elements. ```cpp // Content for repetitions_counter.cpp would go here. ``` -------------------------------- ### Boost.Bimap Test Suite Main Entry Point in C++ Source: https://www.boost.org/doc/libs/latest/libs/bimap/test/test_bimap_info Main function orchestrating all Boost.Bimap info functionality tests. Executes three test cases covering basic info operations, tagged type access, and heterogeneous lookups, returning aggregated test results using boost::report_errors(). ```cpp int main() { test_bimap_info(); test_tagged_bimap_info(); test_heterogeneous_access_bimap_info(); return boost::report_errors(); } ``` -------------------------------- ### Initialize and Suppress Unused Variable Warnings in C++ Source: https://www.boost.org/doc/libs/latest/libs/bimap/test/test_bimap_unordered_multiset_of Uses boost::ignore_unused() utility to explicitly mark type definitions as intentionally unused, preventing compiler warnings about unused variables. This pattern is useful in example code and template instantiation tests. ```cpp boost::ignore_unused(); boost::ignore_unused(); ``` -------------------------------- ### Untagged Bimap with Multiset Keys in C++ Source: https://www.boost.org/doc/libs/latest/libs/bimap/example/user_defined_names Demonstrates creating and using an untagged bimap where keys are of type std::string (multiset) and int. It shows how to find elements by their integer ID and iterate through the map by name. This example requires the Boost.Bimap library. ```cpp #define _CRT_SECURE_NO_DEPRECATE #define _SCL_SECURE_NO_DEPRECATE #include #include #include #include #include using namespace boost::bimaps; void untagged_version() { //[ code_user_defined_names_untagged_version typedef bimap < multiset_of, int > People; People people; // ... int user_id; std::cin >> user_id; // people.right : map People::right_const_iterator id_iter = people.right.find(user_id); if( id_iter != people.right.end() ) { // first : id // second : name std::cout << "name: " << id_iter->second << std::endl << "id: " << id_iter->first << std::endl; } else { std::cout << "Unknown id, users are:" << std::endl; // people.left : map for( People::left_const_iterator name_iter = people.left.begin(), iend = people.left.end(); name_iter != iend; ++name_iter ) { // first : name // second : id std::cout << "name: " << name_iter->first << std::endl << "id: " << name_iter->second << std::endl; } } //] } ``` -------------------------------- ### Boost.Bimap Mutable Operations Example in C++ Source: https://www.boost.org/doc/libs/latest/libs/bimap/test/compile_fail/test_bimap_mutable_2 This C++ code snippet demonstrates how to perform mutable operations on a Boost.Bimap. It defines a bimap with integer keys and lists of integers as values, inserts an initial element, and then attempts to modify an existing element via a const reference to the bimap's left view. This showcases how elements can be updated after insertion. ```cpp #define _CRT_SECURE_NO_DEPRECATE #define _SCL_SECURE_NO_DEPRECATE #include // Boost.Bimap #include #include void test_bimap_mutable_2() { using namespace boost::bimaps; typedef bimap< int, list_of > bm_type; bm_type bm; bm.insert( bm_type::value_type(1,1) ); // fail test { const bm_type & cbm = bm; cbm.left.find(1)->second = 10; } } ``` -------------------------------- ### Boost.Bimap with Tagged Info Hook Example Source: https://www.boost.org/doc/libs/latest/libs/bimap/example/tutorial_info_hook Illustrates using tagged info hooks in a bimap, which allows for explicitly named data associated with keys. This provides better code readability and maintainability. It covers insertion, accessing elements by tag, modifying tagged info, and using info_at with tags. Dependencies include Boost.Bimap and standard C++ libraries. ```cpp struct author {}; struct title {}; struct abstract {}; void tutorial_about_tagged_info_hook() { //[ code_tutorial_info_hook_tagged_info typedef bimap< multiset_of< tagged< std::string, author > >, set_of< tagged< std::string, title > >, with_info< tagged< std::string, abstract > > > bm_type; typedef bm_type::value_type book; bm_type bm; bm.insert( book( "Bjarne Stroustrup" , "The C++ Programming Language", "For C++ old-timers, the first edition of this book is" "the one that started it all—the font of our knowledge." ) ); // Print the author of the bible std::cout << bm.by().at("The C++ Programming Language"); // Print the abstract of this book bm_type::map_by<author>::iterator i = bm.by<author>().find("Bjarne Stroustrup"); std::cout << i->get<abstract>(); // Contrary to the two key types, the information will be mutable // using iterators. i->get<abstract>() += "More details about this book"; // Print the new abstract std::cout << bm.by<title>().info_at("The C++ Programming Language"); //] } ```