2    Copyright (c) 2002-2009 Tampere University.
 
    4    This file is part of TTA-Based Codesign Environment (TCE).
 
    6    Permission is hereby granted, free of charge, to any person obtaining a
 
    7    copy of this software and associated documentation files (the "Software"),
 
    8    to deal in the Software without restriction, including without limitation
 
    9    the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
   10    and/or sell copies of the Software, and to permit persons to whom the
 
   11    Software is furnished to do so, subject to the following conditions:
 
   13    The above copyright notice and this permission notice shall be included in
 
   14    all copies or substantial portions of the Software.
 
   16    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
   17    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
   18    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
   19    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
   20    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
   21    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
   22    DEALINGS IN THE SOFTWARE.
 
   27 * Tools for handling STL Sets.
 
   29 * Inline and template definitions.
 
   31 * @author Heikki Kultala 2008 (hkultala-no.spam-cs.tut.fi)
 
   37 * Creates an intersection of the given containers.
 
   39 * The elements in the intersection are selected by using < and > operators
 
   40 * of the elements in the container. Thus, if both containers contains an
 
   41 * equal element, it is added to the intersection.
 
   43 * @param firstContainer The first container.
 
   44 * @param secondContainer The second container.
 
   45 * @param intersection Intersection of the container is added to this
 
   48template <typename ValueType>
 
   50SetTools::intersection(
 
   51    const std::set<ValueType>& firstContainer,
 
   52    const std::set<ValueType>& secondContainer,
 
   53    std::set<ValueType>& intersection) {
 
   55    std::insert_iterator<std::set<ValueType> >
 
   56        intersectIter(intersection, intersection.end());
 
   57    std::set_intersection(firstContainer.begin(), firstContainer.end(),
 
   58                          secondContainer.begin(), secondContainer.end(),
 
   63 * Creates an intersection of the given containers.
 
   65 * Same as intersection(3), but this returns the intersection instead of
 
   66 * appending existing set via reference.
 
   68 * @param firstContainer The first container.
 
   69 * @param secondContainer The second container.
 
   70 * @returns The intersection.
 
   72template <typename ValueType>
 
   74SetTools::intersection(
 
   75    const std::set<ValueType>& firstContainer,
 
   76    const std::set<ValueType>& secondContainer) {
 
   78    std::set<ValueType> result;
 
   79    std::set_intersection(firstContainer.begin(), firstContainer.end(),
 
   80                          secondContainer.begin(), secondContainer.end(),
 
   81                          std::inserter(result, result.end()));
 
   87 * Creates an intersection of the given containers.
 
   89 * The elements in the intersection are selected by using comparator operator
 
   90 * of the elements in the container. Thus, if both containers contains an
 
   91 * equal element, it is added to the intersection.
 
   93 * @param firstContainer The first container.
 
   94 * @param secondContainer The second container.
 
   95 * @param intersection Intersection of the container is added to this
 
   98template <typename ValueType, typename Comparator>
 
  100SetTools::intersection(
 
  101    const std::set<ValueType, Comparator>& firstContainer,
 
  102    const std::set<ValueType, Comparator>& secondContainer,
 
  103    std::set<ValueType, Comparator>& intersection) {
 
  105    std::insert_iterator<std::set<ValueType, Comparator> >
 
  106        intersectIter(intersection, intersection.end());
 
  107    std::set_intersection(firstContainer.begin(), firstContainer.end(),
 
  108                          secondContainer.begin(), secondContainer.end(),
 
  109                          intersectIter, Comparator());