Compare commits

...

20 Commits

Author SHA1 Message Date
e5ea93bab1 Revert "Merge pull request #14 from nigels-com/merge-hex_lower"
This reverts commit 5412438df5, reversing
changes made to a09963bf93.
2016-03-07 15:43:55 -08:00
5412438df5 Merge pull request #14 from nigels-com/merge-hex_lower
Implement algorithm::hex_lower (Trac ticket #7064)
2016-03-07 14:57:34 -08:00
baa6eca18c Test coverage for algorithm::hex_lower, adapting existing coverage for algorithm::hex 2016-01-31 20:18:22 +10:00
073eb62f64 Another overload of algorithm::hex_lower as lower-case alternative to algorithm::hex 2016-01-31 20:17:23 +10:00
cc1392cae6 Implement algorithm::hex_lower as lower-case alternative to algorithm::hex 2016-01-31 19:11:11 +10:00
a09963bf93 Merge from develop; new feature 'power'; doc fixes; remove usage of C++11 versions of the algorithms 2015-03-18 21:31:53 -07:00
ba1894bfde Manually apply pull request #10 (since it was against master) 2015-03-18 08:39:42 -07:00
0693c80c98 Added meta/libraries.json 2015-01-26 07:08:13 -08:00
d4734356e9 Added more general power functionality as requested by Sean Parent. Also added enable_if to make sure the exponent is an integral type. 2014-12-03 15:15:15 -08:00
85adf4c74e For some reason, these routines were only compiled in for C++11 and less. Make them available all the time. 2014-12-03 15:07:33 -08:00
0c3f9a38f4 Add new algorithm boost::power, which raises a number to an integer power 2014-12-02 14:38:25 -08:00
c5c927bf25 Merge pull request #9 from jzmaddock/patch-1
Remove use of deprecated TR1 library.
2014-09-29 07:47:05 -07:00
eb9079c49c Remove use of deprecated TR1 library. 2014-09-27 13:13:27 +01:00
0a55238652 Removed some debugging code from the test 2014-09-24 10:33:46 -07:00
4dac507b77 Remove code to use standard library versions of algorithms. Always use the boost ones 2014-08-28 10:07:16 -07:00
3fd9c35138 Removed some tabs that snuck in. No functionality change 2014-07-08 08:47:15 -07:00
b9d91c59e4 Add missing ::type in the range-based partition_point implementation. Add test for this call - since there was none before. Thanks to Wygos for the fix. 2014-06-18 19:16:34 +02:00
5af84327ad Merge pull request #1 from pabigot/fixup/hex
hex: remove unreferenced type declaration. Thanks to pabigot.
2014-05-13 15:24:43 -06:00
d121a40f2b Add a missing 'not' to the description for mismatch. Thanks to K-ballo for the catch 2014-05-03 15:13:44 -07:00
9155d4c1cb hex: remove unreferenced type declaration
Presence with gcc -Wunused -Werror produces error.
2013-12-30 07:03:47 -06:00
23 changed files with 218 additions and 84 deletions

View File

@ -60,7 +60,7 @@ mismatch ( c1.end(), c1.end(), c2.end(), c2.end()) --> <c1.end(),
[heading Complexity] [heading Complexity]
Both of the variants of `mismatch` run in ['O(N)] (linear) time; that is, they compare against each element in the list once. If the sequence is found to be equal at any point, the routine will terminate immediately, without examining the rest of the elements. Both of the variants of `mismatch` run in ['O(N)] (linear) time; that is, they compare against each element in the list once. If the sequence is found to be not equal at any point, the routine will terminate immediately, without examining the rest of the elements.
[heading Exception Safety] [heading Exception Safety]

View File

@ -0,0 +1,86 @@
/*
Copyright (c) Marshall Clow 2014.
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)
Revision history:
2 Dec 2014 mtc First version; power
*/
/// \file algorithm.hpp
/// \brief Misc Algorithms
/// \author Marshall Clow
///
#ifndef BOOST_ALGORITHM_HPP
#define BOOST_ALGORITHM_HPP
#include <boost/utility/enable_if.hpp> // for boost::disable_if
#include <boost/type_traits/is_integral.hpp>
namespace boost { namespace algorithm {
template <typename T>
T identity_operation ( std::multiplies<T> ) { return T(1); }
template <typename T>
T identity_operation ( std::plus<T> ) { return T(0); }
/// \fn power ( T x, Integer n )
/// \return the value "x" raised to the power "n"
///
/// \param x The value to be exponentiated
/// \param n The exponent (must be >= 0)
///
// \remark Taken from Knuth, The Art of Computer Programming, Volume 2:
// Seminumerical Algorithms, Section 4.6.3
template <typename T, typename Integer>
typename boost::enable_if<boost::is_integral<Integer>, T>::type
power (T x, Integer n) {
T y = 1; // Should be "T y{1};"
if (n == 0) return y;
while (true) {
if (n % 2 == 1) {
y = x * y;
if (n == 1)
return y;
}
n = n / 2;
x = x * x;
}
return y;
}
/// \fn power ( T x, Integer n, Operation op )
/// \return the value "x" raised to the power "n"
/// using the operaton "op".
///
/// \param x The value to be exponentiated
/// \param n The exponent (must be >= 0)
/// \param op The operation used
///
// \remark Taken from Knuth, The Art of Computer Programming, Volume 2:
// Seminumerical Algorithms, Section 4.6.3
template <typename T, typename Integer, typename Operation>
typename boost::enable_if<boost::is_integral<Integer>, T>::type
power (T x, Integer n, Operation op) {
T y = identity_operation(op);
if (n == 0) return y;
while (true) {
if (n % 2 == 1) {
y = op(x, y);
if (n == 1)
return y;
}
n = n / 2;
x = op(x, x);
}
return y;
}
}}
#endif // BOOST_ALGORITHM_HPP

View File

@ -18,10 +18,6 @@
namespace boost { namespace algorithm { namespace boost { namespace algorithm {
#if __cplusplus >= 201103L
// Use the C++11 versions of all_of if it is available
using std::all_of; // Section 25.2.1
#else
/// \fn all_of ( InputIterator first, InputIterator last, Predicate p ) /// \fn all_of ( InputIterator first, InputIterator last, Predicate p )
/// \return true if all elements in [first, last) satisfy the predicate 'p' /// \return true if all elements in [first, last) satisfy the predicate 'p'
/// \note returns true on an empty range /// \note returns true on an empty range
@ -41,7 +37,6 @@ bool all_of ( InputIterator first, InputIterator last, Predicate p )
return false; return false;
return true; return true;
} }
#endif
/// \fn all_of ( const Range &r, Predicate p ) /// \fn all_of ( const Range &r, Predicate p )
/// \return true if all elements in the range satisfy the predicate 'p' /// \return true if all elements in the range satisfy the predicate 'p'

View File

@ -20,10 +20,6 @@
namespace boost { namespace algorithm { namespace boost { namespace algorithm {
// Use the C++11 versions of any_of if it is available
#if __cplusplus >= 201103L
using std::any_of; // Section 25.2.2
#else
/// \fn any_of ( InputIterator first, InputIterator last, Predicate p ) /// \fn any_of ( InputIterator first, InputIterator last, Predicate p )
/// \return true if any of the elements in [first, last) satisfy the predicate /// \return true if any of the elements in [first, last) satisfy the predicate
/// \note returns false on an empty range /// \note returns false on an empty range
@ -40,7 +36,6 @@ bool any_of ( InputIterator first, InputIterator last, Predicate p )
return true; return true;
return false; return false;
} }
#endif
/// \fn any_of ( const Range &r, Predicate p ) /// \fn any_of ( const Range &r, Predicate p )
/// \return true if any elements in the range satisfy the predicate 'p' /// \return true if any elements in the range satisfy the predicate 'p'

View File

@ -18,10 +18,6 @@
namespace boost { namespace algorithm { namespace boost { namespace algorithm {
#if __cplusplus >= 201103L
// Use the C++11 versions of copy_if if it is available
using std::copy_if; // Section 25.3.1
#else
/// \fn copy_if ( InputIterator first, InputIterator last, OutputIterator result, Predicate p ) /// \fn copy_if ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
/// \brief Copies all the elements from the input range that satisfy the /// \brief Copies all the elements from the input range that satisfy the
/// predicate to the output range. /// predicate to the output range.
@ -42,7 +38,6 @@ OutputIterator copy_if ( InputIterator first, InputIterator last, OutputIterator
*result++ = *first; *result++ = *first;
return result; return result;
} }
#endif
/// \fn copy_if ( const Range &r, OutputIterator result, Predicate p ) /// \fn copy_if ( const Range &r, OutputIterator result, Predicate p )
/// \brief Copies all the elements from the input range that satisfy the /// \brief Copies all the elements from the input range that satisfy the

View File

@ -16,10 +16,6 @@
namespace boost { namespace algorithm { namespace boost { namespace algorithm {
#if __cplusplus >= 201103L
// Use the C++11 versions of copy_n if it is available
using std::copy_n; // Section 25.3.1
#else
/// \fn copy_n ( InputIterator first, Size n, OutputIterator result ) /// \fn copy_n ( InputIterator first, Size n, OutputIterator result )
/// \brief Copies exactly n (n > 0) elements from the range starting at first to /// \brief Copies exactly n (n > 0) elements from the range starting at first to
/// the range starting at result. /// the range starting at result.
@ -38,7 +34,6 @@ OutputIterator copy_n ( InputIterator first, Size n, OutputIterator result )
*result = *first; *result = *first;
return result; return result;
} }
#endif
}} // namespace boost and algorithm }} // namespace boost and algorithm
#endif // BOOST_ALGORITHM_COPY_IF_HPP #endif // BOOST_ALGORITHM_COPY_IF_HPP

View File

@ -19,10 +19,6 @@
namespace boost { namespace algorithm { namespace boost { namespace algorithm {
#if __cplusplus >= 201103L
// Use the C++11 versions of find_if_not if it is available
using std::find_if_not; // Section 25.2.5
#else
/// \fn find_if_not(InputIterator first, InputIterator last, Predicate p) /// \fn find_if_not(InputIterator first, InputIterator last, Predicate p)
/// \brief Finds the first element in the sequence that does not satisfy the predicate. /// \brief Finds the first element in the sequence that does not satisfy the predicate.
/// \return The iterator pointing to the desired element. /// \return The iterator pointing to the desired element.
@ -41,7 +37,6 @@ InputIterator find_if_not ( InputIterator first, InputIterator last, Predicate p
break; break;
return first; return first;
} }
#endif
/// \fn find_if_not ( const Range &r, Predicate p ) /// \fn find_if_not ( const Range &r, Predicate p )
/// \brief Finds the first element in the sequence that does not satisfy the predicate. /// \brief Finds the first element in the sequence that does not satisfy the predicate.

View File

@ -19,10 +19,6 @@
namespace boost { namespace algorithm { namespace boost { namespace algorithm {
#if __cplusplus >= 201103L
// Use the C++11 versions of iota if it is available
using std::iota; // Section 26.7.6
#else
/// \fn iota ( ForwardIterator first, ForwardIterator last, T value ) /// \fn iota ( ForwardIterator first, ForwardIterator last, T value )
/// \brief Generates an increasing sequence of values, and stores them in [first, last) /// \brief Generates an increasing sequence of values, and stores them in [first, last)
/// ///
@ -38,7 +34,6 @@ void iota ( ForwardIterator first, ForwardIterator last, T value )
for ( ; first != last; ++first, ++value ) for ( ; first != last; ++first, ++value )
*first = value; *first = value;
} }
#endif
/// \fn iota ( Range &r, T value ) /// \fn iota ( Range &r, T value )
/// \brief Generates an increasing sequence of values, and stores them in the input Range. /// \brief Generates an increasing sequence of values, and stores them in the input Range.

View File

@ -19,10 +19,6 @@
namespace boost { namespace algorithm { namespace boost { namespace algorithm {
#if __cplusplus >= 201103L
// Use the C++11 versions of is_partitioned if it is available
using std::is_partitioned; // Section 25.3.13
#else
/// \fn is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p ) /// \fn is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p )
/// \brief Tests to see if a sequence is partitioned according to a predicate /// \brief Tests to see if a sequence is partitioned according to a predicate
/// ///
@ -45,7 +41,6 @@ bool is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p
return false; return false;
return true; return true;
} }
#endif
/// \fn is_partitioned ( const Range &r, UnaryPredicate p ) /// \fn is_partitioned ( const Range &r, UnaryPredicate p )
/// \brief Generates an increasing sequence of values, and stores them in the input Range. /// \brief Generates an increasing sequence of values, and stores them in the input Range.

View File

@ -99,11 +99,6 @@ namespace detail {
} }
/// \endcond /// \endcond
#if __cplusplus >= 201103L
// Use the C++11 versions of is_permutation if it is available
using std::is_permutation; // Section 25.2.12
#else
/// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 first2, BinaryPredicate p ) /// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 first2, BinaryPredicate p )
/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 /// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2
/// ///
@ -161,8 +156,6 @@ bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIt
return true; return true;
} }
#endif
/// \fn is_permutation ( const Range &r, ForwardIterator first2 ) /// \fn is_permutation ( const Range &r, ForwardIterator first2 )
/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 /// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2

View File

@ -26,11 +26,6 @@
namespace boost { namespace algorithm { namespace boost { namespace algorithm {
#if __cplusplus >= 201103L
// Use the C++11 versions of is_sorted/is_sorted_until if they are available
using std::is_sorted_until; // Section 25.4.1.5
using std::is_sorted; // Section 25.4.1.5
#else
/// \fn is_sorted_until ( ForwardIterator first, ForwardIterator last, Pred p ) /// \fn is_sorted_until ( ForwardIterator first, ForwardIterator last, Pred p )
/// \return the point in the sequence [first, last) where the elements are unordered /// \return the point in the sequence [first, last) where the elements are unordered
/// (according to the comparison predicate 'p'). /// (according to the comparison predicate 'p').
@ -91,7 +86,6 @@ using std::is_sorted; // Section 25.4.1.5
{ {
return boost::algorithm::is_sorted_until (first, last) == last; return boost::algorithm::is_sorted_until (first, last) == last;
} }
#endif
/// ///
/// -- Range based versions of the C++11 functions /// -- Range based versions of the C++11 functions

View File

@ -18,10 +18,6 @@
namespace boost { namespace algorithm { namespace boost { namespace algorithm {
// Use the C++11 versions of the none_of if it is available
#if __cplusplus >= 201103L
using std::none_of; // Section 25.2.3
#else
/// \fn none_of ( InputIterator first, InputIterator last, Predicate p ) /// \fn none_of ( InputIterator first, InputIterator last, Predicate p )
/// \return true if none of the elements in [first, last) satisfy the predicate 'p' /// \return true if none of the elements in [first, last) satisfy the predicate 'p'
/// \note returns true on an empty range /// \note returns true on an empty range
@ -38,7 +34,6 @@ for ( ; first != last; ++first )
return false; return false;
return true; return true;
} }
#endif
/// \fn none_of ( const Range &r, Predicate p ) /// \fn none_of ( const Range &r, Predicate p )
/// \return true if none of the elements in the range satisfy the predicate 'p' /// \return true if none of the elements in the range satisfy the predicate 'p'

View File

@ -20,10 +20,6 @@
namespace boost { namespace algorithm { namespace boost { namespace algorithm {
#if __cplusplus >= 201103L
// Use the C++11 versions of partition_copy if it is available
using std::partition_copy; // Section 25.3.13
#else
/// \fn partition_copy ( InputIterator first, InputIterator last, /// \fn partition_copy ( InputIterator first, InputIterator last,
/// OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p ) /// OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p )
/// \brief Copies the elements that satisfy the predicate p from the range [first, last) /// \brief Copies the elements that satisfy the predicate p from the range [first, last)
@ -53,7 +49,6 @@ partition_copy ( InputIterator first, InputIterator last,
*out_false++ = *first; *out_false++ = *first;
return std::pair<OutputIterator1, OutputIterator2> ( out_true, out_false ); return std::pair<OutputIterator1, OutputIterator2> ( out_true, out_false );
} }
#endif
/// \fn partition_copy ( const Range &r, /// \fn partition_copy ( const Range &r,
/// OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p ) /// OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p )

View File

@ -19,10 +19,6 @@
namespace boost { namespace algorithm { namespace boost { namespace algorithm {
#if __cplusplus >= 201103L
// Use the C++11 versions of partition_point if it is available
using std::partition_point; // Section 25.3.13
#else
/// \fn partition_point ( ForwardIterator first, ForwardIterator last, Predicate p ) /// \fn partition_point ( ForwardIterator first, ForwardIterator last, Predicate p )
/// \brief Given a partitioned range, returns the partition point, i.e, the first element /// \brief Given a partitioned range, returns the partition point, i.e, the first element
/// that does not satisfy p /// that does not satisfy p
@ -52,7 +48,6 @@ ForwardIterator partition_point ( ForwardIterator first, ForwardIterator last, P
} }
return first; return first;
} }
#endif
/// \fn partition_point ( Range &r, Predicate p ) /// \fn partition_point ( Range &r, Predicate p )
/// \brief Given a partitioned range, returns the partition point /// \brief Given a partitioned range, returns the partition point
@ -61,7 +56,7 @@ ForwardIterator partition_point ( ForwardIterator first, ForwardIterator last, P
/// \param p The predicate to test the values with /// \param p The predicate to test the values with
/// ///
template <typename Range, typename Predicate> template <typename Range, typename Predicate>
typename boost::range_iterator<Range> partition_point ( Range &r, Predicate p ) typename boost::range_iterator<Range>::type partition_point ( Range &r, Predicate p )
{ {
return boost::algorithm::partition_point (boost::begin(r), boost::end(r), p); return boost::algorithm::partition_point (boost::begin(r), boost::end(r), p);
} }

View File

@ -22,7 +22,6 @@
namespace boost { namespace algorithm { namespace boost { namespace algorithm {
#if __cplusplus <= 201103L
/// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, /// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last,
/// ForwardIterator2 first2, ForwardIterator2 last2 ) /// ForwardIterator2 first2, ForwardIterator2 last2 )
/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 /// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2
@ -40,10 +39,10 @@ bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1,
{ {
// How should I deal with the idea that ForwardIterator1::value_type // How should I deal with the idea that ForwardIterator1::value_type
// and ForwardIterator2::value_type could be different? Define my own comparison predicate? // and ForwardIterator2::value_type could be different? Define my own comparison predicate?
std::pair<ForwardIterator1, ForwardIterator2> eq = boost::algorithm::mismatch std::pair<ForwardIterator1, ForwardIterator2> eq = boost::algorithm::mismatch
( first1, last1, first2, last2 ); ( first1, last1, first2, last2 );
if ( eq.first == last1 && eq.second == last2) if ( eq.first == last1 && eq.second == last2)
return true; return true;
return boost::algorithm::detail::is_permutation_tag ( return boost::algorithm::detail::is_permutation_tag (
eq.first, last1, eq.second, last2, eq.first, last1, eq.second, last2,
std::equal_to<typename std::iterator_traits<ForwardIterator1>::value_type> (), std::equal_to<typename std::iterator_traits<ForwardIterator1>::value_type> (),
@ -70,16 +69,15 @@ bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2, ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred ) BinaryPredicate pred )
{ {
std::pair<ForwardIterator1, ForwardIterator2> eq = boost::algorithm::mismatch std::pair<ForwardIterator1, ForwardIterator2> eq = boost::algorithm::mismatch
( first1, last1, first2, last2, pred ); ( first1, last1, first2, last2, pred );
if ( eq.first == last1 && eq.second == last2) if ( eq.first == last1 && eq.second == last2)
return true; return true;
return boost::algorithm::detail::is_permutation_tag ( return boost::algorithm::detail::is_permutation_tag (
first1, last1, first2, last2, pred, first1, last1, first2, last2, pred,
typename std::iterator_traits<ForwardIterator1>::iterator_category (), typename std::iterator_traits<ForwardIterator1>::iterator_category (),
typename std::iterator_traits<ForwardIterator2>::iterator_category ()); typename std::iterator_traits<ForwardIterator2>::iterator_category ());
} }
#endif
}} }}

View File

@ -207,7 +207,6 @@ OutputIterator unhex ( InputIterator first, InputIterator last, OutputIterator o
/// \note Based on the MySQL function of the same name /// \note Based on the MySQL function of the same name
template <typename T, typename OutputIterator> template <typename T, typename OutputIterator>
OutputIterator unhex ( const T *ptr, OutputIterator out ) { OutputIterator unhex ( const T *ptr, OutputIterator out ) {
typedef typename detail::hex_iterator_traits<OutputIterator>::value_type OutputType;
// If we run into the terminator while decoding, we will throw a // If we run into the terminator while decoding, we will throw a
// malformed input exception. It would be nicer to throw a 'Not enough input' // malformed input exception. It would be nicer to throw a 'Not enough input'
// exception - but how much extra work would that require? // exception - but how much extra work would that require?

View File

@ -21,7 +21,7 @@
#include <boost/array.hpp> #include <boost/array.hpp>
#ifdef BOOST_NO_CXX11_HDR_UNORDERED_MAP #ifdef BOOST_NO_CXX11_HDR_UNORDERED_MAP
#include <boost/tr1/tr1/unordered_map> #include <boost/unordered_map.hpp>
#else #else
#include <unordered_map> #include <unordered_map>
#endif #endif
@ -40,7 +40,7 @@ namespace boost { namespace algorithm { namespace detail {
class skip_table<key_type, value_type, false> { class skip_table<key_type, value_type, false> {
private: private:
#ifdef BOOST_NO_CXX11_HDR_UNORDERED_MAP #ifdef BOOST_NO_CXX11_HDR_UNORDERED_MAP
typedef std::tr1::unordered_map<key_type, value_type> skip_map; typedef boost::unordered_map<key_type, value_type> skip_map;
#else #else
typedef std::unordered_map<key_type, value_type> skip_map; typedef std::unordered_map<key_type, value_type> skip_map;
#endif #endif

View File

@ -230,7 +230,12 @@ namespace boost {
\post eof()==true \post eof()==true
*/ */
split_iterator() { m_bEof = true; } split_iterator() :
m_Next(),
m_End(),
m_bEof(true)
{}
//! Copy constructor //! Copy constructor
/*! /*!
Construct a copy of the split_iterator Construct a copy of the split_iterator

47
meta/libraries.json Normal file
View File

@ -0,0 +1,47 @@
[
{
"key": "algorithm",
"name": "Algorithm",
"authors": [
"Marshall Clow"
],
"description": "A collection of useful generic algorithms.",
"category": [
"Algorithms"
],
"maintainers": [
"Marshall Clow <marshall -at- idio.com>"
]
},
{
"key": "algorithm/minmax",
"name": "Min-Max",
"authors": [
"Hervé Brönnimann"
],
"description": "Standard library extensions for simultaneous min/max and min/max element computations.",
"documentation": "minmax/",
"category": [
"Algorithms"
],
"maintainers": [
"Marshall Clow <marshall -at- idio.com>"
]
},
{
"key": "algorithm/string",
"name": "String Algo",
"authors": [
"Pavol Droba"
],
"description": "String algorithms library.",
"documentation": "string/",
"category": [
"Algorithms",
"String"
],
"maintainers": [
"Marshall Clow <marshall -at- idio.com>"
]
}
]

View File

@ -27,8 +27,10 @@ alias unit_test_framework
[ compile-fail search_fail2.cpp : : : : ] [ compile-fail search_fail2.cpp : : : : ]
[ compile-fail search_fail3.cpp : : : : ] [ compile-fail search_fail3.cpp : : : : ]
# Clamp tests # Misc tests
[ run clamp_test.cpp unit_test_framework : : : : clamp_test ] [ run clamp_test.cpp unit_test_framework : : : : clamp_test ]
[ run power_test.cpp unit_test_framework : : : : power_test ]
[ compile-fail power_fail1.cpp : : : : ]
# Cxx11 tests # Cxx11 tests
[ run all_of_test.cpp unit_test_framework : : : : all_of_test ] [ run all_of_test.cpp unit_test_framework : : : : all_of_test ]

View File

@ -43,16 +43,17 @@ void test_sequence ( Container &v, Predicate comp, int expected ) {
res = ba::partition_point ( v.begin (), v.end (), comp ); res = ba::partition_point ( v.begin (), v.end (), comp );
exp = offset_to_iter ( v, expected ); exp = offset_to_iter ( v, expected );
std::cout << "Expected(1): " << std::distance ( v.begin (), exp )
<< ", got: " << std::distance ( v.begin (), res ) << std::endl;
BOOST_CHECK ( exp == res ); BOOST_CHECK ( exp == res );
// Duplicate the last element; this checks for any even/odd problems // Duplicate the last element; this checks for any even/odd problems
v.push_back ( * v.rbegin ()); v.push_back ( * v.rbegin ());
res = ba::partition_point ( v.begin (), v.end (), comp ); res = ba::partition_point ( v.begin (), v.end (), comp );
exp = offset_to_iter ( v, expected ); exp = offset_to_iter ( v, expected );
std::cout << "Expected(2): " << std::distance ( v.begin (), exp ) BOOST_CHECK ( exp == res );
<< ", got: " << std::distance ( v.begin (), res ) << std::endl;
// Range based test
res = ba::partition_point ( v, comp );
exp = offset_to_iter ( v, expected );
BOOST_CHECK ( exp == res ); BOOST_CHECK ( exp == res );
} }

24
test/power_fail1.cpp Normal file
View File

@ -0,0 +1,24 @@
/*
Copyright (c) Marshall Clow 2014.
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)
For more information, see http://www.boost.org
*/
#include <iostream>
#include <boost/config.hpp>
#include <boost/algorithm/algorithm.hpp>
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
namespace ba = boost::algorithm;
BOOST_AUTO_TEST_CASE( test_main )
{
// Second argument must be an integral value
BOOST_CHECK ( ba::power(1, 1.0) == 1);
}

35
test/power_test.cpp Normal file
View File

@ -0,0 +1,35 @@
/*
Copyright (c) Marshall Clow 2014.
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)
For more information, see http://www.boost.org
*/
#include <iostream>
#include <boost/config.hpp>
#include <boost/algorithm/algorithm.hpp>
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
namespace ba = boost::algorithm;
BOOST_AUTO_TEST_CASE( test_main )
{
BOOST_CHECK ( ba::power(0, 0) == 1);
BOOST_CHECK ( ba::power(5, 0) == 1);
BOOST_CHECK ( ba::power(1, 1) == 1);
BOOST_CHECK ( ba::power(1, 4) == 1);
BOOST_CHECK ( ba::power(3, 2) == 9);
BOOST_CHECK ( ba::power(2, 3) == 8);
BOOST_CHECK ( ba::power(3, 3) == 27);
BOOST_CHECK ( ba::power(2, 30) == 0x40000000);
BOOST_CHECK ( ba::power(5L, 10) == 3125*3125);
BOOST_CHECK ( ba::power(18, 3) == 18*18*18);
BOOST_CHECK ( ba::power(3,2) == ba::power(3,2, std::multiplies<int>()));
BOOST_CHECK ( ba::power(3,2, std::plus<int>()) == 6);
}