1042 ///\relates NotMap |
1042 ///\relates NotMap |
1043 template <typename M> |
1043 template <typename M> |
1044 inline NotMap<M> notMap(const M &m) { |
1044 inline NotMap<M> notMap(const M &m) { |
1045 return NotMap<M>(m); |
1045 return NotMap<M>(m); |
1046 } |
1046 } |
1047 |
1047 |
1048 template <typename M> |
1048 template <typename M> |
1049 inline NotWriteMap<M> notMap(M &m) { |
1049 inline NotWriteMap<M> notMap(M &m) { |
1050 return NotWriteMap<M>(m); |
1050 return NotWriteMap<M>(m); |
1051 } |
1051 } |
1052 |
1052 |
1053 namespace _maps_bits { |
1053 namespace _maps_bits { |
|
1054 |
1054 template <typename Value> |
1055 template <typename Value> |
1055 struct Identity { |
1056 struct Identity { |
1056 typedef Value argument_type; |
1057 typedef Value argument_type; |
1057 typedef Value result_type; |
1058 typedef Value result_type; |
1058 Value operator()(const Value& val) { |
1059 Value operator()(const Value& val) const { |
1059 return val; |
1060 return val; |
1060 } |
1061 } |
1061 }; |
1062 }; |
|
1063 |
|
1064 template <typename _Iterator, typename Enable = void> |
|
1065 struct IteratorTraits { |
|
1066 typedef typename std::iterator_traits<_Iterator>::value_type Value; |
|
1067 }; |
|
1068 |
|
1069 template <typename _Iterator> |
|
1070 struct IteratorTraits<_Iterator, |
|
1071 typename exists<typename _Iterator::container_type>::type> |
|
1072 { |
|
1073 typedef typename _Iterator::container_type::value_type Value; |
|
1074 }; |
|
1075 |
1062 } |
1076 } |
1063 |
1077 |
1064 |
1078 |
1065 /// \brief Writable bool map for store each true assigned elements. |
1079 /// \brief Writable bool map for store each true assigned elements. |
1066 /// |
1080 /// |
1083 /// writerMap(ostream_iterator<int>(cout, " "), uedgeIdFunctor); |
1097 /// writerMap(ostream_iterator<int>(cout, " "), uedgeIdFunctor); |
1084 /// |
1098 /// |
1085 /// prim(ugraph, cost, writerMap); |
1099 /// prim(ugraph, cost, writerMap); |
1086 ///\endcode |
1100 ///\endcode |
1087 template <typename _Iterator, |
1101 template <typename _Iterator, |
1088 typename _Functor = |
1102 typename _Functor = |
1089 _maps_bits::Identity<typename std::iterator_traits<_Iterator>::value_type> > |
1103 _maps_bits::Identity<typename _maps_bits:: |
|
1104 IteratorTraits<_Iterator>::Value> > |
1090 class StoreBoolMap { |
1105 class StoreBoolMap { |
1091 public: |
1106 public: |
1092 typedef _Iterator Iterator; |
1107 typedef _Iterator Iterator; |
1093 |
1108 |
1094 typedef typename _Functor::argument_type Key; |
1109 typedef typename _Functor::argument_type Key; |
1109 Iterator end() const { |
1124 Iterator end() const { |
1110 return _end; |
1125 return _end; |
1111 } |
1126 } |
1112 |
1127 |
1113 /// Setter function of the map |
1128 /// Setter function of the map |
1114 void set(const Key& key, Value value) { |
1129 void set(const Key& key, Value value) const { |
1115 if (value) { |
1130 if (value) { |
1116 *_end++ = _functor(key); |
1131 *_end++ = _functor(key); |
1117 } |
1132 } |
1118 } |
1133 } |
1119 |
1134 |
1120 private: |
1135 private: |
1121 Iterator _begin, _end; |
1136 Iterator _begin; |
|
1137 mutable Iterator _end; |
1122 Functor _functor; |
1138 Functor _functor; |
1123 }; |
1139 }; |
1124 |
1140 |
1125 /// \brief Writable bool map for store each true assigned elements in |
1141 /// \brief Writable bool map for store each true assigned elements in |
1126 /// a back insertable container. |
1142 /// a back insertable container. |