#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/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>
#include "strong_type.hpp"
void test_bimap_operator_bracket()
{
using namespace boost::bimaps;
{
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" );
{
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 );
}
}
{
typedef bimap<int, list_of<std::string> > bm;
bm b;
{
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 );
}
{
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" );
}
{
typedef bimap< vector_of<int>, unordered_set_of<std::string> > bm;
bm b;
{
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 );
}
{
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 );
}
{
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 );
}
{
typedef bimap
<
set_of<int, std::less< strong<int> > >,
list_of<std::string>
> bm;
bm b;
b.left[1] = "0";
b.left[semistrong<int>(1)] = "1";
BOOST_TEST( b.left.at(strong<int>(1)) == "1");
b.left.at(strong<int>(1)) = "2";
BOOST_TEST( b.left.at(strong<int>(1)) == "2");
}
{
typedef bimap
<
list_of<int>,
unordered_set_of
<
std::string,
boost::hash< strong<std::string> >,
std::equal_to< strong<std::string> >
>
> bm;
bm b;
b.right["1"]=0;
b.right[semistrong<std::string>("1")] = 1;
BOOST_TEST( b.right.at(strong<std::string>("1")) == 1);
b.right.at(strong<std::string>("1")) = 2;
BOOST_TEST( b.right.at(strong<std::string>("1")) == 2);
}
}
int main()
{
test_bimap_operator_bracket();
return boost::report_errors();
}