File indexing completed on 2025-01-18 09:29:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_BIMAP_RELATION_STRUCTURED_PAIR_HPP
0013 #define BOOST_BIMAP_RELATION_STRUCTURED_PAIR_HPP
0014
0015 #if defined(_MSC_VER)
0016 #pragma once
0017 #endif
0018
0019 #include <boost/config.hpp>
0020
0021 #include <utility>
0022
0023 #include <boost/type_traits/remove_const.hpp>
0024
0025 #include <boost/mpl/aux_/na.hpp>
0026
0027 #include <boost/call_traits.hpp>
0028
0029 #include <boost/core/enable_if.hpp>
0030 #include <boost/type_traits/is_same.hpp>
0031 #include <boost/mpl/if.hpp>
0032 #include <boost/mpl/vector.hpp>
0033
0034 #include <boost/bimap/detail/debug/static_error.hpp>
0035 #include <boost/bimap/relation/pair_layout.hpp>
0036 #include <boost/bimap/relation/symmetrical_base.hpp>
0037 #include <boost/bimap/relation/support/get.hpp>
0038 #include <boost/bimap/tags/support/value_type_of.hpp>
0039
0040
0041
0042 namespace boost {
0043 namespace bimaps {
0044 namespace relation {
0045
0046 namespace detail {
0047
0048
0049
0050
0051
0052
0053
0054 template< class FirstType, class SecondType >
0055 class normal_storage :
0056 public symmetrical_base<FirstType,SecondType>
0057 {
0058 typedef symmetrical_base<FirstType,SecondType> base_;
0059
0060 public:
0061
0062 typedef normal_storage storage_;
0063
0064 typedef BOOST_DEDUCED_TYPENAME base_::left_value_type first_type;
0065 typedef BOOST_DEDUCED_TYPENAME base_::right_value_type second_type;
0066
0067 first_type first;
0068 second_type second;
0069
0070 normal_storage() {}
0071
0072 normal_storage(BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0073 first_type >::param_type f,
0074 BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0075 second_type>::param_type s)
0076
0077 : first(f), second(s) {}
0078
0079 BOOST_DEDUCED_TYPENAME base_:: left_value_type & get_left() { return first; }
0080 const BOOST_DEDUCED_TYPENAME base_:: left_value_type & get_left()const { return first; }
0081 BOOST_DEDUCED_TYPENAME base_::right_value_type & get_right() { return second; }
0082 const BOOST_DEDUCED_TYPENAME base_::right_value_type & get_right()const { return second; }
0083 };
0084
0085
0086
0087
0088
0089
0090
0091 template< class FirstType, class SecondType >
0092 class mirror_storage :
0093 public symmetrical_base<SecondType,FirstType>
0094 {
0095 typedef symmetrical_base<SecondType,FirstType> base_;
0096
0097 public:
0098
0099 typedef mirror_storage storage_;
0100
0101 typedef BOOST_DEDUCED_TYPENAME base_::left_value_type second_type;
0102 typedef BOOST_DEDUCED_TYPENAME base_::right_value_type first_type;
0103
0104 second_type second;
0105 first_type first;
0106
0107 mirror_storage() {}
0108
0109 mirror_storage(BOOST_DEDUCED_TYPENAME ::boost::call_traits<first_type >::param_type f,
0110 BOOST_DEDUCED_TYPENAME ::boost::call_traits<second_type >::param_type s)
0111
0112 : second(s), first(f) {}
0113
0114 BOOST_DEDUCED_TYPENAME base_:: left_value_type & get_left() { return second; }
0115 const BOOST_DEDUCED_TYPENAME base_:: left_value_type & get_left()const { return second; }
0116 BOOST_DEDUCED_TYPENAME base_::right_value_type & get_right() { return first; }
0117 const BOOST_DEDUCED_TYPENAME base_::right_value_type & get_right()const { return first; }
0118 };
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
0135
0136 template
0137 <
0138 class FirstType,
0139 class SecondType,
0140 class Layout
0141 >
0142 struct storage_finder
0143 {
0144 typedef normal_storage<FirstType,SecondType> type;
0145 };
0146
0147 template
0148 <
0149 class FirstType,
0150 class SecondType
0151 >
0152 struct storage_finder<FirstType,SecondType,mirror_layout>
0153 {
0154 typedef mirror_storage<FirstType,SecondType> type;
0155 };
0156
0157 #endif
0158
0159
0160 template< class TA, class TB, class Info, class Layout >
0161 class pair_info_hook :
0162 public ::boost::bimaps::relation::detail::storage_finder<TA,TB,Layout>::type
0163 {
0164 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::detail::storage_finder<TA,TB,Layout>::type base_;
0165
0166 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::tags::support::
0167 default_tagged<Info,member_at::info>::type tagged_info_type;
0168
0169 public:
0170 typedef BOOST_DEDUCED_TYPENAME tagged_info_type::value_type info_type;
0171 typedef BOOST_DEDUCED_TYPENAME tagged_info_type::tag info_tag;
0172
0173 info_type info;
0174
0175 protected:
0176
0177 pair_info_hook() {}
0178
0179 pair_info_hook( BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0180 BOOST_DEDUCED_TYPENAME base_::first_type
0181 >::param_type f,
0182 BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0183 BOOST_DEDUCED_TYPENAME base_::second_type
0184 >::param_type s,
0185 BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0186 info_type
0187 >::param_type i = info_type() )
0188 : base_(f,s), info(i) {}
0189
0190 template< class Pair >
0191 pair_info_hook( const Pair & p) :
0192 base_(p.first,p.second),
0193 info(p.info) {}
0194
0195 template< class Pair >
0196 void change_to( const Pair & p )
0197 {
0198 base_::first = p.first ;
0199 base_::second = p.second;
0200 info = p.info ;
0201 }
0202
0203 void clear_info()
0204 {
0205 info = info_type();
0206 };
0207 };
0208
0209 template< class TA, class TB, class Layout>
0210 class pair_info_hook<TA,TB,::boost::mpl::na,Layout> :
0211 public ::boost::bimaps::relation::detail::storage_finder<TA,TB,Layout>::type
0212 {
0213 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::detail::storage_finder<TA,TB,Layout>::type base_;
0214
0215 public:
0216 typedef ::boost::mpl::na info_type;
0217 typedef member_at::info info_tag;
0218
0219 protected:
0220
0221 pair_info_hook() {}
0222
0223 pair_info_hook( BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0224 BOOST_DEDUCED_TYPENAME base_::first_type
0225 >::param_type f,
0226 BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0227 BOOST_DEDUCED_TYPENAME base_::second_type
0228 >::param_type s)
0229
0230 : base_(f,s) {}
0231
0232 template< class Pair >
0233 pair_info_hook( const Pair & p ) :
0234 base_(p.first,p.second) {}
0235
0236 template< class Pair >
0237 void change_to( const Pair & p )
0238 {
0239 base_::first = p.first ;
0240 base_::second = p.second;
0241 }
0242
0243 void clear_info() {};
0244 };
0245
0246
0247
0248 }
0249
0250 template< class TA, class TB, class Info, bool FM >
0251 class mutant_relation;
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261 template< class FirstType, class SecondType, class Info, class Layout = normal_layout >
0262 class structured_pair :
0263
0264 public ::boost::bimaps::relation::detail::pair_info_hook
0265 <
0266 FirstType, SecondType,
0267 Info,
0268 Layout
0269
0270 >
0271
0272 {
0273 typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::detail::pair_info_hook
0274 <
0275 FirstType, SecondType,
0276 Info,
0277 Layout
0278
0279 > base_;
0280
0281 public:
0282
0283 typedef ::boost::mpl::vector3<
0284 structured_pair< FirstType, SecondType, Info, normal_layout >,
0285 structured_pair< FirstType, SecondType, Info, mirror_layout >,
0286 BOOST_DEDUCED_TYPENAME ::boost::mpl::if_<
0287 BOOST_DEDUCED_TYPENAME ::boost::is_same<Layout, normal_layout>::type,
0288 mutant_relation< FirstType, SecondType, Info, true >,
0289 mutant_relation< SecondType, FirstType, Info, true >
0290 >::type
0291
0292 > mutant_views;
0293
0294 structured_pair() {}
0295
0296 structured_pair(BOOST_DEDUCED_TYPENAME boost::call_traits<
0297 BOOST_DEDUCED_TYPENAME base_::first_type >::param_type f,
0298 BOOST_DEDUCED_TYPENAME boost::call_traits<
0299 BOOST_DEDUCED_TYPENAME base_::second_type >::param_type s)
0300 : base_(f,s) {}
0301
0302 structured_pair(BOOST_DEDUCED_TYPENAME boost::call_traits<
0303 BOOST_DEDUCED_TYPENAME base_::first_type >::param_type f,
0304 BOOST_DEDUCED_TYPENAME boost::call_traits<
0305 BOOST_DEDUCED_TYPENAME base_::second_type >::param_type s,
0306 BOOST_DEDUCED_TYPENAME boost::call_traits<
0307 BOOST_DEDUCED_TYPENAME base_::info_type >::param_type i)
0308 : base_(f,s,i) {}
0309
0310 template< class OtherLayout >
0311 structured_pair(
0312 const structured_pair<FirstType,SecondType,Info,OtherLayout> & p)
0313 : base_(p) {}
0314
0315 template< class OtherLayout >
0316 structured_pair& operator=(
0317 const structured_pair<FirstType,SecondType,OtherLayout> & p)
0318 {
0319 base_::change_to(p);
0320 return *this;
0321 }
0322
0323 template< class First, class Second >
0324 structured_pair(const std::pair<First,Second> & p) :
0325 base_(p.first,p.second)
0326 {}
0327
0328 template< class First, class Second >
0329 structured_pair& operator=(const std::pair<First,Second> & p)
0330 {
0331 base_::first = p.first;
0332 base_::second = p.second;
0333 base_::clear_info();
0334 return *this;
0335 }
0336
0337 template< class Tag >
0338 const BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
0339 result_of::get<Tag,const structured_pair>::type
0340 get() const
0341 {
0342 return ::boost::bimaps::relation::support::get<Tag>(*this);
0343 }
0344
0345 template< class Tag >
0346 BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::
0347 result_of::get<Tag,structured_pair>::type
0348 get()
0349 {
0350 return ::boost::bimaps::relation::support::get<Tag>(*this);
0351 }
0352 };
0353
0354
0355
0356 template< class FirstType, class SecondType, class Info, class Layout1, class Layout2 >
0357 bool operator==(const structured_pair<FirstType,SecondType,Info,Layout1> & a,
0358 const structured_pair<FirstType,SecondType,Info,Layout2> & b)
0359 {
0360 return ( ( a.first == b.first ) &&
0361 ( a.second == b.second ) );
0362 }
0363
0364 template< class FirstType, class SecondType, class Info, class Layout1, class Layout2 >
0365 bool operator!=(const structured_pair<FirstType,SecondType,Info,Layout1> & a,
0366 const structured_pair<FirstType,SecondType,Info,Layout2> & b)
0367 {
0368 return ! ( a == b );
0369 }
0370
0371 template< class FirstType, class SecondType, class Info, class Layout1, class Layout2 >
0372 bool operator<(const structured_pair<FirstType,SecondType,Info,Layout1> & a,
0373 const structured_pair<FirstType,SecondType,Info,Layout2> & b)
0374 {
0375 return ( ( a.first < b.first ) ||
0376 (( a.first == b.first ) && ( a.second < b.second )));
0377 }
0378
0379 template< class FirstType, class SecondType, class Info, class Layout1, class Layout2 >
0380 bool operator<=(const structured_pair<FirstType,SecondType,Info,Layout1> & a,
0381 const structured_pair<FirstType,SecondType,Info,Layout2> & b)
0382 {
0383 return ( ( a.first < b.first ) ||
0384 (( a.first == b.first ) && ( a.second <= b.second )));
0385 }
0386
0387 template< class FirstType, class SecondType, class Info, class Layout1, class Layout2 >
0388 bool operator>(const structured_pair<FirstType,SecondType,Info,Layout1> & a,
0389 const structured_pair<FirstType,SecondType,Info,Layout2> & b)
0390 {
0391 return ( ( a.first > b.first ) ||
0392 (( a.first == b.first ) && ( a.second > b.second )));
0393 }
0394
0395 template< class FirstType, class SecondType, class Info, class Layout1, class Layout2 >
0396 bool operator>=(const structured_pair<FirstType,SecondType,Info,Layout1> & a,
0397 const structured_pair<FirstType,SecondType,Info,Layout2> & b)
0398 {
0399 return ( ( a.first > b.first ) ||
0400 (( a.first == b.first ) && ( a.second >= b.second )));
0401 }
0402
0403
0404
0405 template< class FirstType, class SecondType, class Info, class Layout, class F, class S >
0406 bool operator==(const structured_pair<FirstType,SecondType,Info,Layout> & a,
0407 const std::pair<F,S> & b)
0408 {
0409 return ( ( a.first == b.first ) &&
0410 ( a.second == b.second ) );
0411 }
0412
0413 template< class FirstType, class SecondType, class Info, class Layout, class F, class S >
0414 bool operator!=(const structured_pair<FirstType,SecondType,Info,Layout> & a,
0415 const std::pair<F,S> & b)
0416 {
0417 return ! ( a == b );
0418 }
0419
0420 template< class FirstType, class SecondType, class Info, class Layout, class F, class S >
0421 bool operator<(const structured_pair<FirstType,SecondType,Info,Layout> & a,
0422 const std::pair<F,S> & b)
0423 {
0424 return ( ( a.first < b.first ) ||
0425 (( a.first == b.first ) && ( a.second < b.second )));
0426 }
0427
0428 template< class FirstType, class SecondType, class Info, class Layout, class F, class S >
0429 bool operator<=(const structured_pair<FirstType,SecondType,Info,Layout> & a,
0430 const std::pair<F,S> & b)
0431 {
0432 return ( ( a.first < b.first ) ||
0433 (( a.first == b.first ) && ( a.second <= b.second )));
0434 }
0435
0436 template< class FirstType, class SecondType, class Info, class Layout, class F, class S >
0437 bool operator>(const structured_pair<FirstType,SecondType,Info,Layout> & a,
0438 const std::pair<F,S> & b)
0439 {
0440 return ( ( a.first > b.first ) ||
0441 (( a.first == b.first ) && ( a.second > b.second )));
0442 }
0443
0444 template< class FirstType, class SecondType, class Info, class Layout, class F, class S >
0445 bool operator>=(const structured_pair<FirstType,SecondType,Info,Layout> & a,
0446 const std::pair<F,S> & b)
0447 {
0448 return ( ( a.first > b.first ) ||
0449 (( a.first == b.first ) && ( a.second >= b.second )));
0450 }
0451
0452
0453
0454 template< class FirstType, class SecondType, class Info, class Layout, class F, class S >
0455 bool operator==(const std::pair<F,S> & a,
0456 const structured_pair<FirstType,SecondType,Info,Layout> & b)
0457 {
0458 return ( ( a.first == b.first ) &&
0459 ( a.second == b.second ) );
0460 }
0461
0462 template< class FirstType, class SecondType, class Info, class Layout, class F, class S >
0463 bool operator!=(const std::pair<F,S> & a,
0464 const structured_pair<FirstType,SecondType,Info,Layout> & b)
0465 {
0466 return ! ( a == b );
0467 }
0468
0469 template< class FirstType, class SecondType, class Info, class Layout, class F, class S >
0470 bool operator<(const std::pair<F,S> & a,
0471 const structured_pair<FirstType,SecondType,Info,Layout> & b)
0472 {
0473 return ( ( a.first < b.first ) ||
0474 (( a.first == b.first ) && ( a.second < b.second )));
0475 }
0476
0477 template< class FirstType, class SecondType, class Info, class Layout, class F, class S >
0478 bool operator<=(const std::pair<F,S> & a,
0479 const structured_pair<FirstType,SecondType,Info,Layout> & b)
0480 {
0481 return ( ( a.first < b.first ) ||
0482 (( a.first == b.first ) && ( a.second <= b.second )));
0483 }
0484
0485 template< class FirstType, class SecondType, class Info, class Layout, class F, class S >
0486 bool operator>(const std::pair<F,S> & a,
0487 const structured_pair<FirstType,SecondType,Info,Layout> & b)
0488 {
0489 return ( ( a.first > b.first ) ||
0490 (( a.first == b.first ) && ( a.second > b.second )));
0491 }
0492
0493 template< class FirstType, class SecondType, class Info, class Layout, class F, class S >
0494 bool operator>=(const std::pair<F,S> & a,
0495 const structured_pair<FirstType,SecondType,Info,Layout> & b)
0496 {
0497 return ( ( a.first > b.first ) ||
0498 (( a.first == b.first ) && ( a.second >= b.second )));
0499 }
0500
0501
0502 namespace detail {
0503
0504 template< class FirstType, class SecondType, class Info, class Layout>
0505 structured_pair<FirstType,SecondType,Info,Layout>
0506 copy_with_first_replaced(structured_pair<FirstType,SecondType,Info,Layout> const& p,
0507 BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME
0508 structured_pair<FirstType,SecondType,Info,Layout>::first_type>
0509 ::param_type f)
0510 {
0511 return structured_pair<FirstType,SecondType,Info,Layout>(f,p.second,p.info);
0512 }
0513
0514 template< class FirstType, class SecondType, class Layout>
0515 structured_pair<FirstType,SecondType,::boost::mpl::na,Layout>
0516 copy_with_first_replaced(structured_pair<FirstType,SecondType,::boost::mpl::na,Layout> const& p,
0517 BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME
0518 structured_pair<FirstType,SecondType,::boost::mpl::na,Layout>::first_type>
0519 ::param_type f)
0520 {
0521 return structured_pair<FirstType,SecondType,::boost::mpl::na,Layout>(f,p.second);
0522 }
0523
0524 template< class FirstType, class SecondType, class Info, class Layout>
0525 structured_pair<FirstType,SecondType,Info,Layout>
0526 copy_with_second_replaced(structured_pair<FirstType,SecondType,Info,Layout> const& p,
0527 BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME
0528 structured_pair<FirstType,SecondType,Info,Layout>::second_type>
0529 ::param_type s)
0530 {
0531 return structured_pair<FirstType,SecondType,Info,Layout>(p.first,s,p.info);
0532 }
0533
0534 template< class FirstType, class SecondType, class Layout>
0535 structured_pair<FirstType,SecondType,::boost::mpl::na,Layout>
0536 copy_with_second_replaced(structured_pair<FirstType,SecondType,::boost::mpl::na,Layout> const& p,
0537 BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME
0538 structured_pair<FirstType,SecondType,::boost::mpl::na,Layout>::second_type>
0539 ::param_type s)
0540 {
0541 return structured_pair<FirstType,SecondType,::boost::mpl::na,Layout>(p.first,s);
0542 }
0543
0544 }
0545
0546
0547 }
0548 }
0549 }
0550
0551 #endif
0552