<< | к задаче | главная | печатать | обсудить(0 сообщений) >>
Задача: Двусторонняя карта
Исходник: Двусторонняя карта, BiMap [C++, code #543, hits: 5810, рейтинг: 3/7,4.86(1981)] +
автор: - [добавлен: 17.12.2007] управление:
  1. namespace nn
  2. {
  3.  
  4. // Like std::pair but takes 3 arguments
  5. template<typename First, typename Second, typename Third>
  6. struct tripple
  7. {
  8. typedef tripple<First, Second, Third> this_type;
  9.  
  10. typedef First first_type;
  11. typedef Second second_type;
  12. typedef Third third_type;
  13.  
  14. tripple() :
  15. first(First()),
  16. second(Second()),
  17. third(Third())
  18. {
  19. }
  20.  
  21. tripple(const First& first_val,
  22. const Second& second_val,
  23. const Third& third_val) :
  24. first(first_val),
  25. second(second_val),
  26. third(third_val)
  27. {
  28. }
  29.  
  30. template<typename First2, typename Second2, typename Third2>
  31. tripple(const tripple<First2, Second2, Third2>& right) :
  32. first(right.first),
  33. second(right.second),
  34. third(right.third)
  35. {
  36. }
  37.  
  38. void swap(const this_type& right)
  39. {
  40. std::swap(first, right.first);
  41. std::swap(second, right.second);
  42. std::swap(third, right.third);
  43. }
  44.  
  45. First first;
  46. Second second;
  47. Third third;
  48. };
  49.  
  50. template<typename First, typename Second, typename Third>
  51. bool operator==(const tripple<First, Second, Third>& left,
  52. const tripple<First, Second, Third>& right)
  53. {
  54. return left.first == right.first &&
  55. left.second == right.second &&
  56. left.third == right.third;
  57. }
  58.  
  59. template<typename First, typename Second, typename Third>
  60. bool operator!=(const tripple<First, Second, Third>& left,
  61. const tripple<First, Second, Third>& right)
  62. {
  63. return !(left == right);
  64. }
  65.  
  66. template<typename First, typename Second, typename Third>
  67. bool operator <(const tripple<First, Second, Third>& left,
  68. const tripple<First, Second, Third>& right)
  69. {
  70. return left.first < right.first &&
  71. left.second < right.second &&
  72. left.third < right.third;
  73. }
  74.  
  75. template<typename First, typename Second, typename Third>
  76. bool operator >(const tripple<First, Second, Third>& left,
  77. const tripple<First, Second, Third>& right)
  78. {
  79. return right < left;
  80. }
  81.  
  82. template<typename First, typename Second, typename Third>
  83. bool operator<=(const tripple<First, Second, Third>& left,
  84. const tripple<First, Second, Third>& right)
  85. {
  86. return !(right < left);
  87. }
  88.  
  89. template<typename First, typename Second, typename Third>
  90. bool operator>=(const tripple<First, Second, Third>& left,
  91. const tripple<First, Second, Third>& right)
  92. {
  93. return !(left < right);
  94. }
  95.  
  96. template<typename First, typename Second, typename Third>
  97. tripple<First, Second, Third> make_tripple(const First& first,
  98. const Second& second,
  99. const Third& third)
  100. {
  101. return tripple<First, Second, Third>(first, second, third);
  102. }
  103.  
  104. template<typename First, typename Second, typename Third>
  105. void swap(const nn::tripple<First, Second, Third>& left,
  106. const nn::tripple<First, Second, Third>& right)
  107. {
  108. left.swap(right);
  109. }
  110.  
  111. } // namespace nn
  112.  
  113.  
  114. // BiMap From >>
  115. #include <map>
  116. #include <memory>
  117. #include <algorithm>
  118. #include <stdexcept>
  119.  
  120. #include <nn/tripple.hpp>
  121.  
  122. namespace nn
  123. {
  124.  
  125. // Exceptions
  126. class duplicate_value : public std::logic_error
  127. {
  128. public:
  129. duplicate_value() : std::logic_error("")
  130. {
  131. }
  132. };
  133.  
  134. class duplicate_value_left_to_right : public duplicate_value
  135. {
  136. };
  137.  
  138. class duplicate_value_right_to_left : public duplicate_value
  139. {
  140. };
  141.  
  142. class invalid_direction : public std::logic_error
  143. {
  144. public:
  145. invalid_direction() : std::logic_error("")
  146. {
  147. }
  148. };
  149.  
  150. // Direction
  151. struct bimap_direction
  152. {
  153. typedef int type;
  154.  
  155. enum
  156. {
  157. none_to_none = 0,
  158. left_to_right = 1,
  159. right_to_left = 2,
  160. all_to_all = left_to_right | right_to_left
  161. };
  162.  
  163. static type invert(type direction)
  164. {
  165. switch(direction)
  166. {
  167. case none_to_none: return all_to_all; break;
  168. case left_to_right: return right_to_left; break;
  169. case right_to_left: return left_to_right; break;
  170. case all_to_all: return none_to_none; break;
  171. default: return none_to_none; break;
  172. }
  173. }
  174. };
  175.  
  176. // Bimap Iterator
  177. template<typename BaseIterator, bimap_direction::type DefaultDirection>
  178. class bimap_iterator : public BaseIterator
  179. {
  180. public:
  181. // Typedef
  182. typedef typename BaseIterator::iterator_category iterator_category;
  183. typedef typename BaseIterator::difference_type difference_type;
  184.  
  185. // Convert from std::pair<const, const*> to
  186. // std::pair<const, const* const>
  187. typedef std::pair<
  188. typename BaseIterator::value_type::first_type,
  189. const typename BaseIterator::value_type::second_type
  190. > value_type;
  191.  
  192. typedef value_type* pointer;
  193. typedef value_type& reference;
  194.  
  195. // Constructor
  196. bimap_iterator()
  197. {
  198. }
  199.  
  200. bimap_iterator(const bimap_iterator& right) :
  201. BaseIterator(right)
  202. {
  203. }
  204.  
  205. template<typename BaseIterator2>
  206. bimap_iterator(const bimap_iterator<BaseIterator2, DefaultDirection>& right) :
  207. BaseIterator(right)
  208. {
  209. }
  210.  
  211. template<typename BaseIterator2>
  212. explicit bimap_iterator(BaseIterator2 iterator) :
  213. BaseIterator(iterator)
  214. {
  215. }
  216.  
  217. reference operator*() const
  218. {
  219. return reference(BaseIterator::operator*());
  220. }
  221.  
  222. pointer operator->() const
  223. {
  224. // Safe conversion from const* to const* const
  225. // We use C-style convertion because reinterpret_cast do not work.
  226. return (pointer)(BaseIterator::operator->());
  227. }
  228.  
  229.  
  230. bimap_iterator& operator++()
  231. {
  232. BaseIterator::operator++();
  233. return *this;
  234. }
  235.  
  236. bimap_iterator operator++(int)
  237. {
  238. bimap_iterator temp = *this;
  239. ++*this;
  240. return temp;
  241. }
  242.  
  243. bimap_iterator& operator--()
  244. {
  245. BaseIterator::operator--();
  246. return *this;
  247. }
  248.  
  249. bimap_iterator operator--(int)
  250. {
  251. bimap_iterator temp = *this;
  252. --*this;
  253. return temp;
  254. }
  255. };
  256.  
  257. // BiMap Left-Right members
  258. template<typename BiMap, typename Map, bimap_direction::type DefaultDirection>
  259. class bimap_lr
  260. {
  261. public:
  262. // Typedef
  263. typedef Map map_type;
  264.  
  265. typedef typename map_type::key_type key_type;
  266. typedef typename map_type::mapped_type mapped_type;
  267.  
  268. typedef typename map_type::key_compare key_compare;
  269. typedef typename map_type::value_compare value_compare;
  270. typedef typename map_type::value_type value_type;
  271.  
  272. typedef typename map_type::allocator_type allocator_type;
  273. typedef typename map_type::size_type size_type;
  274. typedef typename map_type::difference_type difference_type;
  275.  
  276. typedef typename map_type::reference reference;
  277. typedef typename map_type::const_reference const_reference;
  278. typedef typename map_type::pointer pointer;
  279. typedef typename map_type::const_pointer const_pointer;
  280.  
  281. typedef bimap_iterator<
  282. typename map_type::iterator,
  283. DefaultDirection
  284. > iterator;
  285.  
  286. typedef bimap_iterator<
  287. typename map_type::const_iterator,
  288. DefaultDirection
  289. > const_iterator;
  290.  
  291. typedef bimap_iterator<
  292. typename map_type::reverse_iterator,
  293. DefaultDirection
  294. > reverse_iterator;
  295.  
  296. typedef bimap_iterator<
  297. typename map_type::const_reverse_iterator,
  298. DefaultDirection
  299. > const_reverse_iterator;
  300.  
  301. bimap_lr(map_type& map) : m_map(map)
  302. {
  303. }
  304.  
  305. bimap_lr(const bimap_lr& right) : m_map(right.m_map)
  306. {
  307. }
  308.  
  309. bimap_lr& operator=(const bimap_lr& right)
  310. {
  311. m_map = right.m_map;
  312. return *this;
  313. }
  314.  
  315. allocator_type get_allocator() const
  316. {
  317. return m_map.get_allocator();
  318. }
  319.  
  320. iterator begin()
  321. {
  322. return iterator(m_map.begin());
  323. }
  324.  
  325. const_iterator begin() const
  326. {
  327. return const_iterator(m_map.begin());
  328. }
  329.  
  330. reverse_iterator rbegin()
  331. {
  332. return reverse_iterator(m_map.rbegin());
  333. }
  334.  
  335. const_reverse_iterator rbegin() const
  336. {
  337. return const_reverse_iterator(m_map.rbegin());
  338. }
  339.  
  340. iterator end()
  341. {
  342. return iterator(m_map.end());
  343. }
  344.  
  345. const_iterator end() const
  346. {
  347. return const_iterator(m_map.end());
  348. }
  349.  
  350. reverse_iterator rend()
  351. {
  352. return reverse_iterator(m_map.rend());
  353. }
  354.  
  355. const_reverse_iterator rend() const
  356. {
  357. return const_reverse_iterator(m_map.rend());
  358. }
  359.  
  360. bool empty() const
  361. {
  362. return m_map.empty();
  363. }
  364.  
  365. size_type size() const
  366. {
  367. return m_map.size();
  368. }
  369.  
  370. // key_comp
  371. key_compare key_comp() const
  372. {
  373. return m_map.key_comp();
  374. }
  375.  
  376. // value_comp
  377. value_compare value_comp() const
  378. {
  379. return m_map.value_comp();
  380. }
  381.  
  382. // Map operations
  383. // find
  384. iterator find(const key_type& key)
  385. {
  386. return iterator(m_map.find(key));
  387. }
  388.  
  389. const_iterator find(const key_type& key) const
  390. {
  391. return m_map.find(key);
  392. }
  393.  
  394. // count
  395. size_type count(const key_type& key) const
  396. {
  397. return m_map.count(key);
  398. }
  399.  
  400. // lower_bound
  401. iterator lower_bound(const key_type& key)
  402. {
  403. m_map.lower_bound(key);
  404. }
  405.  
  406. const_iterator lower_bound(const key_type& key) const
  407. {
  408. m_map.lower_bound(key);
  409. }
  410.  
  411. // upper_bound
  412. iterator upper_bound(const key_type& key)
  413. {
  414. m_map.upper_bound(key);
  415. }
  416.  
  417. const_iterator upper_bound(const key_type& key) const
  418. {
  419. m_map.upper_bound(key);
  420. }
  421.  
  422. std::pair<iterator, iterator> equal_range(const key_type& key)
  423. {
  424. return m_map.equal_range(key);
  425. }
  426.  
  427. std::pair<const_iterator, const_iterator> equal_range(const key_type& key) const
  428. {
  429. return m_map.equal_range(key);
  430. }
  431.  
  432. // Special overloading for map class
  433. friend BiMap;
  434.  
  435. private:
  436. typedef typename map_type::iterator map_iterator;
  437. typedef typename map_type::const_iterator map_const_iterator;
  438. typedef typename map_type::reverse_iterator map_reverse_iterator;
  439. typedef typename map_type::const_reverse_iterator map_const_reverse_iterator;
  440.  
  441. map_iterator map_begin()
  442. {
  443. return m_map.begin();
  444. }
  445.  
  446. map_const_iterator map_begin() const
  447. {
  448. return m_map.begin();
  449. }
  450.  
  451. map_reverse_iterator map_rbegin()
  452. {
  453. return m_map.rbegin();
  454. }
  455.  
  456. map_const_reverse_iterator map_rbegin() const
  457. {
  458. return m_map.rbegin();
  459. }
  460.  
  461. map_iterator map_end()
  462. {
  463. return m_map.end();
  464. }
  465.  
  466. map_const_iterator map_end() const
  467. {
  468. return m_map.end();
  469. }
  470.  
  471. map_reverse_iterator map_rend()
  472. {
  473. return m_map.rend();
  474. }
  475.  
  476. map_const_reverse_iterator map_rend() const
  477. {
  478. return m_map.rend();
  479. }
  480.  
  481. private:
  482. map_type& m_map;
  483. };
  484.  
  485. // Bidirectional multimap, from
  486. template<typename Left,
  487. typename Right,
  488. typename CompareLeft = std::less<Left>,
  489. typename CompareRight = std::less<Right>,
  490. typename AllocatorLeft = std::allocator<std::pair<const Left, const Right*> >,
  491. typename AllocatorRight = std::allocator<std::pair<const Right, const Left*> >
  492. >
  493. class bimap_from
  494. {
  495. public:
  496. // Typedef
  497. typedef bimap_from<
  498. Left,
  499. Right,
  500. CompareLeft,
  501. CompareRight,
  502. AllocatorLeft,
  503. AllocatorRight
  504. > this_type;
  505.  
  506. // Map
  507. typedef std::map<
  508. Left,
  509. const Right*,
  510. CompareLeft,
  511. AllocatorLeft
  512. > map_left_type;
  513.  
  514. typedef std::map<
  515. Right,
  516. const Left*,
  517. CompareRight,
  518. AllocatorRight
  519. > map_right_type;
  520.  
  521. // Left to Right
  522. typedef bimap_lr<
  523. this_type,
  524. map_left_type,
  525. bimap_direction::left_to_right
  526. > left_type;
  527.  
  528. // Right to Left
  529. typedef bimap_lr<
  530. this_type,
  531. map_right_type,
  532. bimap_direction::right_to_left
  533. > right_type;
  534.  
  535. // Size
  536. typedef std::size_t size_type;
  537.  
  538. // Value
  539. typedef tripple<Left, Right, bimap_direction::type> value_type;
  540.  
  541. // Iterator pair
  542. typedef std::pair<
  543. typename left_type::iterator,
  544. typename right_type::iterator
  545. > pair_iterator;
  546.  
  547. typedef std::pair<
  548. typename left_type::const_iterator,
  549. typename right_type::const_iterator
  550. > pair_const_iterator;
  551.  
  552. typedef nn::tripple<
  553. typename left_type::map_iterator,
  554. typename right_type::map_iterator,
  555. bimap_direction::type
  556. > map_iterator_type;
  557.  
  558. // Constructor
  559. bimap_from() : left(m_map_left), right(m_map_right)
  560. {
  561. }
  562.  
  563. template<typename ForwardIterator>
  564. bimap_from(ForwardIterator first, ForwardIterator last) :
  565. left(m_map_left),
  566. right(m_map_right)
  567. {
  568. insert(first, last);
  569. }
  570.  
  571. bimap_from(const this_type& r) :
  572. m_map_left(r.m_map_left),
  573. m_map_right(r.m_map_right),
  574. m_count_to(r.m_count_to),
  575. left(r.left),
  576. right(r.right)
  577. {
  578. }
  579.  
  580. // Destructor
  581. ~bimap_from()
  582. {
  583. clear();
  584. }
  585.  
  586. // Assignment
  587. this_type& operator=(const this_type& r)
  588. {
  589. m_map_left = r.m_map_left;
  590. m_map_right = r.m_map_right;
  591.  
  592. m_count_to = r.m_count_to;
  593.  
  594. left = r.left;
  595. right = r.right;
  596.  
  597. return *this;
  598. }
  599.  
  600. // Capacity
  601. bool empty() const
  602. {
  603. return m_map_left.empty() && m_map_right.empty();
  604. }
  605.  
  606. size_type size() const
  607. {
  608. return static_cast<size_type>(std::max(left.size(), right.size()));
  609. }
  610.  
  611. // Modifiers
  612. // insert
  613. pair_const_iterator insert(const value_type& v)
  614. {
  615. typedef typename left_type::map_iterator left_type_iterator;
  616. typedef typename right_type::map_iterator right_type_iterator;
  617.  
  618. // No erase
  619. if(v.third == bimap_direction::none_to_none)
  620. throw invalid_direction();
  621.  
  622. // Insert left
  623. std::pair<left_type_iterator, bool> insert_pair_left =
  624. m_map_left.insert(typename left_type::value_type(v.first, NULL));
  625.  
  626. // Check for duplicates
  627. if(v.third & bimap_direction::left_to_right &&
  628. !insert_pair_left.second &&
  629. insert_pair_left.first->second != NULL)
  630. throw duplicate_value_left_to_right();
  631.  
  632. // Insert right
  633. std::pair<right_type_iterator, bool> insert_pair_right =
  634. m_map_right.insert(typename right_type::value_type(v.second, NULL));
  635.  
  636. // Check for duplicates
  637. if(v.third & bimap_direction::right_to_left &&
  638. !insert_pair_right.second &&
  639. insert_pair_right.first->second != NULL)
  640. {
  641. // Remove value from left if was created
  642. if(insert_pair_left.second)
  643. m_map_left.erase(insert_pair_left.first);
  644.  
  645. throw duplicate_value_right_to_left();
  646. }
  647.  
  648. left_type_iterator& it_left = insert_pair_left.first;
  649. right_type_iterator& it_right = insert_pair_right.first;
  650.  
  651. // Exchange references
  652. if(v.third & bimap_direction::left_to_right)
  653. {
  654. it_left->second = &it_right->first;
  655.  
  656. // Increase reference count
  657. ++m_count_to[&it_right->first];
  658. }
  659. if(v.third & bimap_direction::right_to_left)
  660. {
  661. it_right->second = &it_left->first;
  662.  
  663. // Increase reference count
  664. ++m_count_to[&it_left->first];
  665. }
  666.  
  667. return pair_const_iterator(left_type::const_iterator(),
  668. right_type::const_iterator());
  669. }
  670.  
  671. template<typename ForwardIterator>
  672. void insert(ForwardIterator first, ForwardIterator last)
  673. {
  674. for(; first != last; ++first)
  675. insert(*first);
  676. }
  677.  
  678. // erase
  679. void erase(const map_iterator_type& v)
  680. {
  681. // No insert
  682. if(v.third == bimap_direction::all_to_all)
  683. throw invalid_direction();
  684.  
  685. // Erase type
  686. bimap_direction::type erase_direction = bimap_direction::none_to_none;
  687.  
  688. // Check for direction and reference
  689. if(!(v.third & bimap_direction::left_to_right) &&
  690. v.first->second == &v.second->first)
  691. erase_direction |= bimap_direction::left_to_right;
  692.  
  693. if(!(v.third & bimap_direction::right_to_left) &&
  694. v.second->second == &v.first->first)
  695. erase_direction |= bimap_direction::right_to_left;
  696.  
  697. if(erase_direction == bimap_direction::none_to_none)
  698. return;
  699.  
  700. // Erase
  701. if(erase_direction & bimap_direction::left_to_right)
  702. {
  703. // Decrease reference count
  704. if(--m_count_to[v.second->second] == 0)
  705. {
  706. m_count_to.erase(v.second->second);
  707.  
  708. // Erase item
  709. m_map_right.erase(*v.first->second);
  710. }
  711.  
  712. v.second->second = NULL;
  713. }
  714. if(erase_direction & bimap_direction::right_to_left)
  715. {
  716. // Decrease reference count
  717. if(--m_count_to[v.first->second] == 0)
  718. {
  719. m_count_to.erase(v.first->second);
  720.  
  721. // Erase item
  722. m_map_left.erase(*v.second->second);
  723. }
  724.  
  725. v.first->second = NULL;
  726. }
  727. }
  728.  
  729. void erase(const value_type& v)
  730. {
  731. // No insert
  732. erase(map_iterator_type(m_map_left.find(v.first),
  733. m_map_right.find(v.second),
  734. v.third));
  735. }
  736.  
  737. template<typename ForwardIterator>
  738. void erase(ForwardIterator first, ForwardIterator last)
  739. {
  740. for(; first != last; ++first)
  741. erase(static_cast<const value_type&>(*first));
  742. }
  743.  
  744. // clear
  745. void clear()
  746. {
  747. // Clear all values
  748. m_map_left.clear();
  749. m_map_right.clear();
  750. }
  751.  
  752. // swap
  753. void swap(const this_type& right)
  754. {
  755. m_map_left.swap(right.m_map_left);
  756. m_map_right.swap(right.m_map_right);
  757.  
  758. m_count_to.swap(right.m_count_to);
  759.  
  760. std::swap(left, right.left);
  761. std::swap(right, right.right);
  762. }
  763.  
  764. public:
  765. // Left operations
  766. left_type left;
  767. // Right operations
  768. right_type right;
  769.  
  770. private:
  771. // Left -> Right
  772. map_left_type m_map_left;
  773. // Right -> Left
  774. map_right_type m_map_right;
  775.  
  776. // Reference counting map
  777. std::map<const void*, unsigned> m_count_to;
  778. };
  779.  
  780. // Operations
  781. // Copied from <map>
  782. template<typename Left,
  783. typename Right,
  784. typename CompareLeft,
  785. typename CompareRight,
  786. typename AllocatorLeft,
  787. typename AllocatorRight>
  788. bool operator==(bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& left,
  789. bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& right)
  790. {
  791. return left.left.size() == right.left.size() &&
  792. std::equal(left.left.begin(), left.left.end(), right.left.begin()) &&
  793. left.right.size() == right.right.size() &&
  794. std::equal(left.right.begin(), left.end_y(), right.right.begin());
  795. }
  796.  
  797. template<typename Left,
  798. typename Right,
  799. typename CompareLeft,
  800. typename CompareRight,
  801. typename AllocatorLeft,
  802. typename AllocatorRight>
  803. bool operator!=(bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& left,
  804. bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& right)
  805. {
  806. return !(left == right);
  807. }
  808.  
  809. template<typename Left,
  810. typename Right,
  811. typename CompareLeft,
  812. typename CompareRight,
  813. typename AllocatorLeft,
  814. typename AllocatorRight>
  815. bool operator< (bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& left,
  816. bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& right)
  817. {
  818. return std::lexicographical_compare(left.left.begin(),
  819. left.end_x(),
  820. right.left.begin(),
  821. right.end_x()) &&
  822. std::lexicographical_compare(left.right.begin(),
  823. left.end_y(),
  824. right.right.begin(),
  825. right.end_y());
  826.  
  827. }
  828.  
  829. template<typename Left,
  830. typename Right,
  831. typename CompareLeft,
  832. typename CompareRight,
  833. typename AllocatorLeft,
  834. typename AllocatorRight>
  835. bool operator> (bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& left,
  836. bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& right)
  837. {
  838. return right < left;
  839. }
  840.  
  841. template<typename Left,
  842. typename Right,
  843. typename CompareLeft,
  844. typename CompareRight,
  845. typename AllocatorLeft,
  846. typename AllocatorRight>
  847. bool operator<=(bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& left,
  848. bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& right)
  849. {
  850. return !(right < left);
  851. }
  852.  
  853. template<typename Left,
  854. typename Right,
  855. typename CompareLeft,
  856. typename CompareRight,
  857. typename AllocatorLeft,
  858. typename AllocatorRight>
  859. bool operator>=(bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& left,
  860. bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& right)
  861. {
  862. return !(left < right);
  863. }
  864.  
  865. template<typename Left,
  866. typename Right,
  867. typename CompareLeft,
  868. typename CompareRight,
  869. typename AllocatorLeft,
  870. typename AllocatorRight>
  871. void swap(nn::bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& left,
  872. nn::bimap_from<Left, Right, CompareLeft, CompareRight, AllocatorLeft, AllocatorRight>& right)
  873. {
  874. left.swap(right);
  875. }
  876.  
  877. } // namespace nn
При желании можно довольно просто расширить на полную двухстороннюю карту отображения.

Источник: http://rsdn.ru/forum/Message.aspx?mid=2356475&only=1

+добавить реализацию
 
каталог | задачи | паттерны | исходники | стат | форумы | карта сайта | контакты | ссылки 
© 2000-2021 CodeLAB Group
  Все права защищены
Страница сгенерирована за 0.005537 секунд
Количество запросов к БД: 8, gzip: 11.8kb/124.3kb(91%)