diff options
Diffstat (limited to 'src/boost/libs/bimap')
66 files changed, 6693 insertions, 0 deletions
diff --git a/src/boost/libs/bimap/CMakeLists.txt b/src/boost/libs/bimap/CMakeLists.txt new file mode 100644 index 000000000..8fbf45eee --- /dev/null +++ b/src/boost/libs/bimap/CMakeLists.txt @@ -0,0 +1,38 @@ +# Generated by `boostdep --cmake bimap` +# Copyright 2020 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# https://www.boost.org/LICENSE_1_0.txt + +cmake_minimum_required(VERSION 3.5...3.16) + +project(boost_bimap VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) + +add_library(boost_bimap INTERFACE) +add_library(Boost::bimap ALIAS boost_bimap) + +target_include_directories(boost_bimap INTERFACE include) + +target_link_libraries(boost_bimap + INTERFACE + Boost::concept_check + Boost::config + Boost::container_hash + Boost::core + Boost::iterator + Boost::lambda + Boost::mpl + Boost::multi_index + Boost::preprocessor + Boost::serialization + Boost::static_assert + Boost::throw_exception + Boost::type_traits + Boost::utility +) + +if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") + + add_subdirectory(test) + +endif() + diff --git a/src/boost/libs/bimap/example/Jamfile.v2 b/src/boost/libs/bimap/example/Jamfile.v2 new file mode 100644 index 000000000..424162943 --- /dev/null +++ b/src/boost/libs/bimap/example/Jamfile.v2 @@ -0,0 +1,50 @@ +# Boost.Bimap +# +# Copyright (c) 2006-2007 Matias Capeletto +# +# 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) + +# bring in rules for testing +import testing ; + +test-suite "examples" + : + [ compile mighty_bimap.cpp ] + [ run simple_bimap.cpp ] + [ run tagged_simple_bimap.cpp ] + [ run step_by_step.cpp ] + [ run population_bimap.cpp ] + [ run repetitions_counter.cpp ] + [ compile user_defined_names.cpp ] + [ run standard_map_comparison.cpp ] + [ run at_function_examples.cpp ] + [ run tutorial_modify_and_replace.cpp ] + [ run tutorial_range.cpp ] + [ run unconstrained_collection.cpp ] + [ run tutorial_info_hook.cpp ] + [ run projection.cpp ] + ; + +test-suite "bimap_and_boost" + : + [ run bimap_and_boost/property_map.cpp ] + [ run bimap_and_boost/range.cpp ] + [ run bimap_and_boost/foreach.cpp ] + [ run bimap_and_boost/lambda.cpp ] + [ run bimap_and_boost/assign.cpp ] + [ run bimap_and_boost/xpressive.cpp ] + [ run bimap_and_boost/typeof.cpp ] + [ run bimap_and_boost/serialization.cpp + /boost/serialization//boost_serialization ] + ; + +test-suite "mi_to_b_path" + : + [ compile mi_to_b_path/bidirectional_map.cpp ] + [ run mi_to_b_path/hashed_indices.cpp ] + [ compile mi_to_b_path/tagged_bidirectional_map.cpp ] + [ compile mi_to_b_path/mi_bidirectional_map.cpp ] + [ run mi_to_b_path/mi_hashed_indices.cpp ] + ; diff --git a/src/boost/libs/bimap/example/at_function_examples.cpp b/src/boost/libs/bimap/example/at_function_examples.cpp new file mode 100644 index 000000000..04f11113b --- /dev/null +++ b/src/boost/libs/bimap/example/at_function_examples.cpp @@ -0,0 +1,97 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <string> +#include <iostream> +#include <cassert> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/unordered_set_of.hpp> +#include <boost/bimap/list_of.hpp> +#include <boost/bimap/multiset_of.hpp> + +using namespace boost::bimaps; + +void first_bimap() +{ + //[ code_at_function_first + + typedef bimap< set_of< std::string >, list_of< int > > bm_type; + bm_type bm; + + try + { + bm.left.at("one") = 1; // throws std::out_of_range + } + catch( std::out_of_range & e ) {} + + assert( bm.empty() ); + + bm.left["one"] = 1; // Ok + + assert( bm.left.at("one") == 1 ); // Ok + //] +} + +void second_bimap() +{ + //[ code_at_function_second + + typedef bimap< multiset_of<std::string>, unordered_set_of<int> > bm_type; + bm_type bm; + + //<- + /* + //-> + bm.right[1] = "one"; // compilation error + //<- + */ + //-> + + bm.right.insert( bm_type::right_value_type(1,"one") ); + + assert( bm.right.at(1) == "one" ); // Ok + + try + { + std::cout << bm.right.at(2); // throws std::out_of_range + } + catch( std::out_of_range & e ) {} + + //<- + /* + //-> + bm.right.at(1) = "1"; // compilation error + //<- + */ + //-> + + //] +} + +int main() +{ + first_bimap(); + second_bimap(); + return 0; +} + diff --git a/src/boost/libs/bimap/example/bimap_and_boost/assign.cpp b/src/boost/libs/bimap/example/bimap_and_boost/assign.cpp new file mode 100644 index 000000000..841c63532 --- /dev/null +++ b/src/boost/libs/bimap/example/bimap_and_boost/assign.cpp @@ -0,0 +1,79 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <string> + +#include <boost/assign/list_of.hpp> +#include <boost/assign/list_inserter.hpp> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/multiset_of.hpp> +#include <boost/bimap/list_of.hpp> + +using namespace boost::bimaps; +using namespace boost; + + +int main() +{ + //[ code_bimap_and_boost_assign + + 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 > /*< + Note that `bm_type::relation` has to be used instead of `bm_type::value_type`. + Contrary to `value_type`, `relation` type stores the elements as non const, a + requirement of `assign::list_of` >*/ + ( 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" ); + //] + + return 0; +} diff --git a/src/boost/libs/bimap/example/bimap_and_boost/foreach.cpp b/src/boost/libs/bimap/example/bimap_and_boost/foreach.cpp new file mode 100644 index 000000000..a1d344112 --- /dev/null +++ b/src/boost/libs/bimap/example/bimap_and_boost/foreach.cpp @@ -0,0 +1,106 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <string> +#include <iostream> + +#include <boost/foreach.hpp> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/list_of.hpp> +#include <boost/bimap/support/lambda.hpp> + +using namespace boost::bimaps; + + +int main() +{ + //[ code_bimap_and_boost_foreach + + typedef bimap< std::string, list_of<int> > bm_type; + + bm_type bm; + bm.insert( bm_type::value_type("1", 1) ); + bm.insert( bm_type::value_type("2", 2) ); + bm.insert( bm_type::value_type("3", 4) ); + bm.insert( bm_type::value_type("4", 2) ); + + BOOST_FOREACH( bm_type::left_reference p, bm.left ) + { + ++p.second; /*< We can modify the right element because we have + use a mutable collection type in the right side. >*/ + } + + BOOST_FOREACH( bm_type::right_const_reference p, bm.right ) + { + std::cout << p.first << "-->" << p.second << std::endl; + } + + //] + + // More examples + + BOOST_FOREACH( bm_type::right_reference p, bm.right ) + { + ++p.first; + } + + BOOST_FOREACH( bm_type::left_const_reference p, bm.left ) + { + std::cout << p.first << "-->" << p.second << std::endl; + } + + BOOST_FOREACH( bm_type::reference p, bm ) + { + ++p.right; + } + + const bm_type & cbm = bm; + BOOST_FOREACH( bm_type::const_reference p, cbm ) + { + std::cout << p.left << "-->" << p.right << std::endl; + } + + BOOST_FOREACH( bm_type::const_reference p, bm ) + { + std::cout << p.left << "-->" << p.right << std::endl; + } + + //[ code_bimap_and_boost_foreach_using_range + + BOOST_FOREACH( bm_type::left_reference p, + ( bm.left.range( std::string("1") <= _key, _key < std::string("3") ) )) + { + ++p.second; + } + + BOOST_FOREACH( bm_type::left_const_reference p, + ( bm.left.range( std::string("1") <= _key, _key < std::string("3") ) )) + { + std::cout << p.first << "-->" << p.second << std::endl; + } + //] + + return 0; +} + + diff --git a/src/boost/libs/bimap/example/bimap_and_boost/lambda.cpp b/src/boost/libs/bimap/example/bimap_and_boost/lambda.cpp new file mode 100644 index 000000000..cd7ce8519 --- /dev/null +++ b/src/boost/libs/bimap/example/bimap_and_boost/lambda.cpp @@ -0,0 +1,49 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <string> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/support/lambda.hpp> + +using namespace boost::bimaps; + +int main() +{ + //[ code_bimap_and_boost_lambda + + typedef bimap< std::string, int > bm_type; + + bm_type bm; + bm.insert( bm_type::value_type("one",1) ); + bm.insert( bm_type::value_type("two",2) ); + + bm.right.range( 5 < _key, _key < 10 ); + + bm.left.modify_key( bm.left.find("one"), _key = "1" ); + + bm.left.modify_data( bm.left.begin(), _data *= 10 ); + //] + return 0; +} + + diff --git a/src/boost/libs/bimap/example/bimap_and_boost/property_map.cpp b/src/boost/libs/bimap/example/bimap_and_boost/property_map.cpp new file mode 100644 index 000000000..aa082781e --- /dev/null +++ b/src/boost/libs/bimap/example/bimap_and_boost/property_map.cpp @@ -0,0 +1,59 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <iostream> +#include <string> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/multiset_of.hpp> +#include <boost/bimap/property_map/set_support.hpp> + +using namespace boost::bimaps; + +//[ code_bimap_and_boost_property_map + +template <typename AddressMap> +void foo(AddressMap & address_map) +{ + typedef typename boost::property_traits<AddressMap>::value_type value_type; + typedef typename boost::property_traits<AddressMap>::key_type key_type; + + value_type address; + key_type fred = "Fred"; + std::cout << boost::get(address_map, fred); +} + +int main() +{ + typedef bimap<std::string, multiset_of<std::string> > 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; +} +//] + diff --git a/src/boost/libs/bimap/example/bimap_and_boost/range.cpp b/src/boost/libs/bimap/example/bimap_and_boost/range.cpp new file mode 100644 index 000000000..046c8686f --- /dev/null +++ b/src/boost/libs/bimap/example/bimap_and_boost/range.cpp @@ -0,0 +1,121 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <iostream> + +#include <boost/range/functions.hpp> +#include <boost/range/metafunctions.hpp> + +//[ code_bimap_and_boost_range_functions + +template< class ForwardReadableRange, class UnaryFunctor > +UnaryFunctor for_each(const ForwardReadableRange & r, UnaryFunctor func) +{ + typedef typename + boost::range_const_iterator<ForwardReadableRange>::type const_iterator; + + for(const_iterator i= boost::begin(r), iend= boost::end(r); i!=iend; ++i ) + { + func(*i); + } + + return func; +} + +template< class ForwardReadableRange, class Predicate > +typename boost::range_difference<ForwardReadableRange>::type + count_if(const ForwardReadableRange & r, Predicate pred) +{ + typedef typename + boost::range_const_iterator<ForwardReadableRange>::type const_iterator; + + typename boost::range_difference<ForwardReadableRange>::type c = 0; + + for( const_iterator i = boost::begin(r), iend = boost::end(r); i != iend; ++i ) + { + if( pred(*i) ) ++c; + } + + return c; +} +//] + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/multiset_of.hpp> +#include <boost/bimap/support/lambda.hpp> +#include <boost/bind.hpp> + +using namespace boost::bimaps; +using namespace boost; + +//[ code_bimap_and_boost_range + +struct pair_printer +{ + pair_printer(std::ostream & o) : os(o) {} + template< class Pair > + void operator()(const Pair & p) + { + os << "(" << p.first << "," << p.second << ")"; + } + private: + std::ostream & os; +}; + +struct second_extractor +{ + template< class Pair > + const typename Pair::second_type & operator()(const Pair & p) + { + return p.second; + } +}; + +int main() +{ + typedef bimap< double, multiset_of<int> > bm_type; + + bm_type bm; + bm.insert( bm_type::value_type(2.5 , 1) ); + bm.insert( bm_type::value_type(3.1 , 2) ); + //... + bm.insert( bm_type::value_type(6.4 , 4) ); + bm.insert( bm_type::value_type(1.7 , 2) ); + + // Print all the elements of the left map view + + for_each( bm.left, pair_printer(std::cout) ); + + // Print a range of elements of the right map view + + for_each( bm.right.range( 2 <= _key, _key < 6 ), pair_printer(std::cout) ); + + // Count the number of elements where the data is equal to 2 from a + // range of elements of the left map view + + count_if( bm.left.range( 2.3 < _key, _key < 5.4 ), + bind<int>( second_extractor(), _1 ) == 2 ); + + return 0; +} +//] + diff --git a/src/boost/libs/bimap/example/bimap_and_boost/serialization.cpp b/src/boost/libs/bimap/example/bimap_and_boost/serialization.cpp new file mode 100644 index 000000000..c2548b8ab --- /dev/null +++ b/src/boost/libs/bimap/example/bimap_and_boost/serialization.cpp @@ -0,0 +1,89 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <fstream> +#include <string> +#include <cassert> + +#include <boost/bimap/bimap.hpp> + +#include <boost/archive/text_oarchive.hpp> +#include <boost/archive/text_iarchive.hpp> + +using namespace boost::bimaps; + +int main() +{ + //[ code_bimap_and_boost_serialization + + typedef bimap< std::string, int > bm_type; + + // Create a bimap and serialize it to a file + { + bm_type bm; + bm.insert( bm_type::value_type("one",1) ); + bm.insert( bm_type::value_type("two",2) ); + + std::ofstream ofs("data"); + boost::archive::text_oarchive oa(ofs); + + oa << const_cast<const bm_type&>(bm); /*< + We must do a const cast because Boost.Serialization archives + only save const objects. Read Boost.Serializartion docs for the + rationale behind this decision >*/ + + /*<< We can only serialize iterators if the bimap was serialized first. + Note that the const cast is not required here because we create + our iterators as const. >>*/ + const bm_type::left_iterator left_iter = bm.left.find("two"); + oa << left_iter; + + const bm_type::right_iterator right_iter = bm.right.find(1); + oa << right_iter; + } + + // Load the bimap back + { + bm_type bm; + + std::ifstream ifs("data", std::ios::binary); + boost::archive::text_iarchive ia(ifs); + + ia >> bm; + + assert( bm.size() == 2 ); + + bm_type::left_iterator left_iter; + ia >> left_iter; + + assert( left_iter->first == "two" ); + + bm_type::right_iterator right_iter; + ia >> right_iter; + + assert( right_iter->first == 1 ); + } + //] + + return 0; +} + diff --git a/src/boost/libs/bimap/example/bimap_and_boost/typeof.cpp b/src/boost/libs/bimap/example/bimap_and_boost/typeof.cpp new file mode 100644 index 000000000..dac1015e1 --- /dev/null +++ b/src/boost/libs/bimap/example/bimap_and_boost/typeof.cpp @@ -0,0 +1,86 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <string> +#include <iostream> +#include <boost/bimap/bimap.hpp> + +#include <boost/typeof/typeof.hpp> + +using namespace boost::bimaps; + +struct name {}; +struct number {}; + +void using_auto() +{ + //[ code_bimap_and_boost_typeof_first + + typedef bimap< tagged<std::string,name>, tagged<int,number> > bm_type; + bm_type bm; + bm.insert( bm_type::value_type("one" ,1) ); + bm.insert( bm_type::value_type("two" ,2) ); + //] + + //[ code_bimap_and_boost_typeof_using_auto + + for( BOOST_AUTO(iter, bm.by<name>().begin()); iter!=bm.by<name>().end(); ++iter) + { + std::cout << iter->first << " --> " << iter->second << std::endl; + } + + BOOST_AUTO( iter, bm.by<number>().find(2) ); + std::cout << "2: " << iter->get<name>(); + //] +} + +void not_using_auto() +{ + typedef bimap< tagged<std::string,name>, tagged<int,number> > bm_type; + bm_type bm; + bm.insert( bm_type::value_type("one" ,1) ); + bm.insert( bm_type::value_type("two" ,2) ); + + //[ code_bimap_and_boost_typeof_not_using_auto + + for( bm_type::map_by<name>::iterator iter = bm.by<name>().begin(); + iter!=bm.by<name>().end(); ++iter) + { + std::cout << iter->first << " --> " << iter->second << std::endl; + } + + bm_type::map_by<number>::iterator iter = bm.by<number>().find(2); + std::cout << "2: " << iter->get<name>(); + //] +} + +int main() +{ + using_auto(); + not_using_auto(); + + return 0; +} + + + + diff --git a/src/boost/libs/bimap/example/bimap_and_boost/xpressive.cpp b/src/boost/libs/bimap/example/bimap_and_boost/xpressive.cpp new file mode 100644 index 000000000..7949c84dc --- /dev/null +++ b/src/boost/libs/bimap/example/bimap_and_boost/xpressive.cpp @@ -0,0 +1,57 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <string> + +#include <boost/bimap/bimap.hpp> + +#include <boost/xpressive/xpressive.hpp> +#include <boost/xpressive/regex_actions.hpp> + +using namespace boost::bimaps; +using namespace boost::xpressive; +namespace xp = boost::xpressive; + +int main() +{ + //[ code_bimap_and_boost_xpressive + + 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<bm_type::value_type>(s1, as<int>(s2)) ) + ]; + + sregex relations = rel >> *(+_s >> rel); + + regex_match(rel_str, relations); + + assert( bm.size() == 3 ); + //] + + return 0; +} + diff --git a/src/boost/libs/bimap/example/mi_to_b_path/bidirectional_map.cpp b/src/boost/libs/bimap/example/mi_to_b_path/bidirectional_map.cpp new file mode 100644 index 000000000..20edf941a --- /dev/null +++ b/src/boost/libs/bimap/example/mi_to_b_path/bidirectional_map.cpp @@ -0,0 +1,87 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + + +// Boost.Bimap Example +//----------------------------------------------------------------------------- +// This example shows how to construct a bidirectional map with +// multi_index_container. +// By a bidirectional map we mean a container of elements of +// std::pair<const FromType,const ToType> such that no two elements exists with +// the same first or second value (std::map only guarantees uniqueness of the +// first member). +// Fast lookup is provided for both keys. The program features a tiny +// Spanish-English dictionary with online query of words in both languages. + +#include <boost/config.hpp> + +//[ code_mi_to_b_path_bidirectional_map + +#include <iostream> +#include <boost/tokenizer.hpp> +#include <boost/bimap/bimap.hpp> + +using namespace boost::bimaps; + +// A dictionary is a bidirectional map from strings to strings + +typedef bimap<std::string,std::string> dictionary; +typedef dictionary::value_type translation; + +int main() +{ + dictionary d; + + // Fill up our microdictionary. + // first members Spanish, second members English. + + d.insert( translation("hola" ,"hello" )); + d.insert( translation("adios","goodbye")); + d.insert( translation("rosa" ,"rose" )); + d.insert( translation("mesa" ,"table" )); + + std::cout << "enter a word" << std::endl; + std::string word; + std::getline(std::cin,word); + + // search the queried word on the from index (Spanish) + + dictionary::left_const_iterator it = d.left.find(word); + + if( it != d.left.end() ) + { + // the second part of the element is the equivalent in English + + std::cout << word << " is said " + << it->second /*< `it` is an iterator of the left view, so + `it->second` refers to the right element of + the relation, the word in english >*/ + << " in English" << std::endl; + } + else + { + // word not found in Spanish, try our luck in English + + dictionary::right_const_iterator it2 = d.right.find(word); + if( it2 != d.right.end() ) + { + std::cout << word << " is said " + << it2->second /*< `it2` is an iterator of the right view, so + `it2->second` refers to the left element of + the relation, the word in spanish >*/ + << " in Spanish" << std::endl; + } + else + { + std::cout << "No such word in the dictionary" << std::endl; + } + } + + return 0; +} +//] diff --git a/src/boost/libs/bimap/example/mi_to_b_path/hashed_indices.cpp b/src/boost/libs/bimap/example/mi_to_b_path/hashed_indices.cpp new file mode 100644 index 000000000..22bb391b8 --- /dev/null +++ b/src/boost/libs/bimap/example/mi_to_b_path/hashed_indices.cpp @@ -0,0 +1,94 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + + +// Boost.Bimap Example +//----------------------------------------------------------------------------- +// Hashed indices can be used as an alternative to ordered indices when fast +// lookup is needed and sorting information is of no interest. The example +// features a word counter where duplicate entries are checked by means of a +// hashed index. + +#include <boost/config.hpp> + +//[ code_mi_to_b_path_hashed_indices + +#include <iostream> +#include <iomanip> + +#include <boost/tokenizer.hpp> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/unordered_set_of.hpp> +#include <boost/bimap/multiset_of.hpp> +#include <boost/bimap/support/lambda.hpp> + +using namespace boost::bimaps; + +struct word {}; +struct occurrences {}; + +typedef bimap +< + + multiset_of< tagged<unsigned int,occurrences>, std::greater<unsigned int> >, +unordered_set_of< tagged< std::string, word> > + +> word_counter; + +typedef boost::tokenizer<boost::char_separator<char> > 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<char>(" \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<occurrences>::iterator wit = + wc.by<occurrences>().insert( + word_counter::map_by<occurrences>::value_type(0,*it) + ).first; + + wc.by<occurrences>().modify_key( wit, ++_key); + } + + // list words by frequency of appearance + + std::cout << std::fixed << std::setprecision(2); + + for( word_counter::map_by<occurrences>::const_iterator + wit = wc.by<occurrences>().begin(), + wit_end = wc.by<occurrences>().end(); + + wit != wit_end; ++wit ) + { + std::cout << std::setw(15) << wit->get<word>() << ": " + << std::setw(5) + << 100.0 * wit->get<occurrences>() / total_occurrences << "%" + << std::endl; + } + + return 0; +} +//] diff --git a/src/boost/libs/bimap/example/mi_to_b_path/mi_bidirectional_map.cpp b/src/boost/libs/bimap/example/mi_to_b_path/mi_bidirectional_map.cpp new file mode 100644 index 000000000..27045d0be --- /dev/null +++ b/src/boost/libs/bimap/example/mi_to_b_path/mi_bidirectional_map.cpp @@ -0,0 +1,107 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +/****************************************************************************** +Boost.MultiIndex +******************************************************************************/ + +#include <boost/config.hpp> + +//[ code_mi_to_b_path_mi_bidirectional_map + +#include <iostream> +#include <boost/tokenizer.hpp> + +#include <boost/multi_index_container.hpp> +#include <boost/multi_index/key_extractors.hpp> +#include <boost/multi_index/ordered_index.hpp> + +using namespace boost; +using namespace boost::multi_index; + +// tags for accessing both sides of a bidirectional map + +struct from {}; +struct to {}; + +// The class template bidirectional_map wraps the specification +// of a bidirectional map based on multi_index_container. + +template<typename FromType,typename ToType> +struct bidirectional_map +{ + typedef std::pair<FromType,ToType> value_type; + + typedef multi_index_container< + value_type, + indexed_by + < + ordered_unique + < + tag<from>, member<value_type,FromType,&value_type::first> + >, + ordered_unique + < + tag<to>, member<value_type,ToType,&value_type::second> + > + > + + > type; + +}; + +// A dictionary is a bidirectional map from strings to strings + +typedef bidirectional_map<std::string,std::string>::type dictionary; + +int main() +{ + dictionary d; + + // Fill up our microdictionary. + // first members Spanish, second members English. + + d.insert(dictionary::value_type("hola","hello")); + d.insert(dictionary::value_type("adios","goodbye")); + d.insert(dictionary::value_type("rosa","rose")); + d.insert(dictionary::value_type("mesa","table")); + + std::cout << "enter a word" << std::endl; + std::string word; + std::getline(std::cin,word); + + // search the queried word on the from index (Spanish) + + dictionary::iterator it = d.get<from>().find(word); + + if( it != d.end() ) + { + // the second part of the element is the equivalent in English + + std::cout << word << " is said " + << it->second << " in English" << std::endl; + } + else + { + // word not found in Spanish, try our luck in English + + dictionary::index_iterator<to>::type it2 = d.get<to>().find(word); + if( it2 != d.get<to>().end() ) + { + std::cout << word << " is said " + << it2->first << " in Spanish" << std::endl; + } + else + { + std::cout << "No such word in the dictionary" << std::endl; + } + } + + return 0; +} +//] diff --git a/src/boost/libs/bimap/example/mi_to_b_path/mi_hashed_indices.cpp b/src/boost/libs/bimap/example/mi_to_b_path/mi_hashed_indices.cpp new file mode 100644 index 000000000..4e59fce00 --- /dev/null +++ b/src/boost/libs/bimap/example/mi_to_b_path/mi_hashed_indices.cpp @@ -0,0 +1,100 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + + +/***************************************************************************** +Boost.MultiIndex +*****************************************************************************/ + +#include <boost/config.hpp> + +//[ code_mi_to_b_path_mi_hashed_indices + +#include <iostream> +#include <iomanip> + +#include <boost/tokenizer.hpp> + +#include <boost/multi_index_container.hpp> +#include <boost/multi_index/key_extractors.hpp> +#include <boost/multi_index/ordered_index.hpp> +#include <boost/multi_index/hashed_index.hpp> +#include <boost/lambda/lambda.hpp> + +using namespace boost::multi_index; +namespace bl = boost::lambda; + +// word_counter keeps the occurrences of words inserted. A hashed +// index allows for fast checking of preexisting entries. + +struct word_counter_entry +{ + std::string word; + unsigned int occurrences; + + word_counter_entry( std::string word_ ) : word(word_), occurrences(0) {} +}; + +typedef multi_index_container +< + word_counter_entry, + indexed_by + < + ordered_non_unique + < + BOOST_MULTI_INDEX_MEMBER( + word_counter_entry,unsigned int,occurrences), + std::greater<unsigned int> + >, + hashed_unique + < + BOOST_MULTI_INDEX_MEMBER(word_counter_entry,std::string,word) + > + > + +> word_counter; + +typedef boost::tokenizer<boost::char_separator<char> > text_tokenizer; + +int main() +{ + std::string text= + "En un lugar de la Mancha, de cuyo nombre no quiero acordarme... " + "...snip..." + "...no se salga un punto de la verdad."; + + // feed the text into the container + + word_counter wc; + text_tokenizer tok(text,boost::char_separator<char>(" \t\n.,;:!?'\"-")); + unsigned int total_occurrences = 0; + + for( text_tokenizer::iterator it = tok.begin(), it_end = tok.end(); + it != it_end ; ++it ) + { + ++total_occurrences; + word_counter::iterator wit = wc.insert(*it).first; + wc.modify_key( wit, ++ bl::_1 ); + } + + // list words by frequency of appearance + + std::cout << std::fixed << std::setprecision(2); + + for( word_counter::iterator wit = wc.begin(), wit_end=wc.end(); + wit != wit_end; ++wit ) + { + std::cout << std::setw(11) << wit->word << ": " + << std::setw(5) + << 100.0 * wit->occurrences / total_occurrences << "%" + << std::endl; + } + + return 0; +} +//] diff --git a/src/boost/libs/bimap/example/mi_to_b_path/tagged_bidirectional_map.cpp b/src/boost/libs/bimap/example/mi_to_b_path/tagged_bidirectional_map.cpp new file mode 100644 index 000000000..4c0ddb616 --- /dev/null +++ b/src/boost/libs/bimap/example/mi_to_b_path/tagged_bidirectional_map.cpp @@ -0,0 +1,90 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + + +// Boost.Bimap Example +//----------------------------------------------------------------------------- +// This example shows how to construct a bidirectional map with +// multi_index_container. +// By a bidirectional map we mean a container of elements of +// std::pair<const FromType,const ToType> such that no two elements exists with +// the same first or second value (std::map only guarantees uniqueness of the +// first member). +// Fast lookup is provided for both keys. The program features a tiny +// Spanish-English dictionary with online query of words in both languages. + +//[ code_mi_to_b_path_tagged_bidirectional_map + +#include <iostream> + +#include <boost/bimap/bimap.hpp> + +using namespace boost::bimaps; + +// tags + +struct spanish {}; +struct english {}; + +// A dictionary is a bidirectional map from strings to strings + +typedef bimap +< + tagged< std::string,spanish >, tagged< std::string,english > + +> dictionary; + +typedef dictionary::value_type translation; + +int main() +{ + dictionary d; + + // Fill up our microdictionary. + // first members Spanish, second members English. + + d.insert( translation("hola" ,"hello" )); + d.insert( translation("adios","goodbye")); + d.insert( translation("rosa" ,"rose" )); + d.insert( translation("mesa" ,"table" )); + + std::cout << "enter a word" << std::endl; + std::string word; + std::getline(std::cin,word); + + // search the queried word on the from index (Spanish) */ + + dictionary::map_by<spanish>::const_iterator it = + d.by<spanish>().find(word); + + if( it != d.by<spanish>().end() ) + { + std::cout << word << " is said " + << it->get<english>() << " in English" << std::endl; + } + else + { + // word not found in Spanish, try our luck in English + + dictionary::map_by<english>::const_iterator it2 = + d.by<english>().find(word); + + if( it2 != d.by<english>().end() ) + { + std::cout << word << " is said " + << it2->get<spanish>() << " in Spanish" << std::endl; + } + else + { + std::cout << "No such word in the dictionary" << std::endl; + } + } + + return 0; +} +//] diff --git a/src/boost/libs/bimap/example/mighty_bimap.cpp b/src/boost/libs/bimap/example/mighty_bimap.cpp new file mode 100644 index 000000000..a4b369ba5 --- /dev/null +++ b/src/boost/libs/bimap/example/mighty_bimap.cpp @@ -0,0 +1,109 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- +// This is the translator example from the tutorial. +// In this example the set type of relation is changed to allow the iteration +// of the container. + +#include <boost/config.hpp> + +//[ code_mighty_bimap + +#include <iostream> +#include <string> +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/list_of.hpp> +#include <boost/bimap/unordered_set_of.hpp> + +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; + + // We have to use `push_back` because the collection of relations is + // a `list_of_relation` + + 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); + + // Search the queried word on the from index (Spanish) + + translator::map_by<spanish>::const_iterator is + = trans.by<spanish>().find(word); + + if( is != trans.by<spanish>().end() ) + { + std::cout << word << " is said " + << is->get<english>() + << " in English" << std::endl; + } + else + { + // Word not found in Spanish, try our luck in English + + translator::map_by<english>::const_iterator ie + = trans.by<english>().find(word); + + if( ie != trans.by<english>().end() ) + { + std::cout << word << " is said " + << ie->get<spanish>() + << " in Spanish" << std::endl; + } + else + { + // Word not found, show the possible translations + + 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<spanish>() + << " <---> " + << i->get<english>() + << std::endl; + } + } + } + return 0; +} +//] diff --git a/src/boost/libs/bimap/example/population_bimap.cpp b/src/boost/libs/bimap/example/population_bimap.cpp new file mode 100644 index 000000000..09fdf7bd4 --- /dev/null +++ b/src/boost/libs/bimap/example/population_bimap.cpp @@ -0,0 +1,121 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <iostream> +#include <string> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/unordered_set_of.hpp> +#include <boost/bimap/multiset_of.hpp> + +#include <boost/optional.hpp> +#include <boost/none.hpp> +#include <boost/foreach.hpp> +#include <boost/assign/list_inserter.hpp> + +using namespace boost::bimaps; +using namespace boost; +using namespace std; + +int main() +{ + { + + typedef bimap< + + string, + multiset_of< optional<string> > + + > bm_type; + + bm_type bm; + + assign::insert( bm ) + + ( "John" , string("lazarus" ) ) + ( "Peter", string("vinicius") ) + ( "Simon", string("vinicius") ) + ( "Brian", none ) + ; + + cout << "John is working in " + << bm.left.at( "John" ).get_value_or( "no project" ) + << endl; + + cout << "Project vinicius is being developed by " << endl; + BOOST_FOREACH( bm_type::right_reference rp, + bm.right.equal_range( std::string("vinicius") ) ) + { + cout << rp.second << endl; + } + + cout << "This workers need a project " << endl; + BOOST_FOREACH( bm_type::right_reference rp, + bm.right.equal_range(none) ) + { + cout << rp.second << endl; + } + +} + + //[ code_population_bimap + + typedef bimap< + + unordered_set_of< std::string >, + multiset_of< long, std::greater<long> > + + > population_bimap; + + typedef population_bimap::value_type population; + + population_bimap pop; + pop.insert( population("China", 1321000000) ); + pop.insert( population("India", 1129000000) ); + pop.insert( population("United States", 301950000) ); + pop.insert( population("Indonesia", 234950000) ); + pop.insert( population("Brazil", 186500000) ); + pop.insert( population("Pakistan", 163630000) ); + + std::cout << "Countries by their population:" << std::endl; + + // First requirement + /*<< The right map view works like a + `std::multimap< long, std::string, std::greater<long> >`, + We can iterate over it to print the results in the required order. >>*/ + for( population_bimap::right_const_iterator + i = pop.right.begin(), iend = pop.right.end(); + i != iend ; ++i ) + { + std::cout << i->second << " with " << i->first << std::endl; + } + + // Second requirement + /*<< The left map view works like a `std::unordered_map< std::string, long >`, + given the name of the country we can use it to search for the population + in constant time >>*/ + std::cout << "Population of China: " << pop.left.at("China") << std::endl; + //] + + return 0; +} + diff --git a/src/boost/libs/bimap/example/projection.cpp b/src/boost/libs/bimap/example/projection.cpp new file mode 100644 index 000000000..8332385a7 --- /dev/null +++ b/src/boost/libs/bimap/example/projection.cpp @@ -0,0 +1,60 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <string> +#include <iostream> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/multiset_of.hpp> +using namespace boost::bimaps; + +void years_example() +{ + //[ code_projection_years + + typedef bimap<std::string,multiset_of<int,std::greater<int> > > bm_type; + + bm_type bm; + bm.insert( bm_type::value_type("John" ,34) ); + bm.insert( bm_type::value_type("Peter",24) ); + bm.insert( bm_type::value_type("Mary" ,12) ); + + // Find the name of the next younger person after Peter + + bm_type::left_const_iterator name_iter = bm.left.find("Peter"); + + bm_type::right_const_iterator years_iter = bm.project_right(name_iter); + + ++years_iter; + + std::cout << "The next younger person after Peter is " << years_iter->second; + //] +} + +int main() +{ + years_example(); + + return 0; +} + + diff --git a/src/boost/libs/bimap/example/repetitions_counter.cpp b/src/boost/libs/bimap/example/repetitions_counter.cpp new file mode 100644 index 000000000..d16570983 --- /dev/null +++ b/src/boost/libs/bimap/example/repetitions_counter.cpp @@ -0,0 +1,91 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <iostream> +#include <boost/tokenizer.hpp> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/unordered_set_of.hpp> +#include <boost/bimap/list_of.hpp> + +using namespace boost::bimaps; + +struct counter { + counter() : c(0) {} + counter& operator++() { ++c; return *this; } + unsigned int operator++(int) { return c++; } + operator const unsigned int() const { return c; } + private: + unsigned int c; +}; + +int main() +{ + //[ code_repetitions_counter + + typedef bimap + < + unordered_set_of< std::string >, + list_of< counter > /*< `counter` is an integer that is initialized + in zero in the constructor >*/ + + > word_counter; + + typedef boost::tokenizer<boost::char_separator<char> > text_tokenizer; + + 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<char>(" \t\n.,;:!?'\"-")); + + for( text_tokenizer::const_iterator it = tok.begin(), it_end = tok.end(); + it != it_end ; ++it ) + { + /*<< Because the right collection type is `list_of`, the right data + is not used a key and can be modified in the same way as with + standard maps. >>*/ + ++ wc.left[*it]; + } + + // list words with counters by order of appearance + /*<< When we insert the elements using the left map view, the element + is inserted at the end of the list. >>*/ + for( word_counter::right_const_iterator + wit = wc.right.begin(), wit_end = wc.right.end(); + + wit != wit_end; ++wit ) + { + std::cout << wit->second << ": " << wit->first; + } + //] + + return 0; +} + + diff --git a/src/boost/libs/bimap/example/simple_bimap.cpp b/src/boost/libs/bimap/example/simple_bimap.cpp new file mode 100644 index 000000000..d7db74c25 --- /dev/null +++ b/src/boost/libs/bimap/example/simple_bimap.cpp @@ -0,0 +1,82 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +//[ code_simple_bimap + +#include <string> +#include <iostream> + +#include <boost/bimap.hpp> + +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; +} +//] + diff --git a/src/boost/libs/bimap/example/standard_map_comparison.cpp b/src/boost/libs/bimap/example/standard_map_comparison.cpp new file mode 100644 index 000000000..37ff660ea --- /dev/null +++ b/src/boost/libs/bimap/example/standard_map_comparison.cpp @@ -0,0 +1,93 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <string> +#include <iostream> + +#include <map> +#include <boost/bimap/bimap.hpp> + +using namespace boost::bimaps; + +//[ code_standard_map_comparison + +template< class Map, class CompatibleKey, class CompatibleData > +void use_it( Map & m, + const CompatibleKey & key, + const CompatibleData & data ) +{ + typedef typename Map::value_type value_type; + typedef typename Map::const_iterator const_iterator; + + m.insert( value_type(key,data) ); + const_iterator iter = m.find(key); + if( iter != m.end() ) + { + assert( iter->first == key ); + assert( iter->second == data ); + + std::cout << iter->first << " --> " << iter->second; + } + m.erase(key); +} + +int main() +{ + typedef bimap< set_of<std::string>, set_of<int> > bimap_type; + bimap_type bm; + + // Standard map + { + typedef std::map< std::string, int > map_type; + map_type m; + + use_it( m, "one", 1 ); + } + + // Left map view + { + typedef bimap_type::left_map map_type; + map_type & m = bm.left; + + use_it( m, "one", 1 ); + } + + // Reverse standard map + { + typedef std::map< int, std::string > reverse_map_type; + reverse_map_type rm; + + use_it( rm, 1, "one" ); + } + + // Right map view + { + typedef bimap_type::right_map reverse_map_type; + reverse_map_type & rm = bm.right; + + use_it( rm, 1, "one" ); + } + + return 0; +} +//] + diff --git a/src/boost/libs/bimap/example/step_by_step.cpp b/src/boost/libs/bimap/example/step_by_step.cpp new file mode 100644 index 000000000..a4be4e6b8 --- /dev/null +++ b/src/boost/libs/bimap/example/step_by_step.cpp @@ -0,0 +1,102 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <iostream> +#include <cassert> + +// A convenience header is available in the boost directory: +#include <boost/bimap.hpp> + +int main() +{ + //[ code_step_by_step_definition + + typedef boost::bimap< int, std::string > bm_type; + bm_type bm; + //] + + //[ code_step_by_step_set_of_relations_view + + bm.insert( bm_type::value_type(1, "one" ) ); + bm.insert( bm_type::value_type(2, "two" ) ); + + std::cout << "There are " << bm.size() << "relations" << std::endl; + + for( bm_type::const_iterator iter = bm.begin(), iend = bm.end(); + iter != iend; ++iter ) + { + // iter->left : data : int + // iter->right : data : std::string + + std::cout << iter->left << " <--> " << iter->right << std::endl; + } + //] + + //[ code_step_by_step_left_map_view + + /*<< The type of `bm.left` is `bm_type::left_map` and the type + of `bm.right` is `bm_type::right_map` >>*/ + typedef bm_type::left_map::const_iterator left_const_iterator; + + for( left_const_iterator left_iter = bm.left.begin(), iend = bm.left.end(); + left_iter != iend; ++left_iter ) + { + // left_iter->first : key : int + // left_iter->second : data : std::string + + std::cout << left_iter->first << " --> " << left_iter->second << std::endl; + } + + /*<< `bm_type::left_`\ -type- can be used as a shortcut for the more verbose + `bm_type::left_map::`\ -type- >>*/ + bm_type::left_const_iterator left_iter = bm.left.find(2); + assert( left_iter->second == "two" ); + + /*<< This line produces the same effect of + `bm.insert( bm_type::value_type(3,"three") );` >>*/ + bm.left.insert( bm_type::left_value_type( 3, "three" ) ); + //] + + + + //[ code_step_by_step_right_map_view + + bm_type::right_const_iterator right_iter = bm.right.find("two"); + + // right_iter->first : key : std::string + // right_iter->second : data : int + + assert( right_iter->second == 2 ); + + assert( bm.right.at("one") == 1 ); + + bm.right.erase("two"); + + /*<< This line produces the same effect of + `bm.insert( bm_type::value_type(4,"four") );` >>*/ + bm.right.insert( bm_type::right_value_type( "four", 4 ) ); + //] + + return 0; +} + + diff --git a/src/boost/libs/bimap/example/tagged_simple_bimap.cpp b/src/boost/libs/bimap/example/tagged_simple_bimap.cpp new file mode 100644 index 000000000..1160ef5cc --- /dev/null +++ b/src/boost/libs/bimap/example/tagged_simple_bimap.cpp @@ -0,0 +1,86 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +//[ code_tagged_simple_bimap + +#include <iostream> + +#include <boost/bimap.hpp> + +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<place>()` is equivalent to `results.right` >>*/ + for( results_bimap::map_by<place>::const_iterator + i = results.by<place>().begin(), + iend = results.by<place>().end() ; + i != iend; ++i ) + { + /*<< `get<Tag>` works for each view of the bimap >>*/ + std::cout << i->get<place >() << ") " + << i->get<country>() << std::endl; + } + + std::cout << std::endl + << "Countries names ordered alfabetically along with" + "their final position:" + << std::endl; + + /*<< `results.by<country>()` is equivalent to `results.left` >>*/ + for( results_bimap::map_by<country>::const_iterator + i = results.by<country>().begin(), + iend = results.by<country>().end() ; + i != iend; ++i ) + { + std::cout << i->get<country>() << " ends " + << i->get<place >() << "º" + << std::endl; + } + + return 0; +} +//] + diff --git a/src/boost/libs/bimap/example/tutorial_info_hook.cpp b/src/boost/libs/bimap/example/tutorial_info_hook.cpp new file mode 100644 index 000000000..a2e321484 --- /dev/null +++ b/src/boost/libs/bimap/example/tutorial_info_hook.cpp @@ -0,0 +1,163 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <string> +#include <iostream> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/multiset_of.hpp> + +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"); + //] +} + +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<title>().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"); + //] +} + + +void bimap_without_an_info_hook() +{ + //[ code_tutorial_info_hook_nothing + + typedef bimap< + + multiset_of< std::string >, // author + set_of< std::string > // title + + > bm_type; + typedef bm_type::value_type book; + + bm_type bm; + + bm.insert( book( "Bjarne Stroustrup" , "The C++ Programming Language" ) ); + bm.insert( book( "Scott Meyers" , "Effective C++" ) ); + bm.insert( book( "Andrei Alexandrescu" , "Modern C++ Design" ) ); + + // Print the author of Modern C++ + std::cout << bm.right.at( "Modern C++ Design" ); + //] +} + + +int main() +{ + tutorial_about_info_hook(); + tutorial_about_tagged_info_hook(); + bimap_without_an_info_hook(); + + return 0; +} + + diff --git a/src/boost/libs/bimap/example/tutorial_modify_and_replace.cpp b/src/boost/libs/bimap/example/tutorial_modify_and_replace.cpp new file mode 100644 index 000000000..fbb93cef8 --- /dev/null +++ b/src/boost/libs/bimap/example/tutorial_modify_and_replace.cpp @@ -0,0 +1,118 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <string> +#include <iostream> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/support/lambda.hpp> + +using namespace boost::bimaps; + +void test_replace() +{ + //[ code_tutorial_replace + + typedef bimap< int, std::string > bm_type; + bm_type bm; + + bm.insert( bm_type::value_type(1,"one") ); + + // Replace (1,"one") with (1,"1") using the right map view + { + bm_type::right_iterator it = bm.right.find("one"); + + bool successful_replace = bm.right.replace_key( it, "1" ); + + assert( successful_replace ); + } + + bm.insert( bm_type::value_type(2,"two") ); + + // Fail to replace (1,"1") with (1,"two") using the left map view + { + assert( bm.size() == 2 ); + + bm_type::left_iterator it = bm.left.find(1); + + bool successful_replace = bm.left.replace_data( it, "two" ); + + /*<< `it` is still valid here, and the bimap was left unchanged >>*/ + assert( ! successful_replace ); + assert( bm.size() == 2 ); + } + //] +} + +void test_modify() +{ + //[ code_tutorial_modify + + typedef bimap< int, std::string > bm_type; + bm_type bm; + bm.insert( bm_type::value_type(1,"one") ); + + // Modify (1,"one") to (1,"1") using the right map view + { + bm_type::right_iterator it = bm.right.find("one"); + + bool successful_modify = bm.right.modify_key( it , _key = "1" ); + + assert( successful_modify ); + } + + bm.insert( bm_type::value_type(2,"two") ); + + // Fail to modify (1,"1") to (1,"two") using the left map view + { + assert( bm.size() == 2 ); + + bm_type::left_iterator it = bm.left.find(1); + + bool successful_modify = bm.left.modify_data( it, _data = "two" ); + + /*<< `it` is not longer valid and `(1,"1")` is removed from the bimap >>*/ + assert( ! successful_modify ); + assert( bm.size() == 1 ); + } + //] + + /* + // Modify (2,"two") to (3,"two") using the set of relations view + { + bm_type::iterator it = bm.begin(); + + bool successful_modify = bm.modify( it, ++_left ); + + assert( successful_modify ); + } + */ +} + +int main() +{ + test_replace(); + test_modify(); + return 0; +} + + diff --git a/src/boost/libs/bimap/example/tutorial_range.cpp b/src/boost/libs/bimap/example/tutorial_range.cpp new file mode 100644 index 000000000..6d3259ae9 --- /dev/null +++ b/src/boost/libs/bimap/example/tutorial_range.cpp @@ -0,0 +1,100 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <string> +#include <iostream> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/support/lambda.hpp> + +using namespace boost::bimaps; + +void using_upper_and_lower_bound() +{ + //[ code_tutorial_range_standard_way + + typedef bimap<int,std::string> bm_type; + bm_type bm; + + // ... + + bm_type::left_iterator iter_first = bm.left.lower_bound(20); + bm_type::left_iterator iter_second = bm.left.upper_bound(50); + + // range [iter_first,iter_second) contains the elements in [20,50] + //] + + // Subtle changes + { + //[ code_tutorial_range_standard_way_subtle_changes + + bm_type::left_iterator iter_first = bm.left.upper_bound(20); + bm_type::left_iterator iter_second = bm.left.lower_bound(50); + + // range [iter_first,iter_second) contains the elements in (20,50) + //] + } +} + +void using_range() +{ + //[ code_tutorial_range + + typedef bimap<int,std::string> bm_type; + bm_type bm; + + // ... + + /*<< `range_type` is a handy typedef equal to `std::pair<iterator,iterator>`. + `const_range_type` is provided too, and it is equal to + `std::pair<const_iterator,const_iterator>` >>*/ + bm_type::left_range_type r; + + /*<< _key is a Boost.Lambda placeholder. To use it you have to include + `<boost/bimap/support/lambda.hpp>` >>*/ + r = bm.left.range( 20 <= _key, _key <= 50 ); // [20,50] + + r = bm.left.range( 20 < _key, _key < 50 ); // (20,50) + + r = bm.left.range( 20 <= _key, _key < 50 ); // [20,50) + //] + + //[ code_tutorial_range_unbounded + + r = bm.left.range( 20 <= _key, unbounded ); // [20,inf) + + r = bm.left.range( unbounded , _key < 50 ); // (-inf,50) + + /*<< This is equivalent to std::make_pair(s.begin(),s.end()) >>*/ + r = bm.left.range( unbounded , unbounded ); // (-inf,inf) + //] +} + +int main() +{ + using_upper_and_lower_bound(); + using_range(); + + return 0; +} + + diff --git a/src/boost/libs/bimap/example/unconstrained_collection.cpp b/src/boost/libs/bimap/example/unconstrained_collection.cpp new file mode 100644 index 000000000..1af035630 --- /dev/null +++ b/src/boost/libs/bimap/example/unconstrained_collection.cpp @@ -0,0 +1,94 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <string> +#include <iostream> + +#include <map> +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/unconstrained_set_of.hpp> +#include <boost/bimap/support/lambda.hpp> + +using namespace boost::bimaps; + +int main() +{ + // Boost.Bimap + { + //[ code_unconstrained_collection_bimap + + typedef bimap< std::string, unconstrained_set_of<int> > bm_type; + typedef bm_type::left_map map_type; + + bm_type bm; + map_type & m = bm.left; + //] + + //[ code_unconstrained_collection_common + + m["one"] = 1; + + assert( m.find("one") != m.end() ); + + for( map_type::iterator i = m.begin(), iend = m.end(); i != iend; ++i ) + { + /*<< The right collection of the bimap is mutable so its elements + can be modified using iterators. >>*/ + ++(i->second); + } + + m.erase("one"); + //] + + m["one"] = 1; + m["two"] = 2; + + //[ code_unconstrained_collection_only_for_bimap + typedef map_type::const_iterator const_iterator; + typedef std::pair<const_iterator,const_iterator> const_range; + + /*<< This range is a model of BidirectionalRange, read the docs of + Boost.Range for more information. >>*/ + const_range r = m.range( "one" <= _key, _key <= "two" ); + for( const_iterator i = r.first; i != r.second; ++i ) + { + std::cout << i->first << "-->" << i->second << std::endl; + } + + m.modify_key( m.begin(), _key = "1" ); + //] + } + + // Standard map + { + //[ code_unconstrained_collection_map + + typedef std::map< std::string, int > map_type; + + map_type m; + //] + } + + return 0; +} + + diff --git a/src/boost/libs/bimap/example/user_defined_names.cpp b/src/boost/libs/bimap/example/user_defined_names.cpp new file mode 100644 index 000000000..53cb2a300 --- /dev/null +++ b/src/boost/libs/bimap/example/user_defined_names.cpp @@ -0,0 +1,142 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +// Boost.Bimap Example +//----------------------------------------------------------------------------- + +#include <boost/config.hpp> + +#include <string> +#include <iostream> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/multiset_of.hpp> + +using namespace boost::bimaps; + +void untagged_version() +{ + //[ code_user_defined_names_untagged_version + + typedef bimap + < + multiset_of<std::string>, + int + + > People; + + People people; + + // ... + + int user_id; + std::cin >> user_id; + + // people.right : map<id,name> + + 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<name,id> + + 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; + } + } + //] +} + +struct id {}; +struct name {}; + +void tagged_version() +{ + //[ code_user_defined_names_tagged_version + + //<- + /* + //-> + struct id {}; // Tag for the identification number + struct name {}; // Tag for the name of the person + //<- + */ + //-> + + typedef bimap + < + tagged< int , id > , + multiset_of< tagged< std::string, name > > + + > People; + + People people; + + // ... + + int user_id; + std::cin >> user_id; + + People::map_by<id>::const_iterator id_iter = people.by<id>().find(user_id); + if( id_iter != people.by<id>().end() ) + { + std::cout << "name: " << id_iter->get<name>() << std::endl + << "id: " << id_iter->get<id>() << std::endl; + } + else + { + std::cout << "Unknown id, users are:" << std::endl; + + for( People::map_by<name>::const_iterator + name_iter = people.by<name>().begin(), + iend = people.by<name>().end(); + + name_iter != iend; ++name_iter ) + { + std::cout << "name: " << name_iter->get<name>() << std::endl + << "id: " << name_iter->get<id>() << std::endl; + } + } + //] +} + +int main() +{ + untagged_version(); + tagged_version(); + + return 0; +} + diff --git a/src/boost/libs/bimap/index.html b/src/boost/libs/bimap/index.html new file mode 100644 index 000000000..f25c67266 --- /dev/null +++ b/src/boost/libs/bimap/index.html @@ -0,0 +1,14 @@ +<html> +<head> +<meta http-equiv="refresh" content="0; URL=doc/html/index.html"> +</head> +<body> +Automatic redirection failed, please go to the +<a href="doc/html/index.html">Boost.Bimap documentation</a>. +<p>Copyright Matias Capeletto 2006-2007</p> +<p>Distributed under the Boost Software License, Version 1.0. (See accompanying file +<a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at +<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>). +</p> +</body> +</html> diff --git a/src/boost/libs/bimap/meta/libraries.json b/src/boost/libs/bimap/meta/libraries.json new file mode 100644 index 000000000..5956ae6f0 --- /dev/null +++ b/src/boost/libs/bimap/meta/libraries.json @@ -0,0 +1,15 @@ +{ + "key": "bimap", + "name": "Bimap", + "authors": [ + "Matias Capeletto" + ], + "description": "Bidirectional maps library for C++. With Boost.Bimap you can create associative containers in which both types can be used as key.", + "category": [ + "Containers", + "Data" + ], + "maintainers": [ + "Matias Capeletto <matias.capeletto -at- gmail.com>" + ] +} diff --git a/src/boost/libs/bimap/test/Jamfile.v2 b/src/boost/libs/bimap/test/Jamfile.v2 new file mode 100644 index 000000000..f7991ef0b --- /dev/null +++ b/src/boost/libs/bimap/test/Jamfile.v2 @@ -0,0 +1,83 @@ +# Boost.Bimap +# +# Copyright (c) 2006-2007 Matias Capeletto +# +# 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) + +# bring in rules for testing +import testing ; + + +test-suite "tagged_test" + : + [ run test_tagged.cpp ] + ; + + +test-suite "relation_test" + : + [ run test_structured_pair.cpp ] + [ run test_mutant.cpp ] + [ run test_mutant_relation.cpp ] + ; + + +test-suite "bimap_test" + : + + # Check library user interface + [ run test_bimap_set_of.cpp ] + [ run test_bimap_multiset_of.cpp ] + [ run test_bimap_unordered_set_of.cpp ] + [ run test_bimap_unordered_multiset_of.cpp ] + [ run test_bimap_list_of.cpp ] + [ run test_bimap_vector_of.cpp ] + + # Test bimap container + [ run test_bimap_ordered.cpp ] + [ run test_bimap_unordered.cpp ] + [ run test_bimap_sequenced.cpp : : : + <toolset>gcc-4.4.7,<variant>release:<build>no ] + [ run test_bimap_unconstrained.cpp ] + [ run test_bimap_assign.cpp ] + [ run test_bimap_property_map.cpp ] + [ run test_bimap_modify.cpp ] + [ run test_bimap_range.cpp ] + [ run test_bimap_operator_bracket.cpp ] + [ run test_bimap_lambda.cpp ] + [ run test_bimap_mutable.cpp ] + [ run test_bimap_extra.cpp ] + [ run test_bimap_convenience_header.cpp ] + [ run test_bimap_project.cpp ] + [ run test_bimap_serialization.cpp + /boost/serialization//boost_serialization ] + [ run test_bimap_info.cpp ] + ; + +test-suite "compile_fail_test" + : + + [ compile-fail compile_fail/test_bimap_mutable_1.cpp ] + [ compile-fail compile_fail/test_bimap_mutable_2.cpp ] + [ compile-fail compile_fail/test_bimap_mutable_3.cpp ] + [ compile-fail compile_fail/test_bimap_info_1.cpp ] + [ compile-fail compile_fail/test_bimap_info_2.cpp ] + [ compile-fail compile_fail/test_bimap_info_3.cpp ] + ; + +test-suite "bimap_and_boost" + : + [ run ../example/bimap_and_boost/property_map.cpp ] + [ run ../example/bimap_and_boost/range.cpp ] + [ run ../example/bimap_and_boost/foreach.cpp ] + [ run ../example/bimap_and_boost/lambda.cpp ] + [ run ../example/bimap_and_boost/assign.cpp ] + [ run ../example/bimap_and_boost/xpressive.cpp : : : + <toolset>gcc-10,<cxxstd>03:<build>no + <toolset>gcc-11,<cxxstd>03:<build>no ] + [ run ../example/bimap_and_boost/typeof.cpp ] + [ compile ../example/bimap_and_boost/serialization.cpp + /boost/serialization//boost_serialization ] + ; diff --git a/src/boost/libs/bimap/test/compile_fail/test_bimap_info_1.cpp b/src/boost/libs/bimap/test/compile_fail/test_bimap_info_1.cpp new file mode 100644 index 000000000..8c06df05a --- /dev/null +++ b/src/boost/libs/bimap/test/compile_fail/test_bimap_info_1.cpp @@ -0,0 +1,38 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +// Boost.Bimap +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/list_of.hpp> + + +void test_bimap_info_1() +{ + using namespace boost::bimaps; + + typedef bimap< int, list_of<int>, with_info<int> > bm_type; + bm_type bm; + bm.insert( bm_type::value_type(1,1) ); + + // fail test + { + const bm_type & cbm = bm; + cbm.begin()->info = 10; + } +} diff --git a/src/boost/libs/bimap/test/compile_fail/test_bimap_info_2.cpp b/src/boost/libs/bimap/test/compile_fail/test_bimap_info_2.cpp new file mode 100644 index 000000000..669973697 --- /dev/null +++ b/src/boost/libs/bimap/test/compile_fail/test_bimap_info_2.cpp @@ -0,0 +1,37 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +// Boost.Bimap +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/list_of.hpp> + + +void test_bimap_info_2() +{ + using namespace boost::bimaps; + + typedef bimap< int, list_of<int> > bm_type; + bm_type bm; + bm.insert( bm_type::value_type(1,1) ); + + // fail test + { + bm.begin()->info; + } +} diff --git a/src/boost/libs/bimap/test/compile_fail/test_bimap_info_3.cpp b/src/boost/libs/bimap/test/compile_fail/test_bimap_info_3.cpp new file mode 100644 index 000000000..6172b1777 --- /dev/null +++ b/src/boost/libs/bimap/test/compile_fail/test_bimap_info_3.cpp @@ -0,0 +1,37 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +// Boost.Bimap +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/list_of.hpp> + + +void test_bimap_info_3() +{ + using namespace boost::bimaps; + + typedef bimap< int, list_of<int> > bm_type; + bm_type bm; + bm.insert( bm_type::value_type(1,1) ); + + // fail test + { + bm.left.info_at(1); + } +} diff --git a/src/boost/libs/bimap/test/compile_fail/test_bimap_mutable_1.cpp b/src/boost/libs/bimap/test/compile_fail/test_bimap_mutable_1.cpp new file mode 100644 index 000000000..935f94bd3 --- /dev/null +++ b/src/boost/libs/bimap/test/compile_fail/test_bimap_mutable_1.cpp @@ -0,0 +1,38 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +// Boost.Bimap +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/list_of.hpp> + + +void test_bimap_mutable_1() +{ + using namespace boost::bimaps; + + typedef bimap< int, list_of<int> > bm_type; + bm_type bm; + bm.insert( bm_type::value_type(1,1) ); + + // fail test + { + const bm_type & cbm = bm; + cbm.begin()->right = 10; + } +} diff --git a/src/boost/libs/bimap/test/compile_fail/test_bimap_mutable_2.cpp b/src/boost/libs/bimap/test/compile_fail/test_bimap_mutable_2.cpp new file mode 100644 index 000000000..e9af2a31b --- /dev/null +++ b/src/boost/libs/bimap/test/compile_fail/test_bimap_mutable_2.cpp @@ -0,0 +1,38 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +// Boost.Bimap +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/list_of.hpp> + + +void test_bimap_mutable_2() +{ + using namespace boost::bimaps; + + typedef bimap< int, list_of<int> > 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; + } +} diff --git a/src/boost/libs/bimap/test/compile_fail/test_bimap_mutable_3.cpp b/src/boost/libs/bimap/test/compile_fail/test_bimap_mutable_3.cpp new file mode 100644 index 000000000..936519e79 --- /dev/null +++ b/src/boost/libs/bimap/test/compile_fail/test_bimap_mutable_3.cpp @@ -0,0 +1,37 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +// Boost.Bimap +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/list_of.hpp> + + +void test_bimap_mutable_3() +{ + using namespace boost::bimaps; + + typedef bimap< int, list_of<int> > bm_type; + bm_type bm; + bm.insert( bm_type::value_type(1,1) ); + + // fail test + { + bm.right.begin()->second = 10; + } +} diff --git a/src/boost/libs/bimap/test/test_bimap.hpp b/src/boost/libs/bimap/test/test_bimap.hpp new file mode 100644 index 000000000..078243562 --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap.hpp @@ -0,0 +1,614 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +#ifndef LIBS_BIMAP_TEST_BIMAP_TEST_HPP +#define LIBS_BIMAP_TEST_BIMAP_TEST_HPP + +#if defined(_MSC_VER) +#pragma once +#endif + +#include <boost/config.hpp> + +// std +#include <cassert> +#include <algorithm> +#include <iterator> + +#include <boost/lambda/lambda.hpp> +#include <boost/static_assert.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/utility.hpp> +#include <boost/next_prior.hpp> + +template< class Container, class Data > +void test_container(Container & c, const Data & d) +{ + assert( d.size() > 2 ); + + c.clear(); + + BOOST_TEST( c.size() == 0 ); + BOOST_TEST( c.empty() ); + + c.insert( *d.begin() ); + + c.insert( ++d.begin(),d.end() ); + + BOOST_TEST( c.size() == d.size() ); + + BOOST_TEST( c.size() <= c.max_size() ); + BOOST_TEST( ! c.empty() ); + + c.erase( c.begin() ); + + BOOST_TEST( c.size() == d.size() - 1 ); + + c.erase( c.begin(), c.end() ); + + BOOST_TEST( c.empty() ); + + c.insert( *d.begin() ); + + BOOST_TEST( c.size() == 1 ); + + c.insert( c.begin(), *(++d.begin()) ); + + BOOST_TEST( c.size() == 2 ); + + BOOST_TEST( c.begin() != c.end() ); +} + +template< class Container, class Data > +void test_sequence_container(Container & c, const Data & d) +{ + assert( d.size() > 2 ); + + c.clear(); + + BOOST_TEST( c.size() == 0 ); + BOOST_TEST( c.empty() ); + + c.push_front( * d.begin() ); + c.push_back ( *(++d.begin()) ); + + BOOST_TEST( c.front() == * c.begin() ); + BOOST_TEST( c.back () == *(++c.begin()) ); + + BOOST_TEST( c.size() == 2 ); + + BOOST_TEST( c.size() <= c.max_size() ); + BOOST_TEST( ! c.empty() ); + + c.erase( c.begin() ); + + BOOST_TEST( c.size() == 1 ); + + c.insert( c.begin(), *(++d.begin()) ); + + c.erase( c.begin(), c.end() ); + + BOOST_TEST( c.empty() ); + + c.push_front( *d.begin() ); + + BOOST_TEST( c.size() == 1 ); + + BOOST_TEST( c.begin() != c.end() ); + + c.clear(); + BOOST_TEST( c.empty() ); + + // assign + + c.assign(d.begin(),d.end()); + BOOST_TEST( c.size() == d.size() ); + BOOST_TEST( std::equal( c.begin(), c.end(), d.begin() ) ); + + c.assign(d.size(),*d.begin()); + BOOST_TEST( c.size() == d.size() ); + BOOST_TEST( *c.begin() == *d.begin() ); + + // Check insert(IterPos,InputIter,InputIter) + + c.clear(); + c.insert( c.begin(), d.begin(), d.end() ); + c.insert( boost::next(c.begin(),2), d.begin(), d.end() ); + + BOOST_TEST( std::equal( boost::next(c.begin(),2) + , boost::next(c.begin(),2+d.size()) , d.begin() ) ); + + // Check resize + + c.clear() ; + c.resize(4,*d.begin()); + BOOST_TEST( c.size() == 4 ); + BOOST_TEST( *c.begin() == *d.begin() ) ; + + BOOST_TEST( c == c ); + BOOST_TEST( ! ( c != c ) ); + BOOST_TEST( ! ( c < c ) ); + BOOST_TEST( ( c <= c ) ); + BOOST_TEST( ! ( c > c ) ); + BOOST_TEST( ( c >= c ) ); +} + +template< class Container, class Data > +void test_vector_container(Container & c, const Data & d) +{ + assert( d.size() > 2 ); + + c.clear() ; + c.reserve(2) ; + BOOST_TEST( c.capacity() >= 2 ) ; + c.assign(d.begin(),d.end()); + BOOST_TEST( c.capacity() >= c.size() ) ; + + BOOST_TEST( c[0] == *d.begin() ) ; + BOOST_TEST( c.at(1) == *boost::next(d.begin()) ); + + test_sequence_container(c,d) ; +} + +template< class Container, class Data > +void test_associative_container(Container & c, const Data & d) +{ + assert( d.size() > 2 ); + + c.clear(); + c.insert(d.begin(),d.end()); + + for( typename Data::const_iterator di = d.begin(), de = d.end(); + di != de; ++di ) + { + BOOST_TEST( c.find(*di) != c.end() ); + } + + typename Data::const_iterator da = d.begin(); + typename Data::const_iterator db = ++d.begin(); + + c.erase(*da); + + BOOST_TEST( c.size() == d.size()-1 ); + + BOOST_TEST( c.count(*da) == 0 ); + BOOST_TEST( c.count(*db) == 1 ); + + BOOST_TEST( c.find(*da) == c.end() ); + BOOST_TEST( c.find(*db) != c.end() ); + + BOOST_TEST( c.equal_range(*db).first != c.end() ); + + c.clear(); + + BOOST_TEST( c.equal_range(*da).first == c.end() ); +} + + +template< class Container > +void test_mapped_container(Container &) +{ + typedef BOOST_DEDUCED_TYPENAME Container:: value_type value_type ; + typedef BOOST_DEDUCED_TYPENAME Container:: key_type key_type ; + typedef BOOST_DEDUCED_TYPENAME Container:: data_type data_type ; + typedef BOOST_DEDUCED_TYPENAME Container::mapped_type mapped_type ; + + typedef BOOST_DEDUCED_TYPENAME + boost::is_same< key_type + , BOOST_DEDUCED_TYPENAME value_type::first_type + >::type test_key_type; + BOOST_STATIC_ASSERT(test_key_type::value); + + typedef BOOST_DEDUCED_TYPENAME + boost::is_same< data_type + , BOOST_DEDUCED_TYPENAME value_type::second_type + >::type test_data_type; + BOOST_STATIC_ASSERT(test_data_type::value); + + typedef BOOST_DEDUCED_TYPENAME + boost::is_same< mapped_type + , BOOST_DEDUCED_TYPENAME value_type::second_type + >::type test_mapped_type; + BOOST_STATIC_ASSERT(test_mapped_type::value); +} + +template< class Container, class Data > +void test_pair_associative_container(Container & c, const Data & d) +{ + test_mapped_container(c); + + assert( d.size() > 2 ); + + c.clear(); + c.insert(d.begin(),d.end()); + + for( typename Data::const_iterator di = d.begin(), de = d.end(); + di != de; ++di ) + { + BOOST_TEST( c.find(di->first) != c.end() ); + } + + typename Data::const_iterator da = d.begin(); + typename Data::const_iterator db = ++d.begin(); + + c.erase(da->first); + + BOOST_TEST( c.size() == d.size()-1 ); + + BOOST_TEST( c.count(da->first) == 0 ); + BOOST_TEST( c.count(db->first) == 1 ); + + BOOST_TEST( c.find(da->first) == c.end() ); + BOOST_TEST( c.find(db->first) != c.end() ); + + BOOST_TEST( c.equal_range(db->first).first != c.end() ); + + c.clear(); + + BOOST_TEST( c.equal_range(da->first).first == c.end() ); +} + + +template< class Container, class Data > +void test_simple_ordered_associative_container_equality(Container & c, const Data & d) +{ + BOOST_TEST( std::equal( c. begin(), c. end(), d. begin() ) ); + BOOST_TEST( std::equal( c.rbegin(), c.rend(), d.rbegin() ) ); + + BOOST_TEST( c.lower_bound( *d.begin() ) == c.begin() ); + BOOST_TEST( c.upper_bound( *d.begin() ) == ++c.begin() ); +} + +template< class Container, class Data > +void test_simple_ordered_associative_container(Container & c, const Data & d) +{ + assert( d.size() > 2 ); + + c.clear(); + c.insert(d.begin(),d.end()); + + for( typename Data::const_iterator di = d.begin(), de = d.end(); + di != de; ++di ) + { + typename Container::const_iterator ci = c.find(*di); + BOOST_TEST( ci != c.end() ); + + BOOST_TEST( ! c.key_comp()(*ci,*di) ); + BOOST_TEST( ! c.value_comp()(*ci,*di) ); + } + + test_simple_ordered_associative_container_equality(c, d); + + const Container & cr = c; + + test_simple_ordered_associative_container_equality(cr, d); + + BOOST_TEST( c == c ); + BOOST_TEST( ! ( c != c ) ); + BOOST_TEST( ! ( c < c ) ); + BOOST_TEST( ( c <= c ) ); + BOOST_TEST( ! ( c > c ) ); + BOOST_TEST( ( c >= c ) ); + + /* + BOOST_TEST( c.range( *c.begin() <= ::boost::lambda::_1, + ::boost::lambda::_1 <= *(++c.begin()) ). + first == c.begin() + ); + */ +} + +template< class Container, class Data > +void test_simple_unordered_associative_container(Container & c, const Data & d) +{ + c.clear(); + c.insert( d.begin(), d.end() ); + + BOOST_TEST( c.bucket_count() * c.max_load_factor() >= d.size() ); + BOOST_TEST( c.max_bucket_count() >= c.bucket_count() ); + + for( typename Data::const_iterator di = d.begin(), de = d.end() ; + di != de ; ++di ) + { + // non const + { + typename Container::size_type nb = c.bucket(*c.find(*di)); + + BOOST_TEST( c.begin(nb) != c.end(nb) ); + } + + // const + { + const Container & const_c = c; + + BOOST_TEST( + const_c.bucket_size(const_c.bucket(*di)) == 1 + ); + + typename Container::size_type nb = + const_c.bucket(*const_c.find(*di)); + + BOOST_TEST( + const_c.begin(nb) != const_c.end(nb) + ); + } + } + + + BOOST_TEST( c.load_factor() < c.max_load_factor() ); + + c.max_load_factor(0.75); + + BOOST_TEST( c.max_load_factor() == 0.75 ); + + c.rehash(10); +} + + +template< class Container, class Data > +void test_pair_ordered_associative_container_equality(Container & c, const Data & d) +{ + BOOST_TEST( std::equal( c. begin(), c. end(), d. begin() ) ); + BOOST_TEST( std::equal( c.rbegin(), c.rend(), d.rbegin() ) ); + + BOOST_TEST( c.lower_bound( d.begin()->first ) == c.begin() ); + BOOST_TEST( c.upper_bound( d.begin()->first ) == ++c.begin() ); +} + +template< class Container, class Data > +void test_pair_ordered_associative_container(Container & c, const Data & d) +{ + assert( d.size() > 2 ); + + c.clear(); + c.insert(d.begin(),d.end()); + + for( typename Container::const_iterator ci = c.begin(), ce = c.end(); + ci != ce; ++ci ) + { + typename Data::const_iterator di = d.find(ci->first); + BOOST_TEST( di != d.end() ); + BOOST_TEST( ! c.key_comp()(di->first,ci->first) ); + BOOST_TEST( ! c.value_comp()(*ci,*di) ); + } + + test_pair_ordered_associative_container_equality(c, d); + + const Container & cr = c; + + test_pair_ordered_associative_container_equality(cr, d); + + BOOST_TEST( c.range( c.begin()->first <= ::boost::lambda::_1, + ::boost::lambda::_1 <= (++c.begin())->first ). + first == c.begin() + ); +} + + +template< class Container, class Data > +void test_pair_unordered_associative_container(Container & c, const Data & d) +{ + c.clear(); + c.insert( d.begin(), d.end() ); + + BOOST_TEST( c.bucket_count() * c.max_load_factor() >= d.size() ); + BOOST_TEST( c.max_bucket_count() >= c.bucket_count() ); + + for( typename Data::const_iterator di = d.begin(), de = d.end() ; + di != de ; ++di ) + { + // non const + { + typename Container::size_type nb = + c.bucket(c.find(di->first)->first); + + BOOST_TEST( c.begin(nb) != c.end(nb) ); + } + + // const + { + const Container & const_c = c; + +#if !defined(_M_IX86) // fails on Windows x86 (collisions?) + + BOOST_TEST_EQ( const_c.bucket_size(const_c.bucket(di->first)), 1 ); + +#endif + + typename Container::size_type nb = + const_c.bucket(const_c.find(di->first)->first); + + BOOST_TEST( const_c.begin(nb) != const_c.end(nb) ); + } + } + + + BOOST_TEST( c.load_factor() < c.max_load_factor() ); + + c.max_load_factor(0.75); + + BOOST_TEST( c.max_load_factor() == 0.75 ); + + c.rehash(10); +} + + +template< class Container, class Data > +void test_unique_container(Container & c, Data & d) +{ + c.clear(); + c.insert(d.begin(),d.end()); + c.insert(*d.begin()); + BOOST_TEST( c.size() == d.size() ); +} + +template< class Container, class Data > +void test_non_unique_container(Container & c, Data & d) +{ + c.clear(); + c.insert(d.begin(),d.end()); + c.insert(*d.begin()); + BOOST_TEST( c.size() == (d.size()+1) ); +} + + + +template< class Bimap, class Data, class LeftData, class RightData > +void test_basic_bimap( Bimap & b, + const Data & d, + const LeftData & ld, const RightData & rd) +{ + using namespace boost::bimaps; + + test_container(b,d); + + BOOST_TEST( & b.left == & b.template by<member_at::left >() ); + BOOST_TEST( & b.right == & b.template by<member_at::right>() ); + + test_container(b.left , ld); + test_container(b.right, rd); +} + +template< class LeftTag, class RightTag, class Bimap, class Data > +void test_tagged_bimap(Bimap & b, + const Data & d) +{ + using namespace boost::bimaps; + + BOOST_TEST( &b.left == & b.template by<LeftTag >() ); + BOOST_TEST( &b.right == & b.template by<RightTag>() ); + + b.clear(); + b.insert( *d.begin() ); + + BOOST_TEST( + b.begin()->template get<LeftTag>() == + b.template by<RightTag>().begin()->template get<LeftTag>() + ); + + BOOST_TEST( + b.begin()->template get<RightTag>() == + b.template by<LeftTag>().begin()->template get<RightTag>() + ); + + // const test + { + + const Bimap & bc = b; + + BOOST_TEST( &bc.left == & bc.template by<LeftTag>() ); + BOOST_TEST( &bc.right == & bc.template by<RightTag>() ); + + BOOST_TEST( bc.begin()->template get<LeftTag>() == + bc.template by<RightTag>().begin()->template get<LeftTag>() ); + + BOOST_TEST( bc.begin()->template get<RightTag>() == + bc.template by<LeftTag>().begin()->template get<RightTag>() ); + } +} + + +template< class Bimap, class Data, class LeftData, class RightData > +void test_set_set_bimap(Bimap & b, + const Data & d, + const LeftData & ld, const RightData & rd) +{ + using namespace boost::bimaps; + + test_basic_bimap(b,d,ld,rd); + + test_associative_container(b,d); + test_simple_ordered_associative_container(b,d); + + test_pair_associative_container(b.left, ld); + test_pair_ordered_associative_container(b.left, ld); + test_unique_container(b.left, ld); + + test_pair_associative_container(b.right, rd); + test_pair_ordered_associative_container(b.right, rd); + test_unique_container(b.right, rd); + +} + + +template< class Bimap, class Data, class LeftData, class RightData > +void test_multiset_multiset_bimap(Bimap & b, + const Data & d, + const LeftData & ld, const RightData & rd) +{ + using namespace boost::bimaps; + + test_basic_bimap(b,d,ld,rd); + test_associative_container(b,d); + test_simple_ordered_associative_container(b,d); + + test_pair_associative_container(b.left, ld); + test_pair_ordered_associative_container(b.left, ld); + test_non_unique_container(b.left, ld); + + test_pair_associative_container(b.right, rd); + test_pair_ordered_associative_container(b.right, rd); + test_non_unique_container(b.right, rd); +} + +template< class Bimap, class Data, class LeftData, class RightData > +void test_unordered_set_unordered_multiset_bimap(Bimap & b, + const Data & d, + const LeftData & ld, + const RightData & rd) +{ + using namespace boost::bimaps; + + test_basic_bimap(b,d,ld,rd); + test_associative_container(b,d); + test_simple_unordered_associative_container(b,d); + + test_pair_associative_container(b.left, ld); + test_pair_unordered_associative_container(b.left, ld); + test_unique_container(b.left, ld); + + test_pair_associative_container(b.right, rd); + test_pair_unordered_associative_container(b.right, rd); + + // Caution, this side is a non unique container, but the other side is a + // unique container so, the overall bimap is a unique one. + test_unique_container(b.right, rd); +} + +template< class Bimap, class Data> +void test_bimap_init_copy_swap(const Data&d) +{ + Bimap b1(d.begin(),d.end()); + Bimap b2( b1 ); + BOOST_TEST( b1 == b2 ); + + b2.clear(); + b2 = b1; + BOOST_TEST( b2 == b1 ); + + b2.clear(); + b2.left = b1.left; + BOOST_TEST( b2 == b1 ); + + b2.clear(); + 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_TEST( b1.empty() && !b2.empty() ); + + b1.right.swap( b2.right ); + BOOST_TEST( b2.empty() && !b1.empty() ); +} + +#endif // LIBS_BIMAP_TEST_BIMAP_TEST_HPP + diff --git a/src/boost/libs/bimap/test/test_bimap_assign.cpp b/src/boost/libs/bimap/test/test_bimap_assign.cpp new file mode 100644 index 000000000..13b620e15 --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_assign.cpp @@ -0,0 +1,86 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +// std +#include <sstream> +#include <algorithm> +#include <set> + +// Boost +#include <boost/assign/list_of.hpp> +#include <boost/assign/list_inserter.hpp> + +// Boost.Bimap +#include <boost/bimap/list_of.hpp> +#include <boost/bimap/unordered_multiset_of.hpp> +#include <boost/bimap/vector_of.hpp> +#include <boost/bimap/bimap.hpp> + +namespace ba = boost::assign; + + +void test_bimap_assign() +{ + using namespace boost::bimaps; + + // test + { + typedef bimap< list_of<int>, double > bm_type; + bm_type bm = ba::list_of< bm_type::relation >(1,0.1)(2,0.2)(3,0.3); + ba::push_back( bm )(4,0.4)(5,0.5); + ba::insert( bm.right )(0.5,5)(0.6,6); + ba::push_back( bm.left )(6,0.6)(7,0.7); + } + + // test + { + typedef bimap< unordered_multiset_of<int>, vector_of<double>, + list_of_relation > bm_type; + bm_type bm = ba::list_of< bm_type::relation >(1,0.1)(2,0.2)(3,0.3); + ba::push_front( bm )(4,0.4)(5,0.5); + ba::push_back( bm.right )(0.6,6)(0.7,7); + ba::insert( bm.left )(8,0.8)(9,0.9); + } + + // test + { + typedef bimap< int, vector_of<double>, right_based > bm_type; + bm_type bm = ba::list_of< bm_type::relation >(1,0.1)(2,0.2)(3,0.3); + ba::push_back( bm )(4,0.4)(5,0.5); + ba::push_back( bm.right )(0.6,6)(0.7,7); + ba::insert( bm.left )(8,0.8)(9,0.9); + } + + // test + { + typedef bimap< int, vector_of<double>, set_of_relation<> > bm_type; + bm_type bm = ba::list_of< bm_type::relation >(1,0.1)(2,0.2)(3,0.3); + ba::insert( bm )(4,0.4)(5,0.5); + ba::push_back( bm.right )(0.6,6)(0.7,7); + ba::insert( bm.left )(8,0.8)(9,0.9); + } +} + + +int main() +{ + test_bimap_assign(); + return 0; +} + diff --git a/src/boost/libs/bimap/test/test_bimap_convenience_header.cpp b/src/boost/libs/bimap/test/test_bimap_convenience_header.cpp new file mode 100644 index 000000000..3455674e0 --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_convenience_header.cpp @@ -0,0 +1,37 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/lightweight_test.hpp> + +#include <boost/bimap.hpp> + +void test_bimap_convenience_header() +{ + typedef boost::bimap< int, double > bm_type; + bm_type bm; + bm.insert( bm_type::value_type(1,0.1) ); + BOOST_TEST( bm.right.at(0.1) == 1 ); +} + +int main() +{ + test_bimap_convenience_header(); + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_extra.cpp b/src/boost/libs/bimap/test/test_bimap_extra.cpp new file mode 100644 index 000000000..d4887cdc3 --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_extra.cpp @@ -0,0 +1,95 @@ + // Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/static_assert.hpp> +#include <boost/type_traits/is_same.hpp> + +// Boost.Bimap +#include <boost/bimap/support/lambda.hpp> +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/list_of.hpp> + +// Support metafunctions +#include <boost/bimap/support/data_type_by.hpp> +#include <boost/bimap/support/key_type_by.hpp> +#include <boost/bimap/support/map_type_by.hpp> +#include <boost/bimap/support/value_type_by.hpp> +#include <boost/bimap/support/iterator_type_by.hpp> +#include <boost/bimap/relation/support/pair_type_by.hpp> + +using namespace boost::bimaps; +using namespace boost::bimaps::support; +using namespace boost::bimaps::relation::support ; + +typedef bimap<int, unconstrained_set_of<double> > bm_type; + +namespace support_metafunctions_test { + + typedef boost::is_same + < + data_type_by< member_at::left , bm_type >::type, + key_type_by < member_at::right, bm_type >::type + + >::type test_metafunction_1; + BOOST_STATIC_ASSERT(test_metafunction_1::value); + + typedef boost::is_same + < + data_type_by< member_at::right, bm_type >::type, + key_type_by < member_at::left , bm_type >::type + + >::type test_metafunction_2; + BOOST_STATIC_ASSERT(test_metafunction_2::value); + + typedef boost::is_same + < + map_type_by < member_at::left , bm_type >::type::value_type, + value_type_by< member_at::left , bm_type >::type + + >::type test_metafunction_3; + BOOST_STATIC_ASSERT(test_metafunction_3::value); + + typedef boost::is_same + < + pair_type_by< member_at::left, bm_type::relation>::type, + value_type_by< member_at::left , bm_type >::type + + >::type test_metafunction_4; + BOOST_STATIC_ASSERT(test_metafunction_4::value); + +} // namespace support_metafunctions_test + +void test_bimap_extra() +{ + // extra tests + // --------------------------------------------------------------- + // This section test small things... when a group of this checks + // can be related it is moved to a separate unit test file. + + + +} + + +int main() +{ + test_bimap_extra(); + return 0; +} + diff --git a/src/boost/libs/bimap/test/test_bimap_info.cpp b/src/boost/libs/bimap/test/test_bimap_info.cpp new file mode 100644 index 000000000..c6d8a82bf --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_info.cpp @@ -0,0 +1,125 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/lightweight_test.hpp> + +#include <boost/config.hpp> + +#include <string> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/unordered_set_of.hpp> + + +int test_bimap_info() +{ + using namespace boost::bimaps; + + typedef bimap< double, unordered_set_of<int>, with_info<std::string> > bm_type; + + bm_type bm; + const bm_type & cbm = bm; + + // Insertion with info + bm .insert( bm_type:: value_type(1.1 , 1, "one" ) ); + bm.left .insert( bm_type:: left_value_type(2.2 , 2, "two" ) ); + bm.right.insert( bm_type::right_value_type( 3 , 3.3, "three" ) ); + + bm.begin()->info = "1"; + BOOST_TEST( bm.right.find(1)->info == "1" ); + + bm.left.find(2.2)->info = "2"; + BOOST_TEST( bm.right.find(2)->info == "2" ); + + bm.right.find(3)->info = "3"; + BOOST_TEST( bm.right.find(3)->info == "3" ); + + // Empty info insert + bm .insert( bm_type:: value_type(4.4 , 4) ); + bm. left.insert( bm_type:: left_value_type(5.5 , 5) ); + bm.right.insert( bm_type::right_value_type( 6 , 6.6) ); + + BOOST_TEST( bm.right.find(4)->info == "" ); + + bm.left.info_at(4.4) = "4"; + BOOST_TEST( bm.right.info_at(4) == "4" ); + BOOST_TEST( cbm.right.info_at(4) == "4" ); + + bm.right.info_at(5) = "5"; + BOOST_TEST( bm.left.info_at(5.5) == "5" ); + BOOST_TEST( cbm.left.info_at(5.5) == "5" ); + + return 0; +} + + +struct left {}; +struct right {}; +struct info {}; + +int test_tagged_bimap_info() +{ + using namespace boost::bimaps; + + typedef bimap< tagged<int,left>, + tagged<int,right>, + with_info<tagged<int,info> > > bm_type; + + bm_type bm; + const bm_type & cbm = bm; + + bm .insert( bm_type:: value_type(1,1,1) ); + bm.left .insert( bm_type:: left_value_type(2,2,2) ); + bm.right.insert( bm_type::right_value_type(3,3,3) ); + + bm.begin()->get<info>() = 10; + BOOST_TEST( bm.right.find(1)->get<info>() == 10 ); + BOOST_TEST( cbm.right.find(1)->get<info>() == 10 ); + + bm.left.find(2)->get<info>() = 20; + BOOST_TEST( bm.right.find(2)->get<info>() == 20 ); + BOOST_TEST( cbm.right.find(2)->get<info>() == 20 ); + + bm.right.find(3)->get<info>() = 30; + BOOST_TEST( bm.right.find(3)->get<info>() == 30 ); + BOOST_TEST( cbm.right.find(3)->get<info>() == 30 ); + + // Empty info insert + bm .insert( bm_type:: value_type(4,4) ); + bm. left.insert( bm_type:: left_value_type(5,5) ); + bm.right.insert( bm_type::right_value_type(6,6) ); + + bm.left.info_at(4) = 4; + BOOST_TEST( bm.right.info_at(4) == 4 ); + BOOST_TEST( cbm.right.info_at(4) == 4 ); + + bm.right.info_at(5) = 5; + BOOST_TEST( bm.left.info_at(5) == 5 ); + BOOST_TEST( cbm.left.info_at(5) == 5 ); + + return 0; +} + +int main() +{ + test_bimap_info(); + test_tagged_bimap_info(); + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_lambda.cpp b/src/boost/libs/bimap/test/test_bimap_lambda.cpp new file mode 100644 index 000000000..36320abce --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_lambda.cpp @@ -0,0 +1,46 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/lightweight_test.hpp> + +// Boost.Bimap +#include <boost/bimap/support/lambda.hpp> +#include <boost/bimap/bimap.hpp> + +void test_bimap_lambda() +{ + using namespace boost::bimaps; + + typedef bimap<int,double> bm; + + bm b; + b.insert( bm::value_type(1,0.1) ); + + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( b.left.modify_key ( b.left.begin(), _key = 2 ) ); + BOOST_TEST( b.left.modify_data( b.left.begin(), _data = 0.2 ) ); + BOOST_TEST( b.left.range( _key >= 1, _key < 3 ).first == b.left.begin() ); +} + +int main() +{ + test_bimap_lambda(); + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_list_of.cpp b/src/boost/libs/bimap/test/test_bimap_list_of.cpp new file mode 100644 index 000000000..c15cbd16f --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_list_of.cpp @@ -0,0 +1,33 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/ignore_unused.hpp> + +#include <boost/bimap/list_of.hpp> + +int main() +{ + typedef boost::bimaps::list_of<int> set_type; + typedef boost::bimaps::list_of_relation set_type_of_relation; + boost::ignore_unused<set_type>(); + boost::ignore_unused<set_type_of_relation>(); + + return 0; +} + diff --git a/src/boost/libs/bimap/test/test_bimap_modify.cpp b/src/boost/libs/bimap/test/test_bimap_modify.cpp new file mode 100644 index 000000000..c84164a9f --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_modify.cpp @@ -0,0 +1,248 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/lightweight_test.hpp> + +// Boost.Bimap +#include <boost/bimap/support/lambda.hpp> +#include <boost/bimap/bimap.hpp> + +struct id{}; + +void test_bimap_modify() +{ + using namespace boost::bimaps; + + typedef bimap<int,long> bm; + + bm b; + b.insert( bm::value_type(2,200) ); + + BOOST_TEST( b.left.at(2) == 200 ); + + bool result; + + // replace + //---------------------------------------------------------------------- + + // successful replace in left map view + { + bm::left_iterator i = b.left.begin(); + + result = b.left.replace( i, bm::left_value_type(1,100) ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( i->first == 1 && i->second == 100 ); + BOOST_TEST( b.left.at(1) == 100 ); + + result = b.left.replace_key( i, 2 ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( i->first == 2 && i->second == 100 ); + BOOST_TEST( b.left.at(2) == 100 ); + + result = b.left.replace_data( i, 200 ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( i->first == 2 && i->second == 200 ); + BOOST_TEST( b.left.at(2) == 200 ); + } + + // successful replace in right map view + { + bm::right_iterator i = b.right.begin(); + + result = b.right.replace( i, bm::right_value_type(100,1) ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( i->first == 100 && i->second == 1 ); + BOOST_TEST( b.right.at(100) == 1 ); + + result = b.right.replace_key( i, 200 ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( i->first == 200 && i->second == 1 ); + BOOST_TEST( b.right.at(200) == 1 ); + + result = b.right.replace_data( i, 2 ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( i->first == 200 && i->second == 2 ); + BOOST_TEST( b.right.at(200) == 2 ); + } + + // successful replace in set of relations view + { + bm::iterator i = b.begin(); + + result = b.replace( i, bm::value_type(1,100) ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( i->left == 1 && i->right == 100 ); + BOOST_TEST( b.left.at(1) == 100 ); + + result = b.replace_left( i, 2 ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( i->left == 2 && i->right == 100 ); + BOOST_TEST( b.left.at(2) == 100 ); + + result = b.replace_right( b.begin(), 200 ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( i->left == 2 && i->right == 200 ); + BOOST_TEST( b.left.at(2) == 200 ); + + } + + b.clear(); + b.insert( bm::value_type(1,100) ); + b.insert( bm::value_type(2,200) ); + + // fail to replace in left map view + { + bm::left_iterator i = b.left.begin(); + + result = b.left.replace( i, bm::left_value_type(2,100) ); + + BOOST_TEST( ! result ); + BOOST_TEST( b.size() == 2 ); + BOOST_TEST( i->first == 1 && i->second == 100 ); + BOOST_TEST( b.left.at(1) == 100 ); + BOOST_TEST( b.left.at(2) == 200 ); + + + // Add checks for replace_key and replace_data + } + + // Add checks for fail to replace in right map view + + // Add checks for fail to replace in set of relations view + + + // modify + // ---------------------------------------------------------------------- + + b.clear(); + b.insert( bm::value_type(1,100) ); + + // successful modify in left map view + { + result = b.left.modify_key( b.left.begin(), _key = 2 ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( b.left.at(2) == 100 ); + + result = b.left.modify_data( b.left.begin() , _data = 200 ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( b.left.at(2) == 200 ); + } + + // Add checks for successful modify in right map view + + // Add checks for fails to modify in left map view + + +} + +void test_bimap_replace_with_info() +{ + using namespace boost::bimaps; + typedef bimap<int,long,with_info<int> > bm; + + bm b; + b.insert( bm::value_type(2,200,-2) ); + + BOOST_TEST( b.left.at(2) == 200 ); + BOOST_TEST( b.left.info_at(2) == -2 ); + + // Use set view + { + bm::iterator i = b.begin(); + + bool result = b.replace( i, bm::value_type(1,100,-1) ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( i->left == 1 && i->right == 100 ); + BOOST_TEST( i->info == -1 ); + + result = b.replace_left( i, 2 ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( i->left == 2 && i->right == 100 ); + BOOST_TEST( i->info == -1 ); + + result = b.replace_right( i, 200 ); + + BOOST_TEST( result ); + BOOST_TEST( b.size() == 1 ); + BOOST_TEST( i->left == 2 && i->right == 200 ); + BOOST_TEST( i->info == -1 ); + } + + // Use map view + { + bm::left_iterator i = b.left.begin(); + + bool result = b.left.replace( i, bm::left_value_type(1,100,-1) ); + + BOOST_TEST( result ); + BOOST_TEST( b.left.size() == 1 ); + BOOST_TEST( i->first == 1 && i->second == 100 ); + BOOST_TEST( i->info == -1 ); + + result = b.left.replace_key( i, 2 ); + + BOOST_TEST( result ); + BOOST_TEST( b.left.size() == 1 ); + BOOST_TEST( i->first == 2 && i->second == 100 ); + BOOST_TEST( i->info == -1 ); + + result = b.left.replace_data( i, 200 ); + + BOOST_TEST( result ); + BOOST_TEST( b.left.size() == 1 ); + BOOST_TEST( i->first == 2 && i->second == 200 ); + BOOST_TEST( i->info == -1 ); + } +} + +int main() +{ + test_bimap_modify(); + + test_bimap_replace_with_info(); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_multiset_of.cpp b/src/boost/libs/bimap/test/test_bimap_multiset_of.cpp new file mode 100644 index 000000000..18dfd288c --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_multiset_of.cpp @@ -0,0 +1,33 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/ignore_unused.hpp> + +#include <boost/bimap/multiset_of.hpp> + +int main() +{ + typedef boost::bimaps::multiset_of<int> set_type; + typedef boost::bimaps::multiset_of_relation<> set_type_of_relation; + boost::ignore_unused<set_type>(); + boost::ignore_unused<set_type_of_relation>(); + + return 0; +} + diff --git a/src/boost/libs/bimap/test/test_bimap_mutable.cpp b/src/boost/libs/bimap/test/test_bimap_mutable.cpp new file mode 100644 index 000000000..287f35fa3 --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_mutable.cpp @@ -0,0 +1,108 @@ + // Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/lightweight_test.hpp> + +// Boost.Bimap +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/list_of.hpp> +#include <boost/bimap/vector_of.hpp> +#include <boost/bimap/unconstrained_set_of.hpp> + +using namespace boost::bimaps; + +template< class BimapType > +void test_bimap_mutable() +{ + typedef BimapType bm_type; + + bm_type bm; + bm.insert( BOOST_DEDUCED_TYPENAME bm_type::value_type(1,0.1) ); + + const bm_type & cbm = bm; + + // Map Mutable Iterator test + { + + BOOST_DEDUCED_TYPENAME bm_type::left_iterator iter = bm.left.begin(); + iter->second = 0.2; + BOOST_TEST( iter->second == bm.left.begin()->second ); + + BOOST_DEDUCED_TYPENAME bm_type::left_const_iterator citer = bm.left.begin(); + BOOST_TEST( citer->second == bm.left.begin()->second ); + + BOOST_DEDUCED_TYPENAME bm_type::left_const_iterator cciter = cbm.left.begin(); + BOOST_TEST( cciter->second == cbm.left.begin()->second ); + + } + + // Set Mutable Iterator test + { + + BOOST_DEDUCED_TYPENAME bm_type::iterator iter = bm.begin(); + iter->right = 0.1; + BOOST_TEST( iter->right == bm.begin()->right ); + + BOOST_DEDUCED_TYPENAME bm_type::const_iterator citer = bm.begin(); + BOOST_TEST( citer->right == bm.begin()->right ); + + BOOST_DEDUCED_TYPENAME bm_type::const_iterator cciter = cbm.begin(); + BOOST_TEST( cciter->left == cbm.begin()->left ); + + } + + // Map Assignable Reference test + { + + BOOST_DEDUCED_TYPENAME bm_type::left_reference r = *bm.left.begin(); + r.second = 0.2; + BOOST_TEST( r == *bm.left.begin() ); + + BOOST_DEDUCED_TYPENAME bm_type::left_const_reference cr = *bm.left.begin(); + BOOST_TEST( cr == *bm.left.begin() ); + + BOOST_DEDUCED_TYPENAME bm_type::left_const_reference ccr = *cbm.left.begin(); + BOOST_TEST( ccr == *cbm.left.begin() ); + + } + + // Set Assignable Reference test + { + + BOOST_DEDUCED_TYPENAME bm_type::reference r = *bm.begin(); + r.right = 0.1; + BOOST_TEST( r == *bm.begin() ); + + BOOST_DEDUCED_TYPENAME bm_type::const_reference cr = *bm.begin(); + BOOST_TEST( cr == *bm.begin() ); + + BOOST_DEDUCED_TYPENAME bm_type::const_reference ccr = *cbm.begin(); + BOOST_TEST( ccr == *bm.begin() ); + + } +} + +int main() +{ + test_bimap_mutable< bimap< int, list_of<double> > >(); + test_bimap_mutable< bimap< int, vector_of<double> > >(); + test_bimap_mutable< bimap< int, unconstrained_set_of<double> > >(); + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_operator_bracket.cpp b/src/boost/libs/bimap/test/test_bimap_operator_bracket.cpp new file mode 100644 index 000000000..06bfc6307 --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_operator_bracket.cpp @@ -0,0 +1,198 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/ignore_unused.hpp> +#include <boost/core/lightweight_test.hpp> + +// Boost.Bimap +#include <boost/bimap/support/lambda.hpp> +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/unordered_set_of.hpp> +#include <boost/bimap/list_of.hpp> +#include <boost/bimap/vector_of.hpp> +#include <boost/bimap/unconstrained_set_of.hpp> + + +void test_bimap_operator_bracket() +{ + using namespace boost::bimaps; + + // Simple test + { + typedef bimap< int, std::string > bm; + + bm b; + b.insert( bm::value_type(0,"0") ); + b.insert( bm::value_type(1,"1") ); + b.insert( bm::value_type(2,"2") ); + b.insert( bm::value_type(3,"3") ); + + BOOST_TEST( b.left.at(1) == "1" ); + + // Out of range test + { + bool value_not_found_test_passed = false; + b.clear(); + try + { + bool comp; + comp = b.left.at(2) < "banana"; + boost::ignore_unused(comp); + } + catch( std::out_of_range & ) + { + value_not_found_test_passed = true; + } + + BOOST_TEST( value_not_found_test_passed ); + } + } + + // Mutable data test (1) + { + typedef bimap<int, list_of<std::string> > bm; + bm b; + + // Out of range test + { + bool value_not_found_test_passed = false; + b.clear(); + try + { + bool comp; + comp = b.left.at(1) < "banana"; + boost::ignore_unused(comp); + } + catch( std::out_of_range & ) + { + value_not_found_test_passed = true; + } + + BOOST_TEST( value_not_found_test_passed ); + + } + + // Out of range test (const version) + { + bool value_not_found_test_passed = false; + b.clear(); + try + { + const bm & cb(b); + bool comp; + comp = cb.left.at(1) < "banana"; + boost::ignore_unused(comp); + } + catch( std::out_of_range & ) + { + value_not_found_test_passed = true; + } + + BOOST_TEST( value_not_found_test_passed ); + } + + BOOST_TEST( b.left[1] == "" ); + BOOST_TEST( b.left.at(1) == "" ); + b.left[2] = "two"; + BOOST_TEST( b.left.at(2) == "two" ); + b.left[2] = "<<two>>"; + BOOST_TEST( b.left.at(2) == "<<two>>" ); + b.left.at(2) = "two"; + BOOST_TEST( b.left.at(2) == "two" ); + + } + + // Mutable data test (2) + { + typedef bimap< vector_of<int>, unordered_set_of<std::string> > bm; + bm b; + + // Out of range test + { + bool value_not_found_test_passed = false; + b.clear(); + try + { + bool comp; + comp = b.right.at("banana") < 1; + boost::ignore_unused(comp); + } + catch( std::out_of_range & ) + { + value_not_found_test_passed = true; + } + BOOST_TEST( value_not_found_test_passed ); + } + + // Out of range test (const version) + { + bool value_not_found_test_passed = false; + b.clear(); + try + { + const bm & cb(b); + bool comp; + comp = cb.right.at("banana") < 1; + boost::ignore_unused(comp); + } + catch( std::out_of_range & ) + { + value_not_found_test_passed = true; + } + + BOOST_TEST( value_not_found_test_passed ); + } + + b.right["one"]; + BOOST_TEST( b.size() == 1 ); + b.right["two"] = 2; + BOOST_TEST( b.right.at("two") == 2 ); + b.right["two"] = -2; + BOOST_TEST( b.right.at("two") == -2 ); + b.right.at("two") = 2; + BOOST_TEST( b.right.at("two") == 2 ); + } + + // Mutable data test (3) + { + typedef bimap< unconstrained_set_of<int>, + unordered_set_of<std::string>, + right_based > bm; + + bm b; + + b.right["one"]; + BOOST_TEST( b.size() == 1 ); + b.right["two"] = 2; + BOOST_TEST( b.right.at("two") == 2 ); + b.right["two"] = -2; + BOOST_TEST( b.right.at("two") == -2 ); + b.right.at("two") = 2; + BOOST_TEST( b.right.at("two") == 2 ); + } + +} + +int main() +{ + test_bimap_operator_bracket(); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_ordered.cpp b/src/boost/libs/bimap/test/test_bimap_ordered.cpp new file mode 100644 index 000000000..ec0d9244b --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_ordered.cpp @@ -0,0 +1,175 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#define BOOST_BIMAP_DISABLE_SERIALIZATION + +#include <boost/core/lightweight_test.hpp> + +// std +#include <set> +#include <map> +#include <string> +#include <functional> + +// Set type specifications +#include <boost/bimap/set_of.hpp> +#include <boost/bimap/multiset_of.hpp> + +// bimap container +#include <boost/bimap/bimap.hpp> + +#include <libs/bimap/test/test_bimap.hpp> + +struct left_tag {}; +struct right_tag {}; + +void test_bimap() +{ + using namespace boost::bimaps; + + typedef std::map<int,double> 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<double,int> 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<int, left_tag > >, + multiset_of< tagged<double, right_tag > >, + 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<left_tag,right_tag>(bm,data); + } + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + { + typedef bimap<int,double,right_based> 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<int> >, set_of<std::string> , + 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_TEST( b1.empty() && !b2.empty() ); + + b1.right.swap( b2.right ); + BOOST_TEST( b2.empty() && !b1.empty() ); + } + //-------------------------------------------------------------------- + +} + + +int main() +{ + test_bimap(); + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_project.cpp b/src/boost/libs/bimap/test/test_bimap_project.cpp new file mode 100644 index 000000000..32066a555 --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_project.cpp @@ -0,0 +1,142 @@ + // Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/lightweight_test.hpp> + +#include <string> + +// Boost.Bimap +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/list_of.hpp> + +using namespace boost::bimaps; + +struct left_tag {}; +struct right_tag {}; + +void test_bimap_project() +{ + typedef bimap + < + tagged< int , left_tag >, + list_of< tagged< std::string, right_tag > > + + > bm_type; + + bm_type bm; + + bm.insert( bm_type::value_type(1,"1") ); + bm.insert( bm_type::value_type(2,"2") ); + + bm_type:: iterator iter = bm.begin(); + bm_type:: left_iterator left_iter = bm.left.find(1); + bm_type::right_iterator right_iter = bm.right.begin(); + + const bm_type & cbm = bm; + + bm_type:: const_iterator citer = cbm.begin(); + bm_type:: left_const_iterator left_citer = cbm.left.find(1); + bm_type::right_const_iterator right_citer = cbm.right.begin(); + + // non const projection + + BOOST_TEST( bm.project_up (bm.end()) == bm.end() ); + BOOST_TEST( bm.project_left (bm.end()) == bm.left.end() ); + BOOST_TEST( bm.project_right(bm.end()) == bm.right.end() ); + + BOOST_TEST( bm.project_up (iter) == iter ); + BOOST_TEST( bm.project_left (iter) == left_iter ); + BOOST_TEST( bm.project_right(iter) == right_iter ); + + BOOST_TEST( bm.project_up (left_iter) == iter ); + BOOST_TEST( bm.project_left (left_iter) == left_iter ); + BOOST_TEST( bm.project_right(left_iter) == right_iter ); + + BOOST_TEST( bm.project_up (right_iter) == iter ); + BOOST_TEST( bm.project_left (right_iter) == left_iter ); + BOOST_TEST( bm.project_right(right_iter) == right_iter ); + + bm.project_up ( left_iter)->right = "u"; + bm.project_left (right_iter)->second = "l"; + bm.project_right( iter)->first = "r"; + + // const projection + + BOOST_TEST( cbm.project_up (cbm.end()) == cbm.end() ); + BOOST_TEST( cbm.project_left (cbm.end()) == cbm.left.end() ); + BOOST_TEST( cbm.project_right(cbm.end()) == cbm.right.end() ); + + BOOST_TEST( cbm.project_up (citer) == citer ); + BOOST_TEST( cbm.project_left (citer) == left_citer ); + BOOST_TEST( cbm.project_right(citer) == right_citer ); + + BOOST_TEST( cbm.project_up (left_citer) == citer ); + BOOST_TEST( cbm.project_left (left_citer) == left_citer ); + BOOST_TEST( cbm.project_right(left_citer) == right_citer ); + + BOOST_TEST( cbm.project_up (right_citer) == citer ); + BOOST_TEST( cbm.project_left (right_citer) == left_citer ); + BOOST_TEST( cbm.project_right(right_citer) == right_citer ); + + // mixed projection + + BOOST_TEST( bm.project_up (left_citer) == iter ); + BOOST_TEST( bm.project_left (left_citer) == left_iter ); + BOOST_TEST( bm.project_right(left_citer) == right_iter ); + + BOOST_TEST( cbm.project_up (right_iter) == citer ); + BOOST_TEST( cbm.project_left (right_iter) == left_citer ); + BOOST_TEST( cbm.project_right(right_iter) == right_citer ); + + bm.project_up ( left_citer)->right = "u"; + bm.project_left (right_citer)->second = "l"; + bm.project_right( citer)->first = "r"; + + // Support for tags + + BOOST_TEST( bm.project< left_tag>(iter) == left_iter ); + BOOST_TEST( bm.project<right_tag>(iter) == right_iter ); + + BOOST_TEST( bm.project< left_tag>(left_iter) == left_iter ); + BOOST_TEST( bm.project<right_tag>(left_iter) == right_iter ); + + BOOST_TEST( bm.project< left_tag>(right_iter) == left_iter ); + BOOST_TEST( bm.project<right_tag>(right_iter) == right_iter ); + + BOOST_TEST( cbm.project< left_tag>(citer) == left_citer ); + BOOST_TEST( cbm.project<right_tag>(citer) == right_citer ); + + BOOST_TEST( cbm.project< left_tag>(left_citer) == left_citer ); + BOOST_TEST( cbm.project<right_tag>(left_citer) == right_citer ); + + BOOST_TEST( cbm.project< left_tag>(right_citer) == left_citer ); + BOOST_TEST( cbm.project<right_tag>(right_citer) == right_citer ); + + bm.project< left_tag>(right_citer)->second = "l"; + bm.project<right_tag>( left_citer)->first = "r"; + +} + + +int main() +{ + test_bimap_project(); + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_property_map.cpp b/src/boost/libs/bimap/test/test_bimap_property_map.cpp new file mode 100644 index 000000000..01f23a68e --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_property_map.cpp @@ -0,0 +1,75 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +// std +#include <set> +#include <map> +#include <cstddef> +#include <cassert> +#include <algorithm> + +#include <boost/core/lightweight_test.hpp> + +// Boost.Bimap + +#include <boost/bimap/set_of.hpp> +#include <boost/bimap/property_map/set_support.hpp> + +#include <boost/bimap/unordered_set_of.hpp> +#include <boost/bimap/property_map/unordered_set_support.hpp> + +#include <boost/bimap/bimap.hpp> + + +template <class Map> +void test_readable_property_map( + Map m, + typename boost::property_traits<Map>:: key_type const & key, + typename boost::property_traits<Map>::value_type const & value +) +{ + // TODO Add STATIC_ASSERT( + // boost::property_traits<Map>::category is readable ) + + BOOST_TEST( get(m,key) == value ); + //BOOST_TEST( m[key] == value ); +} + + +void test_bimap_property_map() +{ + using namespace boost::bimaps; + + typedef bimap< set_of<int>, unordered_set_of<double> > bm; + + bm b; + b.insert( bm::value_type(1,0.1) ); + b.insert( bm::value_type(2,0.2) ); + b.insert( bm::value_type(3,0.3) ); + + test_readable_property_map(b.left , 1,0.1); + test_readable_property_map(b.right,0.1, 1); +} + +int main() +{ + test_bimap_property_map(); + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_range.cpp b/src/boost/libs/bimap/test/test_bimap_range.cpp new file mode 100644 index 000000000..bf361f851 --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_range.cpp @@ -0,0 +1,135 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/ignore_unused.hpp> +#include <boost/core/lightweight_test.hpp> + +#include <boost/config.hpp> + +#include <algorithm> + +#include <boost/range/functions.hpp> +#include <boost/range/const_iterator.hpp> + +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/multiset_of.hpp> +#include <boost/bimap/support/lambda.hpp> + + +template< class ForwardReadableRange, class UnaryFunctor > +UnaryFunctor for_each(const ForwardReadableRange & r, UnaryFunctor func) +{ + typedef typename + boost::range_const_iterator<ForwardReadableRange>::type const_iterator; + + for(const_iterator i= boost::begin(r), iend= boost::end(r); i!=iend; ++i ) + { + func(*i); + } + + return func; +} + +struct do_something_with_a_pair +{ + template< class Pair > + void operator()(const Pair & p) + { + BOOST_TEST( p.first && p.second ); + } +}; + +int test_bimap_range() +{ + using namespace boost::bimaps; + + typedef bimap< double, multiset_of<int> > bm_type; + + + bm_type bm; + bm.insert( bm_type::value_type(1.1 , 1) ); + bm.insert( bm_type::value_type(2.2 , 2) ); + bm.insert( bm_type::value_type(3.3 , 3) ); + bm.insert( bm_type::value_type(4.4 , 4) ); + + + for_each( bm.left.range( 1.0 < _key, _key < 5.0 ), + do_something_with_a_pair() ); + + for_each( bm.right.range( unbounded, _key <= 2 ), + do_something_with_a_pair() ); + + + // left range + { + + bm_type::left_range_type r = bm.left.range( 2.0 < _key, _key < 4.0 ); + BOOST_TEST( ! boost::empty(r) ); + BOOST_TEST( boost::begin(r) == bm.left.upper_bound(2.0) ); + BOOST_TEST( boost::end(r) == bm.left.lower_bound(4.0) ); + + } + + // right range + { + + bm_type::right_range_type r = bm.right.range( 2 <= _key, _key <= 3 ); + BOOST_TEST( ! boost::empty(r) ); + BOOST_TEST( boost::begin(r) == bm.right.lower_bound(2) ); + BOOST_TEST( boost::end(r) == bm.right.upper_bound(3) ); + + } + + // const range from range + { + + bm_type:: left_const_range_type lr = bm. left.range( unbounded, _key < 4.0 ); + bm_type::right_const_range_type rr = bm.right.range( 2 < _key , unbounded ); + boost::ignore_unused(lr); + boost::ignore_unused(rr); + } + + const bm_type & cbm = bm; + + // left const range + { + bm_type:: left_const_range_type r = cbm.left.range( unbounded, unbounded ); + BOOST_TEST( ! boost::empty(r) ); + BOOST_TEST( boost::begin(r) == cbm.left.begin() ); + + } + + // right const range + { + + bm_type::right_const_range_type r = cbm.right.range( 1 < _key, _key < 1 ); + BOOST_TEST( boost::empty(r) ); + + } + + return 0; +} +//] + +int main() +{ + test_bimap_range(); + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_sequenced.cpp b/src/boost/libs/bimap/test/test_bimap_sequenced.cpp new file mode 100644 index 000000000..20616278d --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_sequenced.cpp @@ -0,0 +1,278 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#define BOOST_BIMAP_DISABLE_SERIALIZATION + +#include <boost/core/lightweight_test.hpp> + +// std +#include <set> +#include <map> +#include <algorithm> +#include <string> +#include <functional> + + +// Set type specifications +#include <boost/bimap/list_of.hpp> +#include <boost/bimap/vector_of.hpp> + +// bimap container +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/support/lambda.hpp> + +#include <libs/bimap/test/test_bimap.hpp> + +struct left_tag {}; +struct right_tag {}; + + +template< class Container, class Data > +void test_list_operations(Container & b, Container& c, const Data & d) +{ + c.clear() ; + c.assign(d.begin(),d.end()); + + BOOST_TEST( std::equal( c.begin(), c.end(), d.begin() ) ); + c.reverse(); + BOOST_TEST( std::equal( c.begin(), c.end(), d.rbegin() ) ); + + c.sort(); + BOOST_TEST( std::equal( c.begin(), c.end(), d.begin() ) ); + + c.push_front( *d.begin() ); + BOOST_TEST( c.size() == d.size()+1 ); + c.unique(); + BOOST_TEST( c.size() == d.size() ); + + c.relocate( c.begin(), ++c.begin() ); + c.relocate( c.end(), c.begin(), ++c.begin() ); + + b.clear(); + c.clear(); + + c.assign(d.begin(),d.end()); + b.splice(b.begin(),c); + + BOOST_TEST( c.size() == 0 ); + BOOST_TEST( b.size() == d.size() ); + + c.splice(c.begin(),b,++b.begin()); + + BOOST_TEST( c.size() == 1 ); + + c.splice(c.begin(),b,b.begin(),b.end()); + + BOOST_TEST( b.size() == 0 ); + + b.assign(d.begin(),d.end()); + c.assign(d.begin(),d.end()); + b.sort(); + c.sort(); + b.merge(c); + BOOST_TEST( b.size() == 2*d.size() ); + + b.unique(); +} + +void test_bimap() +{ + using namespace boost::bimaps; + + typedef std::map<std::string,long> left_data_type; + left_data_type left_data; + left_data.insert( left_data_type::value_type("1",1) ); + left_data.insert( left_data_type::value_type("2",2) ); + left_data.insert( left_data_type::value_type("3",3) ); + left_data.insert( left_data_type::value_type("4",4) ); + + typedef std::map<long,std::string> right_data_type; + right_data_type right_data; + right_data.insert( right_data_type::value_type(1,"1") ); + right_data.insert( right_data_type::value_type(2,"2") ); + right_data.insert( right_data_type::value_type(3,"3") ); + right_data.insert( right_data_type::value_type(4,"4") ); + + + //-------------------------------------------------------------------- + { + typedef bimap< + list_of< std::string >, vector_of< long > + + > bm_type; + + std::set< bm_type::value_type > data; + data.insert( bm_type::value_type("1",1) ); + data.insert( bm_type::value_type("2",2) ); + data.insert( bm_type::value_type("3",3) ); + data.insert( bm_type::value_type("4",4) ); + + bm_type b; + + test_bimap_init_copy_swap<bm_type>(data) ; + test_sequence_container(b,data); + test_sequence_container(b.left , left_data); + test_vector_container(b.right,right_data); + + test_mapped_container(b.left ); + test_mapped_container(b.right); + + bm_type c; + test_list_operations(b,c,data) ; + test_list_operations(b.left,c.left,left_data) ; + test_list_operations(b.right,c.right,right_data) ; + + c.assign(data.begin(),data.end()); + b.assign(data.begin(),data.end()); + c.remove_if(_key<=bm_type::value_type("1",1)); + c.sort(std::less<bm_type::value_type>()); + b.sort(std::less<bm_type::value_type>()); + c.merge(b,std::less<bm_type::value_type>()); + c.unique(std::equal_to<bm_type::value_type>()); + + c.assign(data.begin(),data.end()); + b.assign(data.begin(),data.end()); + c.left.remove_if(_key<="1"); + c.left.sort(std::less<std::string>()); + b.left.sort(std::less<std::string>()); + c.left.merge(b.left,std::less<std::string>()); + c.left.unique(std::equal_to<std::string>()); + + c.assign(data.begin(),data.end()); + b.assign(data.begin(),data.end()); + c.right.remove_if(_key<=1); + c.right.sort(std::less<long>()); + b.right.sort(std::less<long>()); + c.right.merge(b.right,std::less<long>()); + c.right.unique(std::equal_to<long>()); + + c.assign(data.begin(),data.end()); + c.right[0].first = -1; + c.right.at(0).second = "[1]"; + } + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + { + typedef bimap + < + vector_of<std::string>, list_of<long>, + vector_of_relation + + > bm_type; + + std::set< bm_type::value_type > data; + data.insert( bm_type::value_type("1",1) ); + data.insert( bm_type::value_type("2",2) ); + data.insert( bm_type::value_type("3",3) ); + data.insert( bm_type::value_type("4",4) ); + + bm_type b; + + test_bimap_init_copy_swap<bm_type>(data) ; + test_vector_container(b,data) ; + + bm_type c; + test_list_operations(b,c,data) ; + test_list_operations(b.left,c.left,left_data) ; + test_list_operations(b.right,c.right,right_data) ; + + c.assign(data.begin(),data.end()); + b.assign(data.begin(),data.end()); + c.remove_if(_key<=bm_type::value_type("1",1)); + c.sort(std::less<bm_type::value_type>()); + b.sort(std::less<bm_type::value_type>()); + c.merge(b,std::less<bm_type::value_type>()); + c.unique(std::equal_to<bm_type::value_type>()); + + c.assign(data.begin(),data.end()); + b.assign(data.begin(),data.end()); + c.left.remove_if(_key<="1"); + c.left.sort(std::less<std::string>()); + b.left.sort(std::less<std::string>()); + c.left.merge(b.left,std::less<std::string>()); + c.left.unique(std::equal_to<std::string>()); + + c.assign(data.begin(),data.end()); + b.assign(data.begin(),data.end()); + c.right.remove_if(_key<=1); + c.right.sort(std::less<long>()); + b.right.sort(std::less<long>()); + c.right.merge(b.right,std::less<long>()); + c.right.unique(std::equal_to<long>()); + + c.assign(data.begin(),data.end()); + c[0].left = "(1)"; + c.at(0).right = -1; + c.left[0].first = "[1]"; + c.left.at(0).second = -1; + } + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + { + typedef bimap + < + vector_of<std::string>, list_of<long>, + list_of_relation + + > bm_type; + + std::set< bm_type::value_type > data; + data.insert( bm_type::value_type("1",1) ); + data.insert( bm_type::value_type("2",2) ); + data.insert( bm_type::value_type("3",3) ); + data.insert( bm_type::value_type("4",4) ); + + bm_type b; + + test_bimap_init_copy_swap<bm_type>(data) ; + test_sequence_container(b,data) ; + + bm_type c; + test_list_operations(b,c,data) ; + test_list_operations(b.left,c.left,left_data) ; + test_list_operations(b.right,c.right,right_data) ; + + + c.assign(data.begin(),data.end()); + b.assign(data.begin(),data.end()); + c.remove_if(_key<=bm_type::value_type("1",1)); + c.sort(std::less<bm_type::value_type>()); + b.sort(std::less<bm_type::value_type>()); + c.merge(b,std::less<bm_type::value_type>()); + c.unique(std::equal_to<bm_type::value_type>()); + + c.assign(data.begin(),data.end()); + c.left[0].first = "[1]"; + c.left.at(0).second = -1; + } + //-------------------------------------------------------------------- + +} + + +int main() +{ + test_bimap(); + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_serialization.cpp b/src/boost/libs/bimap/test/test_bimap_serialization.cpp new file mode 100644 index 000000000..b736808a7 --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_serialization.cpp @@ -0,0 +1,113 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +// std +#include <set> +#include <map> +#include <cstddef> +#include <cassert> +#include <algorithm> +#include <sstream> +#include <algorithm> + +#include <boost/core/lightweight_test.hpp> + +// Boost +#include <boost/archive/text_oarchive.hpp> +#include <boost/archive/text_iarchive.hpp> + +// Boost.Bimap +#include <boost/bimap/bimap.hpp> + + +template< class Bimap, class Archive > +void save_bimap(const Bimap & b, Archive & ar) +{ + using namespace boost::bimaps; + + ar << b; + + const typename Bimap::left_const_iterator left_iter = b.left.begin(); + ar << left_iter; + + const typename Bimap::const_iterator iter = ++b.begin(); + ar << iter; +} + + + + +void test_bimap_serialization() +{ + using namespace boost::bimaps; + + typedef bimap<int,double> bm; + + std::set< bm::value_type > data; + data.insert( bm::value_type(1,0.1) ); + data.insert( bm::value_type(2,0.2) ); + data.insert( bm::value_type(3,0.3) ); + data.insert( bm::value_type(4,0.4) ); + + std::ostringstream oss; + + // Save it + { + bm b; + + b.insert(data.begin(),data.end()); + + boost::archive::text_oarchive oa(oss); + + save_bimap(b,oa); + } + + // Reload it + { + bm b; + + std::istringstream iss(oss.str()); + boost::archive::text_iarchive ia(iss); + + ia >> b; + + BOOST_TEST( std::equal( b.begin(), b.end(), data.begin() ) ); + + bm::left_const_iterator left_iter; + + ia >> left_iter; + + BOOST_TEST( left_iter == b.left.begin() ); + + bm::const_iterator iter; + + ia >> iter; + + BOOST_TEST( iter == ++b.begin() ); + } + +} + + +int main() +{ + test_bimap_serialization(); + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_set_of.cpp b/src/boost/libs/bimap/test/test_bimap_set_of.cpp new file mode 100644 index 000000000..952f911df --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_set_of.cpp @@ -0,0 +1,33 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/ignore_unused.hpp> + +#include <boost/bimap/set_of.hpp> + +int main() +{ + typedef boost::bimaps::set_of<int> set_type; + typedef boost::bimaps::set_of_relation<> set_type_of_relation; + boost::ignore_unused<set_type>(); + boost::ignore_unused<set_type_of_relation>(); + + return 0; +} + diff --git a/src/boost/libs/bimap/test/test_bimap_unconstrained.cpp b/src/boost/libs/bimap/test/test_bimap_unconstrained.cpp new file mode 100644 index 000000000..b0c0c5347 --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_unconstrained.cpp @@ -0,0 +1,108 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/lightweight_test.hpp> + +// Boost.Bimap +#include <boost/bimap/support/lambda.hpp> +#include <boost/bimap/bimap.hpp> + + +void test_bimap_unconstrained() +{ + using namespace boost::bimaps; + + { + typedef bimap<int,double,unconstrained_set_of_relation> 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<int,unconstrained_set_of<double> > bm; + bm b; + b.insert( bm::value_type(2,34.4) ); + BOOST_TEST( b.size() == 1 ); + } + + { + typedef bimap<unconstrained_set_of<int>, double > bm; + bm b; + b.right[2.4] = 34; + BOOST_TEST( b.right.size() == 1 ); + } + + { + typedef bimap<unconstrained_set_of<int>, double, right_based > bm; + bm b; + b.right[2.4] = 34; + BOOST_TEST( b.right.size() == 1 ); + } + + { + typedef bimap + < + int, + unconstrained_set_of<double>, + unconstrained_set_of_relation + + > bm; + + bm b; + b.left[2] = 34.4; + BOOST_TEST( b.left.size() == 1 ); + } + + { + typedef bimap + < + unconstrained_set_of<int>, + double, + unconstrained_set_of_relation + + > bm; + + bm b; + b.right[2.4] = 34; + BOOST_TEST( b.right.size() == 1 ); + } + + { + typedef bimap + < + unconstrained_set_of<int>, + unconstrained_set_of<double>, + 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(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_unordered.cpp b/src/boost/libs/bimap/test/test_bimap_unordered.cpp new file mode 100644 index 000000000..486072cda --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_unordered.cpp @@ -0,0 +1,166 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#define BOOST_BIMAP_DISABLE_SERIALIZATION + +#include <boost/core/lightweight_test.hpp> + +// std +#include <set> +#include <map> +#include <string> +#include <functional> + +// Set type specifications +#include <boost/bimap/unordered_set_of.hpp> +#include <boost/bimap/unordered_multiset_of.hpp> + +// bimap container +#include <boost/bimap/bimap.hpp> + +#include <libs/bimap/test/test_bimap.hpp> + +struct left_tag {}; +struct right_tag {}; + +void test_bimap() +{ + using namespace boost::bimaps; + + + typedef std::map<char,std::string> left_data_type; + left_data_type left_data; + left_data.insert( left_data_type::value_type('a',"a") ); + left_data.insert( left_data_type::value_type('b',"b") ); + left_data.insert( left_data_type::value_type('c',"c") ); + left_data.insert( left_data_type::value_type('d',"e") ); + + typedef std::map<std::string,char> right_data_type; + right_data_type right_data; + right_data.insert( right_data_type::value_type("a",'a') ); + right_data.insert( right_data_type::value_type("b",'b') ); + right_data.insert( right_data_type::value_type("c",'c') ); + right_data.insert( right_data_type::value_type("d",'e') ); + + + + //-------------------------------------------------------------------- + { + typedef bimap< + unordered_set_of<char>, unordered_multiset_of<std::string> + + > bm_type; + + std::set< bm_type::value_type > data; + data.insert( bm_type::value_type('a',"a") ); + data.insert( bm_type::value_type('b',"b") ); + data.insert( bm_type::value_type('c',"c") ); + data.insert( bm_type::value_type('d',"d") ); + + bm_type bm; + + test_unordered_set_unordered_multiset_bimap( + bm,data,left_data,right_data + ); + } + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + { + typedef bimap< + unordered_set_of< tagged< char , left_tag > >, + unordered_multiset_of< tagged< std::string, right_tag > > + + > bm_type; + + std::set< bm_type::value_type > data; + data.insert( bm_type::value_type('a',"a") ); + data.insert( bm_type::value_type('b',"b") ); + data.insert( bm_type::value_type('c',"c") ); + data.insert( bm_type::value_type('d',"d") ); + + bm_type bm; + + test_unordered_set_unordered_multiset_bimap( + bm,data,left_data,right_data + ); + test_tagged_bimap<left_tag,right_tag>(bm,data); + } + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + { + typedef bimap + < + set_of< char, std::greater<char> >, + unordered_multiset_of<std::string>, + unordered_set_of_relation<> + + > bm_type; + + std::set< bm_type::value_type > data; + data.insert( bm_type::value_type('a',"a") ); + data.insert( bm_type::value_type('b',"b") ); + data.insert( bm_type::value_type('c',"c") ); + data.insert( bm_type::value_type('d',"d") ); + + bm_type bm; + + test_basic_bimap(bm,data,left_data,right_data); + test_associative_container(bm,data); + test_simple_unordered_associative_container(bm,data); + } + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + { + typedef bimap + < + unordered_multiset_of< char >, + unordered_multiset_of< std::string >, + unordered_multiset_of_relation<> + + > bm_type; + + std::set< bm_type::value_type > data; + data.insert( bm_type::value_type('a',"a") ); + data.insert( bm_type::value_type('b',"b") ); + data.insert( bm_type::value_type('c',"c") ); + data.insert( bm_type::value_type('d',"d") ); + + bm_type bm; + + test_basic_bimap(bm,data,left_data,right_data); + test_associative_container(bm,data); + test_simple_unordered_associative_container(bm,data); + + } + //-------------------------------------------------------------------- +} + + +int main() +{ + test_bimap(); + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_bimap_unordered_multiset_of.cpp b/src/boost/libs/bimap/test/test_bimap_unordered_multiset_of.cpp new file mode 100644 index 000000000..bcfb209b2 --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_unordered_multiset_of.cpp @@ -0,0 +1,36 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/ignore_unused.hpp> + +#include <boost/bimap/unordered_multiset_of.hpp> + +int main() +{ + typedef boost::bimaps::unordered_multiset_of<int> set_type; + + typedef boost::bimaps:: + unordered_multiset_of_relation<> set_type_of_relation; + + boost::ignore_unused<set_type>(); + boost::ignore_unused<set_type_of_relation>(); + + return 0; +} + diff --git a/src/boost/libs/bimap/test/test_bimap_unordered_set_of.cpp b/src/boost/libs/bimap/test/test_bimap_unordered_set_of.cpp new file mode 100644 index 000000000..1d9300da9 --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_unordered_set_of.cpp @@ -0,0 +1,33 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/ignore_unused.hpp> + +#include <boost/bimap/unordered_set_of.hpp> + +int main() +{ + typedef boost::bimaps::unordered_set_of<int> set_type; + typedef boost::bimaps::unordered_set_of_relation<> set_type_of_relation; + boost::ignore_unused<set_type>(); + boost::ignore_unused<set_type_of_relation>(); + + return 0; +} + diff --git a/src/boost/libs/bimap/test/test_bimap_vector_of.cpp b/src/boost/libs/bimap/test/test_bimap_vector_of.cpp new file mode 100644 index 000000000..7f14a051b --- /dev/null +++ b/src/boost/libs/bimap/test/test_bimap_vector_of.cpp @@ -0,0 +1,33 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/ignore_unused.hpp> + +#include <boost/bimap/vector_of.hpp> + +int main() +{ + typedef boost::bimaps::vector_of<int> set_type; + typedef boost::bimaps::vector_of_relation set_type_of_relation; + boost::ignore_unused<set_type>(); + boost::ignore_unused<set_type_of_relation>(); + + return 0; +} + diff --git a/src/boost/libs/bimap/test/test_mutant.cpp b/src/boost/libs/bimap/test/test_mutant.cpp new file mode 100644 index 000000000..5e74ba133 --- /dev/null +++ b/src/boost/libs/bimap/test/test_mutant.cpp @@ -0,0 +1,102 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/lightweight_test.hpp> + +// Boost.MPL +#include <boost/mpl/list.hpp> +#include <boost/type_traits/is_same.hpp> + +// Boost.Bimap +#include <boost/bimap/relation/detail/mutant.hpp> + +using namespace boost::bimaps::relation::detail; + +// The mutant idiom is standard if only POD types are used. + +typedef double type_a; +typedef int type_b; + +const type_a value_a = 1.4; +const type_b value_b = 3; + +struct Data +{ + type_a a; + type_b b; +}; + +struct StdPairView +{ + typedef type_a first_type; + typedef type_b second_type; + type_a first; + type_b second; +}; + +struct ReverseStdPairView +{ + typedef type_a second_type; + typedef type_b first_type; + type_a second; + type_b first; +}; + + +struct MutantData +{ + typedef boost::mpl::list< StdPairView, ReverseStdPairView > mutant_views; + + MutantData(type_a ap, type_b bp) : a(ap), b(bp) {} + type_a a; + type_b b; +}; + + +void test_mutant_basic() +{ + + // mutant test + { + MutantData m(value_a,value_b); + + BOOST_TEST( sizeof( MutantData ) == sizeof( StdPairView ) ); + + BOOST_TEST( mutate<StdPairView>(m).first == value_a ); + BOOST_TEST( mutate<StdPairView>(m).second == value_b ); + BOOST_TEST( mutate<ReverseStdPairView>(m).first == value_b ); + BOOST_TEST( mutate<ReverseStdPairView>(m).second == value_a ); + + ReverseStdPairView & rpair = mutate<ReverseStdPairView>(m); + rpair.first = value_b; + rpair.second = value_a; + + BOOST_TEST( mutate<StdPairView>(m).first == value_a ); + BOOST_TEST( mutate<StdPairView>(m).second == value_b ); + + BOOST_TEST( &mutate<StdPairView>(m).first == &m.a ); + BOOST_TEST( &mutate<StdPairView>(m).second == &m.b ); + } +} + +int main() +{ + test_mutant_basic(); + return boost::report_errors(); +} diff --git a/src/boost/libs/bimap/test/test_mutant_relation.cpp b/src/boost/libs/bimap/test/test_mutant_relation.cpp new file mode 100644 index 000000000..6ff4ac146 --- /dev/null +++ b/src/boost/libs/bimap/test/test_mutant_relation.cpp @@ -0,0 +1,240 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +// std +#include <string> + +#include <boost/core/lightweight_test.hpp> + +// Boost.MPL +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_same.hpp> + +// Boost.Bimap +#include <boost/bimap/detail/test/check_metadata.hpp> +#include <boost/bimap/tags/tagged.hpp> + +// Boost.Bimap.Relation +#include <boost/bimap/relation/mutant_relation.hpp> +#include <boost/bimap/relation/member_at.hpp> +#include <boost/bimap/relation/support/get.hpp> +#include <boost/bimap/relation/support/pair_by.hpp> +#include <boost/bimap/relation/support/pair_type_by.hpp> +#include <boost/bimap/relation/support/value_type_of.hpp> +#include <boost/bimap/relation/support/member_with_tag.hpp> +#include <boost/bimap/relation/support/is_tag_of_member_at.hpp> + +// Bimap Test Utilities +#include "test_relation.hpp" + +BOOST_BIMAP_TEST_STATIC_FUNCTION( untagged_static_test ) +{ + using namespace boost::bimaps::relation::member_at; + using namespace boost::bimaps::relation; + using namespace boost::bimaps::tags; + + struct left_data {}; + struct right_data {}; + + typedef mutant_relation< left_data, right_data > rel; + + BOOST_BIMAP_CHECK_METADATA(rel,left_value_type ,left_data); + BOOST_BIMAP_CHECK_METADATA(rel,right_value_type,right_data); + + BOOST_BIMAP_CHECK_METADATA(rel,left_tag ,left ); + BOOST_BIMAP_CHECK_METADATA(rel,right_tag,right); + + typedef tagged<left_data ,left > desired_tagged_left_type; + BOOST_BIMAP_CHECK_METADATA(rel,tagged_left_type,desired_tagged_left_type); + + typedef tagged<right_data,right> desired_tagged_right_type; + BOOST_BIMAP_CHECK_METADATA(rel,tagged_right_type,desired_tagged_right_type); + +} + +BOOST_BIMAP_TEST_STATIC_FUNCTION( tagged_static_test) +{ + using namespace boost::bimaps::relation::member_at; + using namespace boost::bimaps::relation; + using namespace boost::bimaps::tags; + + struct left_data {}; + struct right_data {}; + + struct left_tag {}; + struct right_tag {}; + + typedef mutant_relation< + tagged<left_data,left_tag>, tagged<right_data,right_tag> > rel; + + BOOST_BIMAP_CHECK_METADATA(rel,left_value_type ,left_data); + BOOST_BIMAP_CHECK_METADATA(rel,right_value_type,right_data); + + BOOST_BIMAP_CHECK_METADATA(rel,left_tag ,left_tag ); + BOOST_BIMAP_CHECK_METADATA(rel,right_tag,right_tag ); + + typedef tagged<left_data ,left_tag > desired_tagged_left_type; + BOOST_BIMAP_CHECK_METADATA(rel,tagged_left_type,desired_tagged_left_type); + + typedef tagged<right_data,right_tag> desired_tagged_right_type; + BOOST_BIMAP_CHECK_METADATA(rel,tagged_right_type,desired_tagged_right_type); +} + +struct mutant_relation_builder +{ + template< class LeftType, class RightType > + struct build + { + typedef boost::bimaps::relation:: + mutant_relation<LeftType,RightType,::boost::mpl::na,true> type; + }; +}; + +// Complex classes + +class cc1 +{ + public: + cc1(int s = 0) : a(s+100), b(s+101) {} + static int sd; + int a; + const int b; +}; + +bool operator==(const cc1 & da, const cc1 & db) +{ + return da.a == db.a && da.b == db.b; +} + +int cc1::sd = 102; + +class cc2_base +{ + public: + cc2_base(int s) : a(s+200) {} + int a; +}; + +class cc2 : public cc2_base +{ + public: + cc2(int s = 0) : cc2_base(s), b(s+201) {} + int b; +}; + +bool operator==(const cc2 & da, const cc2 & db) +{ + return da.a == db.a && da.b == db.b; +} + +class cc3_base +{ + public: + cc3_base(int s = 0) : a(s+300) {} + const int a; +}; + +class cc3 : virtual public cc3_base +{ + public: + cc3(int s = 0) : cc3_base(s), b(s+301) {} + int b; +}; + +bool operator==(const cc3 & da, const cc3 & db) +{ + return da.a == db.a && da.b == db.b; +} + +class cc4_base +{ + public: + cc4_base(int s) : a(s+400) {} + virtual ~cc4_base() {} + const int a; +}; + +class cc4 : public cc4_base +{ + public: + cc4(int s = 0) : cc4_base(s), b(s+401) {} + int b; +}; + +bool operator==(const cc4 & da, const cc4 & db) +{ + return da.a == db.a && da.b == db.b; +} + +class cc5 : public cc1, public cc3, public cc4 +{ + public: + cc5(int s = 0) : cc1(s), cc3(s), cc4(s) {} +}; + +bool operator==(const cc5 & da, const cc5 & db) +{ + return da.cc1::a == db.cc1::a && da.cc1::b == db.cc1::b && + da.cc3::a == db.cc3::a && da.cc3::b == db.cc3::b && + da.cc4::a == db.cc4::a && da.cc4::b == db.cc4::b; +} + +class cc6 +{ + public: + cc6(int s = 0) : a(s+600), b(a) {} + int a; + int & b; +}; + +bool operator==(const cc6 & da, const cc6 & db) +{ + return da.a == db.a && da.b == db.b; +} + +void test_mutant_relation() +{ + test_relation< mutant_relation_builder, char , double >( 'l', 2.5 ); + test_relation< mutant_relation_builder, double, char >( 2.5, 'r' ); + + test_relation<mutant_relation_builder, int , int >( 1 , 2 ); + + test_relation<mutant_relation_builder, std::string, int* >("left value",0); + + test_relation<mutant_relation_builder, cc1, cc2>(0,0); + test_relation<mutant_relation_builder, cc2, cc3>(0,0); + test_relation<mutant_relation_builder, cc3, cc4>(0,0); + test_relation<mutant_relation_builder, cc4, cc5>(0,0); +} + +int main() +{ + + // Test metadata correctness with untagged relation version + BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( tagged_static_test ); + + // Test metadata correctness with tagged relation version + BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( untagged_static_test ); + + // Test basic + test_mutant_relation(); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_relation.hpp b/src/boost/libs/bimap/test/test_relation.hpp new file mode 100644 index 000000000..4cde2e701 --- /dev/null +++ b/src/boost/libs/bimap/test/test_relation.hpp @@ -0,0 +1,190 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +#ifndef BOOST_BIMAP_TEST_TEST_RELATION_HPP +#define BOOST_BIMAP_TEST_TEST_RELATION_HPP + +#if defined(_MSC_VER) +#pragma once +#endif + +#include <boost/config.hpp> + +#include <boost/core/lightweight_test.hpp> + +// Boost.MPL +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_same.hpp> + +// Boost.Bimap +#include <boost/bimap/detail/test/check_metadata.hpp> +#include <boost/bimap/tags/tagged.hpp> + +// Boost.Bimap.Relation +#include <boost/bimap/relation/member_at.hpp> +#include <boost/bimap/relation/support/get.hpp> +#include <boost/bimap/relation/support/pair_by.hpp> +#include <boost/bimap/relation/support/pair_type_by.hpp> +#include <boost/bimap/relation/support/value_type_of.hpp> +#include <boost/bimap/relation/support/member_with_tag.hpp> +#include <boost/bimap/relation/support/is_tag_of_member_at.hpp> + + + +template< class Relation > +void test_relation_with_default_tags(Relation & rel, + const typename Relation::left_value_type & lv, + const typename Relation::right_value_type & rv) +{ + + using namespace boost::bimaps::relation::support; + using namespace boost::bimaps::relation; + using namespace boost::bimaps::tags; + + // It must work with normal tags + + BOOST_TEST( pair_by<member_at::left >(rel).first == lv ); + BOOST_TEST( pair_by<member_at::left >(rel).second == rv ); + + BOOST_TEST( pair_by<member_at::right>(rel).first == rv ); + BOOST_TEST( pair_by<member_at::right>(rel).second == lv ); + + BOOST_TEST( get<member_at::left >(rel) == rel.left ); + BOOST_TEST( get<member_at::right>(rel) == rel.right ); + + BOOST_TEST( + get<member_at::left >(pair_by<member_at::left >(rel)) == rel.left + ); + + BOOST_TEST( + get<member_at::right>(pair_by<member_at::left >(rel)) == rel.right + ); + + BOOST_TEST( + get<member_at::left >(pair_by<member_at::right>(rel)) == rel.left + ); + + BOOST_TEST( + get<member_at::right>(pair_by<member_at::right>(rel)) == rel.right + ); + +} + +template< class Relation, class LeftTag, class RightTag > +void test_relation_with_user_tags(Relation & rel, + const typename Relation::left_value_type & lv, + const typename Relation::right_value_type & rv) +{ + + using namespace boost::bimaps::relation::support; + using namespace boost::bimaps::relation; + using namespace boost::bimaps::tags; + + // And with users ones + + BOOST_TEST( pair_by<LeftTag >(rel).first == lv ); + BOOST_TEST( pair_by<LeftTag >(rel).second == rv ); + + BOOST_TEST( pair_by<RightTag>(rel).first == rv ); + BOOST_TEST( pair_by<RightTag>(rel).second == lv ); + + BOOST_TEST( get<LeftTag >(rel) == rel.left ); + BOOST_TEST( get<RightTag>(rel) == rel.right ); + + BOOST_TEST( get<LeftTag >(pair_by<LeftTag >(rel)) == rel.left ); + BOOST_TEST( get<RightTag>(pair_by<LeftTag >(rel)) == rel.right ); + + BOOST_TEST( get<LeftTag >(pair_by<RightTag>(rel)) == rel.left ); + BOOST_TEST( get<RightTag>(pair_by<RightTag>(rel)) == rel.right ); + + //---------------------------------------------------------------- + + BOOST_TEST( rel.template get<LeftTag >() == rel.left ); + BOOST_TEST( rel.template get<RightTag>() == rel.right ); + + BOOST_TEST( pair_by<LeftTag >(rel).template get<LeftTag >()== rel.left ); + BOOST_TEST( pair_by<LeftTag >(rel).template get<RightTag>()== rel.right); + + BOOST_TEST( pair_by<RightTag>(rel).template get<LeftTag >()== rel.left ); + BOOST_TEST( pair_by<RightTag>(rel).template get<RightTag>()== rel.right); +} + +struct left_user_tag {}; +struct right_user_tag {}; + +template< class RelationBuilder, class LeftData, class RightData > +void test_relation(const LeftData & lv, const RightData & rv) +{ + using namespace boost::bimaps::relation::support; + using namespace boost::bimaps::relation; + using boost::bimaps::tags::tagged; + + // Untagged test + { + typedef typename RelationBuilder::template build + < + LeftData, + RightData + + >::type rel_type; + + rel_type rel( lv, rv ); + + test_relation_with_default_tags( rel, lv, rv); + } + + // Tagged test + { + typedef typename RelationBuilder::template build + < + tagged<LeftData , left_user_tag >, + tagged<RightData, right_user_tag > + + >::type rel_type; + + rel_type rel( lv, rv ); + + test_relation_with_default_tags(rel, lv, rv ); + test_relation_with_user_tags + < + rel_type, + left_user_tag,right_user_tag + + >(rel,lv,rv); + } + + // Default Constructor, Constructor from views and some operators + { +/* + typedef typename RelationBuilder::template build + < + tagged<LeftData , left_user_tag >, + tagged<RightData, right_user_tag > + + >::type rel_type; + + typedef typename pair_type_by< left_user_tag,rel_type>::type left_pair; + typedef typename pair_type_by<right_user_tag,rel_type>::type right_pair; + + rel_type rel_from_left ( left_pair(lv,rv) ); + rel_type rel_from_right( right_pair(rv,lv) ); + + BOOST_TEST( rel_from_left == rel_from_right ); + BOOST_TEST( rel_from_left == rel_type(lv,rv) ); + + rel_type rel; + + rel = rel_from_left; + + BOOST_TEST( rel == rel_from_left ); +*/ + } + +} + +#endif // BOOST_BIMAP_TEST_TEST_RELATION_HPP diff --git a/src/boost/libs/bimap/test/test_structured_pair.cpp b/src/boost/libs/bimap/test/test_structured_pair.cpp new file mode 100644 index 000000000..59aaa50ef --- /dev/null +++ b/src/boost/libs/bimap/test/test_structured_pair.cpp @@ -0,0 +1,97 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/lightweight_test.hpp> + +// std +#include <utility> +#include <cstddef> + +// Boost.Static_assert +#include <boost/static_assert.hpp> + +// Boost.Bimap +#include <boost/bimap/detail/test/check_metadata.hpp> + +#include <boost/bimap/relation/structured_pair.hpp> + + +BOOST_BIMAP_TEST_STATIC_FUNCTION( static_metadata_test ) +{ + using namespace boost::bimaps::relation; + + struct data_a { char data; }; + struct data_b { double data; }; + + typedef structured_pair + < + data_a, + data_b, + normal_layout + + > sp_ab; + + typedef structured_pair + < + data_b, + data_a, + mirror_layout + + > sp_ba; + + BOOST_BIMAP_CHECK_METADATA(sp_ab, first_type , data_a); + BOOST_BIMAP_CHECK_METADATA(sp_ab, second_type, data_b); + + BOOST_BIMAP_CHECK_METADATA(sp_ba, first_type , data_b); + BOOST_BIMAP_CHECK_METADATA(sp_ba, second_type, data_a); + +} + + +void test_basic() +{ + + using namespace boost::bimaps::relation; + + // Instantiate two pairs and test the storage alignmentDataData + + typedef structured_pair< short, double, normal_layout > pair_type; + typedef structured_pair< double, short, mirror_layout > mirror_type; + + pair_type pa( 2, 3.1416 ); + mirror_type pb( 3.1416, 2 ); + + BOOST_TEST( pa.first == pb.second ); + BOOST_TEST( pa.second == pb.first ); + +} + + +int main() +{ + + BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( static_are_storage_compatible_test ); + + BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( static_metadata_test ); + + test_basic(); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/bimap/test/test_tagged.cpp b/src/boost/libs/bimap/test/test_tagged.cpp new file mode 100644 index 000000000..8e3a869ad --- /dev/null +++ b/src/boost/libs/bimap/test/test_tagged.cpp @@ -0,0 +1,107 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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) + +// VC++ 8.0 warns on usage of certain Standard Library and API functions that +// can be cause buffer overruns or other possible security issues if misused. +// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx +// But the wording of the warning is misleading and unsettling, there are no +// portable alternative functions, and VC++ 8.0's own libraries use the +// functions in question. So turn off the warnings. +#define _CRT_SECURE_NO_DEPRECATE +#define _SCL_SECURE_NO_DEPRECATE + +#include <boost/config.hpp> + +#include <boost/core/lightweight_test.hpp> + +#include <boost/static_assert.hpp> + +// Boost.MPL +#include <boost/type_traits/is_same.hpp> +#include <boost/mpl/placeholders.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/add_const.hpp> + +// Boost.Bimap +#include <boost/bimap/detail/test/check_metadata.hpp> + +// Boost.Bimap.Tags +#include <boost/bimap/tags/tagged.hpp> +#include <boost/bimap/tags/support/default_tagged.hpp> +#include <boost/bimap/tags/support/is_tagged.hpp> +#include <boost/bimap/tags/support/overwrite_tagged.hpp> +#include <boost/bimap/tags/support/tag_of.hpp> +#include <boost/bimap/tags/support/value_type_of.hpp> +#include <boost/bimap/tags/support/apply_to_value_type.hpp> + + + + +BOOST_BIMAP_TEST_STATIC_FUNCTION( test_metafunctions ) +{ + using namespace boost::bimaps::tags::support; + using namespace boost::bimaps::tags; + using namespace boost::mpl::placeholders; + using namespace boost; + + struct tag {}; + struct value {}; + + // Test apply_to_value_type metafunction + // tagged<value,tag> ----(add_const<_>)----> tagged<value const,tag> + typedef tagged< value, tag > ttype; + typedef apply_to_value_type< add_const<_>,ttype>::type result; + typedef is_same<tagged<value const,tag>,result> compare; + BOOST_MPL_ASSERT_MSG(compare::value,tag,(result)); +} + +struct tag_a {}; +struct tag_b {}; +struct data {}; + +void test_function() +{ + + using namespace boost::bimaps::tags::support; + using namespace boost::bimaps::tags; + using boost::is_same; + + typedef tagged< data, tag_a > data_a; + typedef tagged< data, tag_b > data_b; + + BOOST_TEST(( is_same< data_a::value_type , data >::value )); + BOOST_TEST(( is_same< data_a::tag , tag_a >::value )); + + BOOST_TEST(( + is_same< overwrite_tagged < data_a, tag_b >::type, data_b >::value + )); + BOOST_TEST(( + is_same< default_tagged < data_a, tag_b >::type, data_a >::value + )); + BOOST_TEST(( + is_same< default_tagged < data , tag_b >::type, data_b >::value + )); + + BOOST_TEST(( is_tagged< data >::value == false )); + BOOST_TEST(( is_tagged< data_a >::value == true )); + + BOOST_TEST(( is_same< value_type_of<data_a>::type, data >::value )); + BOOST_TEST(( is_same< tag_of <data_a>::type, tag_a >::value )); + +} + +int main() +{ + test_function(); + + // Test metanfunctions + BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( test_metafunctions ); + + return boost::report_errors(); +} + |