00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef MLN_SET_INTER_HH
00027 # define MLN_SET_INTER_HH
00028 
00032 
00033 # include <algorithm>
00034 # include <iterator>
00035 
00036 # include <mln/core/site_set/p_set.hh>
00037 # include <mln/convert/from_to.hh>
00038 # include <mln/util/ord.hh>
00039 
00040 
00041 
00042 namespace mln
00043 {
00044 
00045   namespace set
00046   {
00047 
00052     template <typename Sl, typename Sr>
00053     p_set<mln_site(Sl)>
00054     inter(const Site_Set<Sl>& lhs, const Site_Set<Sr>& rhs);
00055 
00056 
00057 # ifndef MLN_INCLUDE_ONLY
00058 
00059     template <typename Sl, typename Sr>
00060     inline
00061     p_set<mln_site(Sl)>
00062     inter(const Site_Set<Sl>& lhs, const Site_Set<Sr>& rhs)
00063     {
00064       trace::entering("set::inter");
00065 
00066       typedef mln_site(Sl) P;
00067       mlc_converts_to(mln_psite(Sr), P)::check(); 
00068       std::set< P, util::ord<P> > sl, sr, si;
00069       convert::from_to(lhs, sl);
00070       convert::from_to(rhs, sr);
00071       std::set_intersection(sl.begin(), sl.end(),
00072                             sr.begin(), sr.end(),
00073                             std::inserter(si, si.begin()),
00074                             util::ord<P>());
00075       p_set<P> s;
00076       convert::from_to(si, s);
00077 
00078       trace::exiting("set::inter");
00079       return s;
00080     }
00081 
00082 # endif // ! MLN_INCLUDE_ONLY
00083 
00084   } 
00085 
00086 } 
00087 
00088 
00089 #endif // ! MLN_SET_INTER_HH