File indexing completed on 2025-01-18 09:38:17
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_ICL_CONCEPT_ELEMENT_SET_HPP_JOFA_100921
0009 #define BOOST_ICL_CONCEPT_ELEMENT_SET_HPP_JOFA_100921
0010
0011 #include <boost/icl/type_traits/is_combinable.hpp>
0012 #include <boost/icl/concept/set_value.hpp>
0013 #include <boost/icl/detail/std_set.hpp>
0014 #include <boost/icl/detail/set_algo.hpp>
0015
0016
0017 namespace boost{ namespace icl
0018 {
0019
0020
0021
0022
0023
0024
0025
0026
0027 template <class Type>
0028 typename enable_if<is_element_set<Type>, Type>::type&
0029 add(Type& object, const typename Type::value_type& operand)
0030 {
0031 object.insert(operand);
0032 return object;
0033 }
0034
0035
0036
0037 template <class Type>
0038 typename enable_if<is_element_set<Type>, typename Type::iterator>::type
0039 add(Type& object, typename Type::iterator prior,
0040 const typename Type::value_type& operand)
0041 {
0042 return object.insert(prior, operand);
0043 }
0044
0045
0046
0047
0048
0049
0050 template<class Type>
0051 typename enable_if<is_element_set<Type>, Type>::type&
0052 subtract(Type& object, const typename Type::value_type& operand)
0053 {
0054 object.erase(operand);
0055 return object;
0056 }
0057
0058
0059
0060
0061
0062 template<class Type>
0063 inline typename enable_if<is_element_set<Type>, bool>::type
0064 intersects(const Type& object, const typename Type::key_type& operand)
0065 {
0066 return !(object.find(operand) == object.end());
0067 }
0068
0069 template<class Type>
0070 inline typename enable_if<is_element_set<Type>, bool>::type
0071 intersects(const Type& object, const Type& operand)
0072 {
0073 if(iterative_size(object) < iterative_size(operand))
0074 return Set::intersects(object, operand);
0075 else
0076 return Set::intersects(operand, object);
0077 }
0078
0079
0080
0081
0082 template<class Type>
0083 inline typename enable_if<is_element_set<Type>, Type>::type&
0084 flip(Type& object, const typename Type::value_type& operand)
0085 {
0086 typedef typename Type::iterator iterator;
0087 std::pair<iterator,bool> insertion = object.insert(operand);
0088 if(!insertion.second)
0089 object.erase(insertion.first);
0090
0091 return object;
0092 }
0093
0094 template<class Type>
0095 inline typename enable_if<is_element_set<Type>, Type>::type&
0096 operator ^= (Type& object, const typename Type::element_type& operand)
0097 {
0098 return icl::flip(object, operand);
0099 }
0100
0101
0102
0103 template<class Type>
0104 inline typename enable_if<is_element_set<Type>, Type>::type&
0105 operator ^= (Type& object, const Type& operand)
0106 {
0107 typedef typename Type::const_iterator const_iterator;
0108 const_iterator it_ = operand.begin();
0109 while(it_ != operand.end())
0110 icl::flip(object, *it_++);
0111
0112 return object;
0113 }
0114
0115
0116
0117
0118 template<class CharType, class CharTraits, class Type>
0119 inline typename enable_if<is_element_set<Type>, std::basic_ostream<CharType, CharTraits> >::type&
0120 operator << (std::basic_ostream<CharType, CharTraits>& stream, const Type& object)
0121 {
0122 stream << "{";
0123 ICL_const_FORALL(typename Type, it, object)
0124 stream << (*it) << " ";
0125
0126 return stream << "}";
0127 }
0128
0129
0130 }}
0131
0132 #endif
0133
0134