// 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.Test #include // Boost.MPL #include #include // Boost.Bimap #include #include // Boost.Bimap.Relation #include #include #include #include #include #include #include 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_CHECK( pair_by(rel).first == lv ); BOOST_CHECK( pair_by(rel).second == rv ); BOOST_CHECK( pair_by(rel).first == rv ); BOOST_CHECK( pair_by(rel).second == lv ); BOOST_CHECK( get(rel) == rel.left ); BOOST_CHECK( get(rel) == rel.right ); BOOST_CHECK( get(pair_by(rel)) == rel.left ); BOOST_CHECK( get(pair_by(rel)) == rel.right ); BOOST_CHECK( get(pair_by(rel)) == rel.left ); BOOST_CHECK( get(pair_by(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_CHECK( pair_by(rel).first == lv ); BOOST_CHECK( pair_by(rel).second == rv ); BOOST_CHECK( pair_by(rel).first == rv ); BOOST_CHECK( pair_by(rel).second == lv ); BOOST_CHECK( get(rel) == rel.left ); BOOST_CHECK( get(rel) == rel.right ); BOOST_CHECK( get(pair_by(rel)) == rel.left ); BOOST_CHECK( get(pair_by(rel)) == rel.right ); BOOST_CHECK( get(pair_by(rel)) == rel.left ); BOOST_CHECK( get(pair_by(rel)) == rel.right ); //---------------------------------------------------------------- BOOST_CHECK( rel.template get() == rel.left ); BOOST_CHECK( rel.template get() == rel.right ); BOOST_CHECK( pair_by(rel).template get()== rel.left ); BOOST_CHECK( pair_by(rel).template get()== rel.right); BOOST_CHECK( pair_by(rel).template get()== rel.left ); BOOST_CHECK( pair_by(rel).template get()== 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, tagged >::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, tagged >::type rel_type; typedef typename pair_type_by< left_user_tag,rel_type>::type left_pair; typedef typename pair_type_by::type right_pair; rel_type rel_from_left ( left_pair(lv,rv) ); rel_type rel_from_right( right_pair(rv,lv) ); BOOST_CHECK( rel_from_left == rel_from_right ); BOOST_CHECK( rel_from_left == rel_type(lv,rv) ); rel_type rel; rel = rel_from_left; BOOST_CHECK( rel == rel_from_left ); */ } } #endif // BOOST_BIMAP_TEST_TEST_RELATION_HPP