WSF
UtRangeAlgorithm.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef UTRANGEALGORITHM_HPP
13#define UTRANGEALGORITHM_HPP
14
15#include <algorithm>
16#include <map>
17#include <set>
18
19// Helper functions to simplify calling some std::algorithms which are usually
20// used on an entire container
21
22// bool contains(Container, Value);
23template<typename Container>
24bool contains(Container const& c, typename Container::const_reference v)
25{
26 return std::find(c.begin(), c.end(), v) != c.end();
27}
28
29template<typename Key, typename Cmp, typename Alloc>
30bool contains(std::set<Key, Cmp, Alloc> const& s, Key const& k)
31{
32 return s.find(k) != s.end();
33}
34
35template<typename Key, typename Value, typename Cmp, typename Alloc>
36bool contains(std::map<Key, Value, Cmp, Alloc> const& m, Key const& k)
37{
38 return m.find(k) != m.end();
39}
40
41template<typename T>
42void unique(std::vector<T>& aVector)
43{
44 aVector.erase(std::unique(aVector.begin(), aVector.end()), aVector.end());
45}
46
47template<typename T>
48void sort(std::vector<T>& aVector)
49{
50 std::sort(aVector.begin(), aVector.end());
51}
52
53#endif
void sort(std::vector< T > &aVector)
Definition UtRangeAlgorithm.hpp:48
bool contains(Container const &c, typename Container::const_reference v)
Definition UtRangeAlgorithm.hpp:24
void unique(std::vector< T > &aVector)
Definition UtRangeAlgorithm.hpp:42
Copyrights Multiple, All Rights Reserved