26 #ifndef MLN_CORE_INTERNAL_SET_OF_HH
27 # define MLN_CORE_INTERNAL_SET_OF_HH
38 # include <mln/core/contract.hh>
39 # include <mln/core/internal/force_exact.hh>
72 set_of_<E>& insert(
const E& elt);
83 set_of_<E>&
remove(
const E& elt);
94 const E& element(
unsigned i)
const;
99 unsigned nelements()
const;
108 bool has(
const E& elt)
const;
113 bool is_empty()
const;
132 const std::vector<E>& vect()
const;
146 mutable std::vector<E> v_;
160 void update_()
const;
163 mutable bool needs_update_;
183 # ifndef MLN_INCLUDE_ONLY
185 template <
typename E>
187 set_of_<E>::set_of_()
189 needs_update_ =
false;
192 template <
typename E>
195 set_of_<E>::insert(
const E& elt)
198 if (needs_update_ ==
false)
199 needs_update_ =
true;
200 return internal::force_exact< set_of_<E> >(*this);
203 template <
typename E>
206 set_of_<E>::remove(
const E& elt)
209 if (needs_update_ ==
false)
210 needs_update_ =
true;
211 return internal::force_exact< set_of_<E> >(*this);
214 template <
typename E>
217 set_of_<E>::element(
unsigned i)
const
221 mln_precondition(i < v_.size());
225 template <
typename E>
228 set_of_<E>::nelements()
const
235 template <
typename E>
238 set_of_<E>::has(
const E& elt)
const
240 return s_.find(elt) != s_.end();
243 template <
typename E>
246 set_of_<E>::is_empty()
const
248 return nelements() == 0;
251 template <
typename E>
258 needs_update_ =
false;
259 mln_postcondition(is_empty());
262 template <
typename E>
264 const std::vector<E>&
265 set_of_<E>::vect()
const
272 template <
typename E>
275 set_of_<E>::update_()
const
277 mln_precondition(needs_update_);
279 std::copy(s_.begin(), s_.end(), std::back_inserter(v_));
283 needs_update_ =
false;
299 # endif // ! MLN_INCLUDE_ONLY
306 #endif // ! MLN_CORE_INTERNAL_SET_OF_HH