1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/detail/algorithm.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,236 @@
1.4 +// (C) Copyright Jeremy Siek 2001.
1.5 +// Distributed under the Boost Software License, Version 1.0. (See accompany-
1.6 +// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
1.7 +
1.8 +/*
1.9 + *
1.10 + * Copyright (c) 1994
1.11 + * Hewlett-Packard Company
1.12 + *
1.13 + * Permission to use, copy, modify, distribute and sell this software
1.14 + * and its documentation for any purpose is hereby granted without fee,
1.15 + * provided that the above copyright notice appear in all copies and
1.16 + * that both that copyright notice and this permission notice appear
1.17 + * in supporting documentation. Hewlett-Packard Company makes no
1.18 + * representations about the suitability of this software for any
1.19 + * purpose. It is provided "as is" without express or implied warranty.
1.20 + *
1.21 + *
1.22 + * Copyright (c) 1996
1.23 + * Silicon Graphics Computer Systems, Inc.
1.24 + *
1.25 + * Permission to use, copy, modify, distribute and sell this software
1.26 + * and its documentation for any purpose is hereby granted without fee,
1.27 + * provided that the above copyright notice appear in all copies and
1.28 + * that both that copyright notice and this permission notice appear
1.29 + * in supporting documentation. Silicon Graphics makes no
1.30 + * representations about the suitability of this software for any
1.31 + * purpose. It is provided "as is" without express or implied warranty.
1.32 + */
1.33 +
1.34 +#ifndef BOOST_ALGORITHM_HPP
1.35 +# define BOOST_ALGORITHM_HPP
1.36 +# include <boost/detail/iterator.hpp>
1.37 +// Algorithms on sequences
1.38 +//
1.39 +// The functions in this file have not yet gone through formal
1.40 +// review, and are subject to change. This is a work in progress.
1.41 +// They have been checked into the detail directory because
1.42 +// there are some graph algorithms that use these functions.
1.43 +
1.44 +#include <algorithm>
1.45 +#include <vector>
1.46 +
1.47 +namespace boost {
1.48 +
1.49 + template <typename Iter1, typename Iter2>
1.50 + Iter1 begin(const std::pair<Iter1, Iter2>& p) { return p.first; }
1.51 +
1.52 + template <typename Iter1, typename Iter2>
1.53 + Iter2 end(const std::pair<Iter1, Iter2>& p) { return p.second; }
1.54 +
1.55 + template <typename Iter1, typename Iter2>
1.56 + typename boost::detail::iterator_traits<Iter1>::difference_type
1.57 + size(const std::pair<Iter1, Iter2>& p) {
1.58 + return std::distance(p.first, p.second);
1.59 + }
1.60 +
1.61 +#if 0
1.62 + // These seem to interfere with the std::pair overloads :(
1.63 + template <typename Container>
1.64 + typename Container::iterator
1.65 + begin(Container& c) { return c.begin(); }
1.66 +
1.67 + template <typename Container>
1.68 + typename Container::const_iterator
1.69 + begin(const Container& c) { return c.begin(); }
1.70 +
1.71 + template <typename Container>
1.72 + typename Container::iterator
1.73 + end(Container& c) { return c.end(); }
1.74 +
1.75 + template <typename Container>
1.76 + typename Container::const_iterator
1.77 + end(const Container& c) { return c.end(); }
1.78 +
1.79 + template <typename Container>
1.80 + typename Container::size_type
1.81 + size(const Container& c) { return c.size(); }
1.82 +#else
1.83 + template <typename T>
1.84 + typename std::vector<T>::iterator
1.85 + begin(std::vector<T>& c) { return c.begin(); }
1.86 +
1.87 + template <typename T>
1.88 + typename std::vector<T>::const_iterator
1.89 + begin(const std::vector<T>& c) { return c.begin(); }
1.90 +
1.91 + template <typename T>
1.92 + typename std::vector<T>::iterator
1.93 + end(std::vector<T>& c) { return c.end(); }
1.94 +
1.95 + template <typename T>
1.96 + typename std::vector<T>::const_iterator
1.97 + end(const std::vector<T>& c) { return c.end(); }
1.98 +
1.99 + template <typename T>
1.100 + typename std::vector<T>::size_type
1.101 + size(const std::vector<T>& c) { return c.size(); }
1.102 +#endif
1.103 +
1.104 + template <class ForwardIterator, class T>
1.105 + void iota(ForwardIterator first, ForwardIterator last, T value)
1.106 + {
1.107 + for (; first != last; ++first, ++value)
1.108 + *first = value;
1.109 + }
1.110 + template <typename Container, typename T>
1.111 + void iota(Container& c, const T& value)
1.112 + {
1.113 + iota(begin(c), end(c), value);
1.114 + }
1.115 +
1.116 + // Also do version with 2nd container?
1.117 + template <typename Container, typename OutIter>
1.118 + OutIter copy(const Container& c, OutIter result) {
1.119 + return std::copy(begin(c), end(c), result);
1.120 + }
1.121 +
1.122 + template <typename Container1, typename Container2>
1.123 + bool equal(const Container1& c1, const Container2& c2)
1.124 + {
1.125 + if (size(c1) != size(c2))
1.126 + return false;
1.127 + return std::equal(begin(c1), end(c1), begin(c2));
1.128 + }
1.129 +
1.130 + template <typename Container>
1.131 + void sort(Container& c) { std::sort(begin(c), end(c)); }
1.132 +
1.133 + template <typename Container, typename Predicate>
1.134 + void sort(Container& c, const Predicate& p) {
1.135 + std::sort(begin(c), end(c), p);
1.136 + }
1.137 +
1.138 + template <typename Container>
1.139 + void stable_sort(Container& c) { std::stable_sort(begin(c), end(c)); }
1.140 +
1.141 + template <typename Container, typename Predicate>
1.142 + void stable_sort(Container& c, const Predicate& p) {
1.143 + std::stable_sort(begin(c), end(c), p);
1.144 + }
1.145 +
1.146 + template <typename InputIterator, typename Predicate>
1.147 + bool any_if(InputIterator first, InputIterator last, Predicate p)
1.148 + {
1.149 + return std::find_if(first, last, p) != last;
1.150 + }
1.151 + template <typename Container, typename Predicate>
1.152 + bool any_if(const Container& c, Predicate p)
1.153 + {
1.154 + return any_if(begin(c), end(c), p);
1.155 + }
1.156 +
1.157 + template <typename InputIterator, typename T>
1.158 + bool contains(InputIterator first, InputIterator last, T value)
1.159 + {
1.160 + return std::find(first, last, value) != last;
1.161 + }
1.162 + template <typename Container, typename T>
1.163 + bool contains(const Container& c, const T& value)
1.164 + {
1.165 + return contains(begin(c), end(c), value);
1.166 + }
1.167 +
1.168 + template <typename InputIterator, typename Predicate>
1.169 + bool all(InputIterator first, InputIterator last, Predicate p)
1.170 + {
1.171 + for (; first != last; ++first)
1.172 + if (!p(*first))
1.173 + return false;
1.174 + return true;
1.175 + }
1.176 + template <typename Container, typename Predicate>
1.177 + bool all(const Container& c, Predicate p)
1.178 + {
1.179 + return all(begin(c), end(c), p);
1.180 + }
1.181 +
1.182 + template <typename Container, typename T>
1.183 + std::size_t count(const Container& c, const T& value)
1.184 + {
1.185 + return std::count(begin(c), end(c), value);
1.186 + }
1.187 +
1.188 + template <typename Container, typename Predicate>
1.189 + std::size_t count_if(const Container& c, Predicate p)
1.190 + {
1.191 + return std::count_if(begin(c), end(c), p);
1.192 + }
1.193 +
1.194 + template <typename ForwardIterator>
1.195 + bool is_sorted(ForwardIterator first, ForwardIterator last)
1.196 + {
1.197 + if (first == last)
1.198 + return true;
1.199 +
1.200 + ForwardIterator next = first;
1.201 + for (++next; next != last; first = next, ++next) {
1.202 + if (*next < *first)
1.203 + return false;
1.204 + }
1.205 +
1.206 + return true;
1.207 + }
1.208 +
1.209 + template <typename ForwardIterator, typename StrictWeakOrdering>
1.210 + bool is_sorted(ForwardIterator first, ForwardIterator last,
1.211 + StrictWeakOrdering comp)
1.212 + {
1.213 + if (first == last)
1.214 + return true;
1.215 +
1.216 + ForwardIterator next = first;
1.217 + for (++next; next != last; first = next, ++next) {
1.218 + if (comp(*next, *first))
1.219 + return false;
1.220 + }
1.221 +
1.222 + return true;
1.223 + }
1.224 +
1.225 + template <typename Container>
1.226 + bool is_sorted(const Container& c)
1.227 + {
1.228 + return is_sorted(begin(c), end(c));
1.229 + }
1.230 +
1.231 + template <typename Container, typename StrictWeakOrdering>
1.232 + bool is_sorted(const Container& c, StrictWeakOrdering comp)
1.233 + {
1.234 + return is_sorted(begin(c), end(c), comp);
1.235 + }
1.236 +
1.237 +} // namespace boost
1.238 +
1.239 +#endif // BOOST_ALGORITHM_HPP