Boost logo

Boost-Commit :

From: jesse_at_[hidden]
Date: 2008-07-23 11:53:24


Author: jesse
Date: 2008-07-23 11:53:23 EDT (Wed, 23 Jul 2008)
New Revision: 47725
URL: http://svn.boost.org/trac/boost/changeset/47725

Log:
find_if_not() sequence algorithm

Added:
   sandbox/boost/algorithm/find_if_not.hpp (contents, props changed)
   sandbox/libs/algorithm/find_if_not/
   sandbox/libs/algorithm/find_if_not/test/
   sandbox/libs/algorithm/find_if_not/test/Jamfile.v2 (contents, props changed)
   sandbox/libs/algorithm/find_if_not/test/find_if_not.cpp (contents, props changed)

Added: sandbox/boost/algorithm/find_if_not.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/algorithm/find_if_not.hpp 2008-07-23 11:53:23 EDT (Wed, 23 Jul 2008)
@@ -0,0 +1,62 @@
+/*
+ Copyright (C) 2008 Jesse Williamson
+
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+*/
+
+#ifndef BOOST_ALGORITHM_SEQUENCE_FIND_IF_NOT_HPP
+ #define BOOST_ALGORITHM_SEQUENCE_FIND_IF_NOT_HPP
+
+#include <boost/range.hpp>
+
+/// \file find_if_not.hpp
+/// \brief Boost implementation of find_if_not() algorithm.
+/// \author Jesse Williamson
+
+namespace boost { namespace algorithm { namespace sequence {
+
+/// \fn InputIterator find_if_not ( InputIterator first, InputIterator last, Predicate pred )
+/// \brief Returns the first iterator in the range [first, last] for which pred is false. Returns [last] if
+/// no such iterator exists.
+///
+/// \param first The start of the input sequence.
+/// \param last One past the end of the input sequence.
+/// \param pred Predicate.
+///
+ template <class InputIterator, class Predicate>
+ InputIterator find_if_not ( InputIterator first, InputIterator last, Predicate pred )
+ {
+ for( ; first != last; ++first )
+ if(! pred( *first ) )
+ return first;
+
+ return last;
+ }
+
+/// \fn InputIterator find_if_not ( ForwardReadableRange& R, Predicate pred )
+/// \brief Returns the first iterator in the range [R] for which pred is false. Returns [R::end] if
+/// no such iterator exists.
+///
+/// \param R A forward readable Boost range input sequence.
+/// \param pred Predicate.
+///
+/*
+ inline typename boost::range_iterator< ForwardReadableRange >::type
+ find( ForwardReadableRange& c, const T& value )
+ {
+ return std::find( boost::begin( c ), boost::end( c ), value );
+ }
+*/
+
+ template <class ForwardReadableRange, class Predicate>
+ typename boost::range_iterator<ForwardReadableRange>::type find_if_not( ForwardReadableRange& R, Predicate pred )
+ {
+ return find_if_not( boost::begin(R), boost::end(R), pred );
+ }
+
+}}} // boost::algorithm::sequence
+
+#endif

Added: sandbox/libs/algorithm/find_if_not/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/libs/algorithm/find_if_not/test/Jamfile.v2 2008-07-23 11:53:23 EDT (Wed, 23 Jul 2008)
@@ -0,0 +1,23 @@
+# Boost.Algorithm Library test Jamfile
+#
+# Copyright (C) 2002--2004, Herve Bronnimann
+#
+# Modified 2008, Jesse Williamson
+#
+# Use, modification, and distribution is subject to the Boost Software
+# License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+#
+
+import testing ;
+
+{
+ test-suite algorithm/find_if_not:
+ :
+ [ run find_if_not.cpp
+ : : : : find_if_not ]
+ [ run find_if_not.cpp
+ : : : : find_if_not ]
+ ;
+}
+

Added: sandbox/libs/algorithm/find_if_not/test/find_if_not.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/algorithm/find_if_not/test/find_if_not.cpp 2008-07-23 11:53:23 EDT (Wed, 23 Jul 2008)
@@ -0,0 +1,58 @@
+/* Unit tests for Boost.algorithms.sequence::find_if_not()
+ *
+ * Copyright (C) 2008, Jesse Williamson
+ *
+ * Use, modification, and distribution is subject to the Boost Software
+ * License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+*/
+
+#include <boost/test/included/test_exec_monitor.hpp>
+
+#include <boost/algorithm/find_if_not.hpp>
+
+#include <list>
+#include <vector>
+#include <string>
+
+using namespace std;
+
+using namespace boost::algorithm::sequence;
+
+int make_zero(int x)
+{
+ return 0;
+}
+
+string make_z(string x)
+{
+ return "z";
+}
+
+int test_main(int, char **)
+{
+ // Basic test:
+ {
+ vector<int> v(3);
+
+ v[0] = 1;
+ v[1] = 2;
+ v[2] = 3;
+
+ BOOST_CHECK(v[1] == *(find_if_not(v.begin(), v.end(), std::bind2nd(std::equal_to<int>(), 1))));
+ }
+
+ // Range test:
+ {
+ vector<int> v(3);
+
+ v[0] = 1;
+ v[1] = 2;
+ v[2] = 3;
+
+ BOOST_CHECK(v[1] == *(find_if_not(v, std::bind2nd(std::equal_to<int>(), 1))));
+ }
+
+ return 0;
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk