1.1 --- a/epoc32/include/stdapis/boost/detail/algorithm.hpp Wed Mar 31 12:27:01 2010 +0100
1.2 +++ b/epoc32/include/stdapis/boost/detail/algorithm.hpp Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -1,103 +1,236 @@
1.4 -#ifndef BOOST_ALGORITHM_RG071801_HPP
1.5 -#define BOOST_ALGORITHM_RG071801_HPP
1.6 +// (C) Copyright Jeremy Siek 2001.
1.7 +// Distributed under the Boost Software License, Version 1.0. (See accompany-
1.8 +// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
1.9
1.10 +/*
1.11 + *
1.12 + * Copyright (c) 1994
1.13 + * Hewlett-Packard Company
1.14 + *
1.15 + * Permission to use, copy, modify, distribute and sell this software
1.16 + * and its documentation for any purpose is hereby granted without fee,
1.17 + * provided that the above copyright notice appear in all copies and
1.18 + * that both that copyright notice and this permission notice appear
1.19 + * in supporting documentation. Hewlett-Packard Company makes no
1.20 + * representations about the suitability of this software for any
1.21 + * purpose. It is provided "as is" without express or implied warranty.
1.22 + *
1.23 + *
1.24 + * Copyright (c) 1996
1.25 + * Silicon Graphics Computer Systems, Inc.
1.26 + *
1.27 + * Permission to use, copy, modify, distribute and sell this software
1.28 + * and its documentation for any purpose is hereby granted without fee,
1.29 + * provided that the above copyright notice appear in all copies and
1.30 + * that both that copyright notice and this permission notice appear
1.31 + * in supporting documentation. Silicon Graphics makes no
1.32 + * representations about the suitability of this software for any
1.33 + * purpose. It is provided "as is" without express or implied warranty.
1.34 + */
1.35 +
1.36 +#ifndef BOOST_ALGORITHM_HPP
1.37 +# define BOOST_ALGORITHM_HPP
1.38 +# include <boost/detail/iterator.hpp>
1.39 +// Algorithms on sequences
1.40 //
1.41 -//
1.42 -// Copyright (c) 1994
1.43 -// Hewlett-Packard Company
1.44 -//
1.45 -// Permission to use, copy, modify, distribute and sell this software
1.46 -// and its documentation for any purpose is hereby granted without fee,
1.47 -// provided that the above copyright notice appear in all copies and
1.48 -// that both that copyright notice and this permission notice appear
1.49 -// in supporting documentation. Hewlett-Packard Company makes no
1.50 -// representations about the suitability of this software for any
1.51 -// purpose. It is provided "as is" without express or implied warranty.
1.52 -//
1.53 -//
1.54 -// Copyright (c) 1996-1998
1.55 -// Silicon Graphics Computer Systems, Inc.
1.56 -//
1.57 -// Permission to use, copy, modify, distribute and sell this software
1.58 -// and its documentation for any purpose is hereby granted without fee,
1.59 -// provided that the above copyright notice appear in all copies and
1.60 -// that both that copyright notice and this permission notice appear
1.61 -// in supporting documentation. Silicon Graphics makes no
1.62 -// representations about the suitability of this software for any
1.63 -// purpose. It is provided "as is" without express or implied warranty.
1.64 -//
1.65 +// The functions in this file have not yet gone through formal
1.66 +// review, and are subject to change. This is a work in progress.
1.67 +// They have been checked into the detail directory because
1.68 +// there are some graph algorithms that use these functions.
1.69
1.70 -// Copyright 2002 The Trustees of Indiana University.
1.71 -
1.72 -// Use, modification and distribution is subject to the Boost Software
1.73 -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.74 -// http://www.boost.org/LICENSE_1_0.txt)
1.75 -
1.76 -// Boost.MultiArray Library
1.77 -// Authors: Ronald Garcia
1.78 -// Jeremy Siek
1.79 -// Andrew Lumsdaine
1.80 -// See http://www.boost.org/libs/multi_array for documentation.
1.81 -
1.82 -
1.83 -#include "boost/iterator.hpp"
1.84 +#include <algorithm>
1.85 +#include <vector>
1.86
1.87 namespace boost {
1.88 -namespace detail {
1.89 -namespace multi_array {
1.90 -//--------------------------------------------------
1.91 -// copy_n (not part of the C++ standard)
1.92 -#if 1
1.93
1.94 -template <class InputIter, class Size, class OutputIter>
1.95 -OutputIter copy_n(InputIter first, Size count,
1.96 - OutputIter result) {
1.97 - for ( ; count > 0; --count) {
1.98 - *result = *first;
1.99 - ++first;
1.100 - ++result;
1.101 + template <typename Iter1, typename Iter2>
1.102 + Iter1 begin(const std::pair<Iter1, Iter2>& p) { return p.first; }
1.103 +
1.104 + template <typename Iter1, typename Iter2>
1.105 + Iter2 end(const std::pair<Iter1, Iter2>& p) { return p.second; }
1.106 +
1.107 + template <typename Iter1, typename Iter2>
1.108 + typename boost::detail::iterator_traits<Iter1>::difference_type
1.109 + size(const std::pair<Iter1, Iter2>& p) {
1.110 + return std::distance(p.first, p.second);
1.111 }
1.112 - return result;
1.113 -}
1.114 -#else // !1
1.115
1.116 -template <class InputIter, class Size, class OutputIter>
1.117 -OutputIter copy_n__(InputIter first, Size count,
1.118 - OutputIter result,
1.119 - std::input_iterator_tag) {
1.120 - for ( ; count > 0; --count) {
1.121 - *result = *first;
1.122 - ++first;
1.123 - ++result;
1.124 +#if 0
1.125 + // These seem to interfere with the std::pair overloads :(
1.126 + template <typename Container>
1.127 + typename Container::iterator
1.128 + begin(Container& c) { return c.begin(); }
1.129 +
1.130 + template <typename Container>
1.131 + typename Container::const_iterator
1.132 + begin(const Container& c) { return c.begin(); }
1.133 +
1.134 + template <typename Container>
1.135 + typename Container::iterator
1.136 + end(Container& c) { return c.end(); }
1.137 +
1.138 + template <typename Container>
1.139 + typename Container::const_iterator
1.140 + end(const Container& c) { return c.end(); }
1.141 +
1.142 + template <typename Container>
1.143 + typename Container::size_type
1.144 + size(const Container& c) { return c.size(); }
1.145 +#else
1.146 + template <typename T>
1.147 + typename std::vector<T>::iterator
1.148 + begin(std::vector<T>& c) { return c.begin(); }
1.149 +
1.150 + template <typename T>
1.151 + typename std::vector<T>::const_iterator
1.152 + begin(const std::vector<T>& c) { return c.begin(); }
1.153 +
1.154 + template <typename T>
1.155 + typename std::vector<T>::iterator
1.156 + end(std::vector<T>& c) { return c.end(); }
1.157 +
1.158 + template <typename T>
1.159 + typename std::vector<T>::const_iterator
1.160 + end(const std::vector<T>& c) { return c.end(); }
1.161 +
1.162 + template <typename T>
1.163 + typename std::vector<T>::size_type
1.164 + size(const std::vector<T>& c) { return c.size(); }
1.165 +#endif
1.166 +
1.167 + template <class ForwardIterator, class T>
1.168 + void iota(ForwardIterator first, ForwardIterator last, T value)
1.169 + {
1.170 + for (; first != last; ++first, ++value)
1.171 + *first = value;
1.172 }
1.173 - return result;
1.174 -}
1.175 + template <typename Container, typename T>
1.176 + void iota(Container& c, const T& value)
1.177 + {
1.178 + iota(begin(c), end(c), value);
1.179 + }
1.180 +
1.181 + // Also do version with 2nd container?
1.182 + template <typename Container, typename OutIter>
1.183 + OutIter copy(const Container& c, OutIter result) {
1.184 + return std::copy(begin(c), end(c), result);
1.185 + }
1.186
1.187 -template <class RAIter, class Size, class OutputIter>
1.188 -inline OutputIter
1.189 -copy_n__(RAIter first, Size count,
1.190 - OutputIter result,
1.191 - std::random_access_iterator_tag) {
1.192 - RAIter last = first + count;
1.193 - return std::copy(first, last, result);
1.194 -}
1.195 + template <typename Container1, typename Container2>
1.196 + bool equal(const Container1& c1, const Container2& c2)
1.197 + {
1.198 + if (size(c1) != size(c2))
1.199 + return false;
1.200 + return std::equal(begin(c1), end(c1), begin(c2));
1.201 + }
1.202
1.203 -template <class InputIter, class Size, class OutputIter>
1.204 -inline OutputIter
1.205 -copy_n__(InputIter first, Size count, OutputIter result) {
1.206 - typedef typename std::iterator_traits<InputIter>::iterator_category cat;
1.207 - return copy_n__(first, count, result, cat());
1.208 -}
1.209 + template <typename Container>
1.210 + void sort(Container& c) { std::sort(begin(c), end(c)); }
1.211
1.212 -template <class InputIter, class Size, class OutputIter>
1.213 -inline OutputIter
1.214 -copy_n(InputIter first, Size count, OutputIter result) {
1.215 - return copy_n__(first, count, result);
1.216 -}
1.217 + template <typename Container, typename Predicate>
1.218 + void sort(Container& c, const Predicate& p) {
1.219 + std::sort(begin(c), end(c), p);
1.220 + }
1.221
1.222 -#endif // 1
1.223 -} // namespace multi_array
1.224 -} // namespace detail
1.225 + template <typename Container>
1.226 + void stable_sort(Container& c) { std::stable_sort(begin(c), end(c)); }
1.227 +
1.228 + template <typename Container, typename Predicate>
1.229 + void stable_sort(Container& c, const Predicate& p) {
1.230 + std::stable_sort(begin(c), end(c), p);
1.231 + }
1.232 +
1.233 + template <typename InputIterator, typename Predicate>
1.234 + bool any_if(InputIterator first, InputIterator last, Predicate p)
1.235 + {
1.236 + return std::find_if(first, last, p) != last;
1.237 + }
1.238 + template <typename Container, typename Predicate>
1.239 + bool any_if(const Container& c, Predicate p)
1.240 + {
1.241 + return any_if(begin(c), end(c), p);
1.242 + }
1.243 +
1.244 + template <typename InputIterator, typename T>
1.245 + bool contains(InputIterator first, InputIterator last, T value)
1.246 + {
1.247 + return std::find(first, last, value) != last;
1.248 + }
1.249 + template <typename Container, typename T>
1.250 + bool contains(const Container& c, const T& value)
1.251 + {
1.252 + return contains(begin(c), end(c), value);
1.253 + }
1.254 +
1.255 + template <typename InputIterator, typename Predicate>
1.256 + bool all(InputIterator first, InputIterator last, Predicate p)
1.257 + {
1.258 + for (; first != last; ++first)
1.259 + if (!p(*first))
1.260 + return false;
1.261 + return true;
1.262 + }
1.263 + template <typename Container, typename Predicate>
1.264 + bool all(const Container& c, Predicate p)
1.265 + {
1.266 + return all(begin(c), end(c), p);
1.267 + }
1.268 +
1.269 + template <typename Container, typename T>
1.270 + std::size_t count(const Container& c, const T& value)
1.271 + {
1.272 + return std::count(begin(c), end(c), value);
1.273 + }
1.274 +
1.275 + template <typename Container, typename Predicate>
1.276 + std::size_t count_if(const Container& c, Predicate p)
1.277 + {
1.278 + return std::count_if(begin(c), end(c), p);
1.279 + }
1.280 +
1.281 + template <typename ForwardIterator>
1.282 + bool is_sorted(ForwardIterator first, ForwardIterator last)
1.283 + {
1.284 + if (first == last)
1.285 + return true;
1.286 +
1.287 + ForwardIterator next = first;
1.288 + for (++next; next != last; first = next, ++next) {
1.289 + if (*next < *first)
1.290 + return false;
1.291 + }
1.292 +
1.293 + return true;
1.294 + }
1.295 +
1.296 + template <typename ForwardIterator, typename StrictWeakOrdering>
1.297 + bool is_sorted(ForwardIterator first, ForwardIterator last,
1.298 + StrictWeakOrdering comp)
1.299 + {
1.300 + if (first == last)
1.301 + return true;
1.302 +
1.303 + ForwardIterator next = first;
1.304 + for (++next; next != last; first = next, ++next) {
1.305 + if (comp(*next, *first))
1.306 + return false;
1.307 + }
1.308 +
1.309 + return true;
1.310 + }
1.311 +
1.312 + template <typename Container>
1.313 + bool is_sorted(const Container& c)
1.314 + {
1.315 + return is_sorted(begin(c), end(c));
1.316 + }
1.317 +
1.318 + template <typename Container, typename StrictWeakOrdering>
1.319 + bool is_sorted(const Container& c, StrictWeakOrdering comp)
1.320 + {
1.321 + return is_sorted(begin(c), end(c), comp);
1.322 + }
1.323 +
1.324 } // namespace boost
1.325
1.326 -#endif // BOOST_ALGORITHM_RG071801_HPP
1.327 +#endif // BOOST_ALGORITHM_HPP