From d161339b9a4f2029dec5e78f197711c4d0b77f1f Mon Sep 17 00:00:00 2001 From: Alexander Zaitsev Date: Tue, 28 Jun 2016 17:18:02 +0300 Subject: [PATCH 1/8] Added is_palindromic() --- boost/algorithm/is_palindromic.hpp | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 boost/algorithm/is_palindromic.hpp diff --git a/boost/algorithm/is_palindromic.hpp b/boost/algorithm/is_palindromic.hpp new file mode 100644 index 0000000..6afa3ac --- /dev/null +++ b/boost/algorithm/is_palindromic.hpp @@ -0,0 +1,50 @@ +#ifndef BOOST_ALGORITHM_is_palindromic_HPP +#define BOOST_ALGORITHM_is_palindromic_HPP + +#include + +#include +#include + +namespace boost { namespace algorithm { + +template +bool is_palindromic(BidirectionalIterator begin, BidirectionalIterator end, Comp comp) +{ + --end; + while(std::distance(begin, end) > 0) + { + if(!comp(*begin, *end)) + { + return false; + } + ++begin; + --end; + } + return true; +} + +template +bool is_palindromic(BidirectionalIterator begin, BidirectionalIterator end) +{ + return is_palindromic(begin, end, + std::equal_to::value_type> ()); +} + + +template +bool is_palindromic(const R& range) +{ + return is_palindromic(boost::begin(range), boost::end(range)); +} + + +template +bool is_palindromic(const R& range, Comp c) +{ + return is_palindromic(boost::begin(range), boost::end(range), c); +} + +}} + +#endif // BOOST_ALGORITHM_is_palindromic_HPP From 97b34e9a68cbad0cedf874a464851b99cf3a1843 Mon Sep 17 00:00:00 2001 From: Alexander Zaitsev Date: Tue, 28 Jun 2016 18:07:31 +0300 Subject: [PATCH 2/8] Fixed is_palindromic() to O(N) --- boost/algorithm/is_palindromic.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/boost/algorithm/is_palindromic.hpp b/boost/algorithm/is_palindromic.hpp index 6afa3ac..bdbf14d 100644 --- a/boost/algorithm/is_palindromic.hpp +++ b/boost/algorithm/is_palindromic.hpp @@ -12,13 +12,17 @@ template bool is_palindromic(BidirectionalIterator begin, BidirectionalIterator end, Comp comp) { --end; - while(std::distance(begin, end) > 0) + while(begin != end) { if(!comp(*begin, *end)) { return false; } ++begin; + if(begin == end) + { + break; + } --end; } return true; From 8424aa7f1db7236e00648dd3dc43dd92f658f43d Mon Sep 17 00:00:00 2001 From: Alexander Zaitsev Date: Tue, 28 Jun 2016 18:29:56 +0300 Subject: [PATCH 3/8] Fixed UB in is_palindromic() --- boost/algorithm/is_palindromic.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/boost/algorithm/is_palindromic.hpp b/boost/algorithm/is_palindromic.hpp index bdbf14d..eaf166f 100644 --- a/boost/algorithm/is_palindromic.hpp +++ b/boost/algorithm/is_palindromic.hpp @@ -11,6 +11,11 @@ namespace boost { namespace algorithm { template bool is_palindromic(BidirectionalIterator begin, BidirectionalIterator end, Comp comp) { + if(begin == end) + { + return true; + } + --end; while(begin != end) { From 7434a8fe672e9a3a097a79010d8f7fc739e8027c Mon Sep 17 00:00:00 2001 From: Alexander Zaitsev Date: Wed, 29 Jun 2016 17:23:52 +0300 Subject: [PATCH 4/8] Added tests and examples for is_palindromic() --- boost/algorithm/is_palindromic.hpp | 64 +++++++++++-- libs/algorithm/example/Jamfile.v2 | 1 + .../example/is_palindromic_example.cpp | 94 +++++++++++++++++++ libs/algorithm/test/Jamfile.v2 | 2 + libs/algorithm/test/is_palindromic_test.cpp | 66 +++++++++++++ 5 files changed, 219 insertions(+), 8 deletions(-) create mode 100644 libs/algorithm/example/is_palindromic_example.cpp create mode 100644 libs/algorithm/test/is_palindromic_test.cpp diff --git a/boost/algorithm/is_palindromic.hpp b/boost/algorithm/is_palindromic.hpp index eaf166f..7696a43 100644 --- a/boost/algorithm/is_palindromic.hpp +++ b/boost/algorithm/is_palindromic.hpp @@ -1,3 +1,17 @@ +/* + Copyright (c) Alexander Zaitsev , 2016 + + 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) + + See http://www.boost.org/ for latest version. +*/ + +/// \file is_palindromic.hpp +/// \brief Checks the input sequence on palindromic. +/// \author Alexander Zaitsev + #ifndef BOOST_ALGORITHM_is_palindromic_HPP #define BOOST_ALGORITHM_is_palindromic_HPP @@ -8,8 +22,18 @@ namespace boost { namespace algorithm { -template -bool is_palindromic(BidirectionalIterator begin, BidirectionalIterator end, Comp comp) +/// \fn is_palindromic ( BidirectionalIterator begin, BidirectionalIterator end, Predicate p ) +/// \return true if the entire sequence is palindromic +/// +/// \param begin The start of the input sequence +/// \param end One past the end of the input sequence +/// \param p A predicate used to compare the values. +/// +/// \note This function will return true for empty sequences and for palindromic +/// sequences. For other sequences function will return false. +/// Complexity: O(N). +template +bool is_palindromic(BidirectionalIterator begin, BidirectionalIterator end, Predicate p) { if(begin == end) { @@ -19,7 +43,7 @@ bool is_palindromic(BidirectionalIterator begin, BidirectionalIterator end, Comp --end; while(begin != end) { - if(!comp(*begin, *end)) + if(!p(*begin, *end)) { return false; } @@ -33,6 +57,15 @@ bool is_palindromic(BidirectionalIterator begin, BidirectionalIterator end, Comp return true; } +/// \fn is_palindromic ( BidirectionalIterator begin, BidirectionalIterator end ) +/// \return true if the entire sequence is palindromic +/// +/// \param begin The start of the input sequence +/// \param end One past the end of the input sequence +/// +/// \note This function will return true for empty sequences and for palindromic +/// sequences. For other sequences function will return false. +/// Complexity: O(N). template bool is_palindromic(BidirectionalIterator begin, BidirectionalIterator end) { @@ -40,18 +73,33 @@ bool is_palindromic(BidirectionalIterator begin, BidirectionalIterator end) std::equal_to::value_type> ()); } - +/// \fn is_palindromic ( const R& range ) +/// \return true if the entire sequence is palindromic +/// +/// \param range The range to be tested. +/// +/// \note This function will return true for empty sequences and for palindromic +/// sequences. For other sequences function will return false. +/// Complexity: O(N). template bool is_palindromic(const R& range) { return is_palindromic(boost::begin(range), boost::end(range)); } - -template -bool is_palindromic(const R& range, Comp c) +/// \fn is_palindromic ( const R& range, Predicate p ) +/// \return true if the entire sequence is palindromic +/// +/// \param range The range to be tested. +/// \param p A predicate used to compare the values. +/// +/// \note This function will return true for empty sequences and for palindromic +/// sequences. For other sequences function will return false. +/// Complexity: O(N). +template +bool is_palindromic(const R& range, Predicate p) { - return is_palindromic(boost::begin(range), boost::end(range), c); + return is_palindromip(boost::begin(range), boost::end(range), p); } }} diff --git a/libs/algorithm/example/Jamfile.v2 b/libs/algorithm/example/Jamfile.v2 index 5b0a50d..079c972 100644 --- a/libs/algorithm/example/Jamfile.v2 +++ b/libs/algorithm/example/Jamfile.v2 @@ -25,3 +25,4 @@ exe ordered_example : ordered_example.cpp ; exe clamp_example : clamp_example.cpp ; exe all_example : all_example.cpp ; exe search_example : search_example.cpp ; +exe is_palindromic_example : is_palindromic_example.cpp; diff --git a/libs/algorithm/example/is_palindromic_example.cpp b/libs/algorithm/example/is_palindromic_example.cpp new file mode 100644 index 0000000..a00c444 --- /dev/null +++ b/libs/algorithm/example/is_palindromic_example.cpp @@ -0,0 +1,94 @@ +/* + Copyright (c) Alexander Zaitsev , 2016 + + 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 +#include +#include +#include +#include + +#include + + +namespace ba = boost::algorithm; + +template +bool funcComparator(const T& v1, const T& v2) +{ + return v1 == v2; +} + +struct functorComparator +{ + template + bool operator()(const T& v1, const T& v2) const + { + return v1 == v2; + } +}; + + +int main ( int /*argc*/, char * /*argv*/ [] ) +{ + //You can this algorithm with iterators(minimum Bidirectional) + std::vector vec{1,2,1}; + if(ba::is_palindromic(vec.begin(), vec.end())) + std::cout << "This container is palindromic" << std::endl; + else + std::cout << "This container is not palindromic" << std::endl; + + + //Of course, you can use const iterators + if(ba::is_palindromic(vec.cbegin(), vec.cend())) + std::cout << "This container is palindromic" << std::endl; + else + std::cout << "This container is not palindromic" << std::endl; + + + //Example with bidirectional iterators + std::list list{1,2,1}; + if(ba::is_palindromic(list.begin(), list.end())) + std::cout << "This container is palindromic" << std::endl; + else + std::cout << "This container is not palindromic" << std::endl; + + + //You can use custom comparators like functions, functors, lambdas + auto lambdaComparator = [](int v1, int v2){ return v1 == v2; }; + auto objFunc = std::function(lambdaComparator); + + if(ba::is_palindromic(vec.begin(), vec.end(), lambdaComparator)) + std::cout << "This container is palindromic" << std::endl; + else + std::cout << "This container is not palindromic" << std::endl; + + if(ba::is_palindromic(vec.begin(), vec.end(), funcComparator)) + std::cout << "This container is palindromic" << std::endl; + else + std::cout << "This container is not palindromic" << std::endl; + + if(ba::is_palindromic(vec.begin(), vec.end(), functorComparator())) + std::cout << "This container is palindromic" << std::endl; + else + std::cout << "This container is not palindromic" << std::endl; + + if(ba::is_palindromic(vec.begin(), vec.end(), objFunc)) + std::cout << "This container is palindromic" << std::endl; + else + std::cout << "This container is not palindromic" << std::endl; + + + //You can use ranges + if(ba::is_palindromic(vec)) + std::cout << "This container is palindromic" << std::endl; + else + std::cout << "This container is not palindromic" << std::endl; + + return 0; +} diff --git a/libs/algorithm/test/Jamfile.v2 b/libs/algorithm/test/Jamfile.v2 index baa0ce2..84c5b5e 100644 --- a/libs/algorithm/test/Jamfile.v2 +++ b/libs/algorithm/test/Jamfile.v2 @@ -63,3 +63,5 @@ run is_partitioned_test1.cpp ; run partition_copy_test1.cpp ; run find_if_not_test1.cpp ; + +run is_palindromic_test.cpp ; diff --git a/libs/algorithm/test/is_palindromic_test.cpp b/libs/algorithm/test/is_palindromic_test.cpp new file mode 100644 index 0000000..e24fa69 --- /dev/null +++ b/libs/algorithm/test/is_palindromic_test.cpp @@ -0,0 +1,66 @@ +/* + Copyright (c) Alexander Zaitsev , 2016 + + 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) + + See http://www.boost.org/ for latest version. +*/ + +#include +#include +#include +#include + +#include +#include + +namespace ba = boost::algorithm; + + +template +bool funcComparator(const T& v1, const T& v2) +{ + return v1 == v2; +} + +struct functorComparator +{ + template + bool operator()(const T& v1, const T& v2) const + { + return v1 == v2; + } +}; + + +static void test_is_palindromic() +{ + const std::list empty; + const std::vector singleElement{'z'}; + int oddNonPalindromic[] = {3,2,2}; + const int evenPalindromic[] = {1,2,2,1}; + + // Test a default operator== + BOOST_CHECK ( ba::is_palindromic(empty)); + BOOST_CHECK ( ba::is_palindromic(singleElement)); + BOOST_CHECK (!ba::is_palindromic(std::begin(oddNonPalindromic), std::end(oddNonPalindromic))); + BOOST_CHECK ( ba::is_palindromic(std::begin(evenPalindromic), std::end(evenPalindromic))); + + //Test the custom comparators + BOOST_CHECK ( ba::is_palindromic(empty.begin(), empty.end(), functorComparator())); + BOOST_CHECK (!ba::is_palindromic(std::begin(oddNonPalindromic), std::end(oddNonPalindromic), funcComparator)); + BOOST_CHECK ( ba::is_palindromic(evenPalindromic, std::equal_to())); + + //Only C++14 or newer + //auto lambdaComparator = [](const auto& v1, const auto& v2){ return v1 == v2; }; + //BOOST_CHECK ( ba::is_palindromic(singleElement, lambdaComparator)); +} + +int test_main( int, char * [] ) +{ + test_is_palindromic(); + + return 0; +} From 7689af86ee2f8c6fe2e75801f795ee9d854883aa Mon Sep 17 00:00:00 2001 From: Alexander Zaitsev Date: Fri, 1 Jul 2016 00:48:09 +0300 Subject: [PATCH 5/8] Added description for is_palindromic --- .idea/Boost-Algorithm.iml | 88 +++++ .idea/misc.xml | 19 ++ .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 473 ++++++++++++++++++++++++++ bin/boostbook_catalog.xml | 9 + bin/project-cache.jam | 5 + libs/algorithm/doc/algorithm.qbk | 1 + libs/algorithm/doc/is_palindromic.qbk | 84 +++++ 9 files changed, 693 insertions(+) create mode 100644 .idea/Boost-Algorithm.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 bin/boostbook_catalog.xml create mode 100644 bin/project-cache.jam create mode 100644 libs/algorithm/doc/is_palindromic.qbk diff --git a/.idea/Boost-Algorithm.iml b/.idea/Boost-Algorithm.iml new file mode 100644 index 0000000..8591463 --- /dev/null +++ b/.idea/Boost-Algorithm.iml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..87a6b24 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6094de4 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..e95eafd --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,473 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1467297019209 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bin/boostbook_catalog.xml b/bin/boostbook_catalog.xml new file mode 100644 index 0000000..e487933 --- /dev/null +++ b/bin/boostbook_catalog.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/bin/project-cache.jam b/bin/project-cache.jam new file mode 100644 index 0000000..da72244 --- /dev/null +++ b/bin/project-cache.jam @@ -0,0 +1,5 @@ +# Automatically generated by Boost.Build. +# Do not edit. + +module config-cache { +} diff --git a/libs/algorithm/doc/algorithm.qbk b/libs/algorithm/doc/algorithm.qbk index c1d2ec4..c91320a 100644 --- a/libs/algorithm/doc/algorithm.qbk +++ b/libs/algorithm/doc/algorithm.qbk @@ -49,6 +49,7 @@ Thanks to all the people who have reviewed this library and made suggestions for [include one_of.qbk] [include is_partitioned.qbk] [include partition_point.qbk] +[include is_palindromic.qbk] [xinclude autodoc.xml] diff --git a/libs/algorithm/doc/is_palindromic.qbk b/libs/algorithm/doc/is_palindromic.qbk new file mode 100644 index 0000000..30b4511 --- /dev/null +++ b/libs/algorithm/doc/is_palindromic.qbk @@ -0,0 +1,84 @@ +[/ File is_palindromic.qbk] + +[section:is_palindromic is_palindromic] + +[/license +Copyright (c) 2016 Alexander Zaitsev + +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) +] + +The header file 'is_palindromic.hpp' contains four variants of a single algorithm, `is_palindromic`. The algorithm tests the sequence and returns true if the sequence is palindromic. + +The routine `is_palindromic` takes a sequence and, optionally, a predicate. It will return true if the predicate returns true for tested elements by algorithm in the sequence. + +The routine come in 4 forms; the first one takes two iterators to define the range. The second form takes two iterators to define the range and a predicate. +The third form takes a single range parameter, and uses Boost.Range to traverse it. And the fourth form takes a single range parameter ( uses Boost.Range to traverse it) and a predicate. + + +[heading interface] + +The function `is_palindromic` returns true if the predicate returns true any tested by algorithm items in the sequence. +There are four versions: +1) takes two iterators. +2) takes two iterators and a predicate. +3) takes a range. +4) takes a range and a predicate. + +`` +template + bool is_palindromic ( BidirectionalIterator begin, BidirectionalIterator end ); +template + bool is_palindromic ( BidirectionalIterator begin, BidirectionalIterator end, Predicate p ); +template + bool is_palindromic ( const Range &r ); +template + bool is_palindromic ( const Range &r, Predicate p ); +`` + + +[heading Examples] + +Given the containers: +const std::list empty, +const std::vector singleElement{'z'}, +int oddNonPalindromic[] = {3,2,2}, +const int evenPalindromic[] = {1,2,2,1}, then +`` + +is_palindromic(empty)) --> true //empty range +is_palindromic(singleElement)) --> true +is_palindromic(std::begin(oddNonPalindromic), std::end(oddNonPalindromic))) --> false +is_palindromic(std::begin(evenPalindromic), std::end(evenPalindromic))) --> true +is_palindromic(empty.begin(), empty.end(), functorComparator())) --> true //empty range +is_palindromic(std::begin(oddNonPalindromic), std::end(oddNonPalindromic), funcComparator)) --> false +is_palindromic(evenPalindromic, std::equal_to())) --> true +`` + +[heading Iterator Requirements] + +`is_palindromic` work on Bidirectional and RandomAccess iterators. + +[heading Complexity] + +All of the variants of `is_palindromic` run in ['O(N)] (linear) time; that is, they compare against each element in the list once. If any of the comparisons not succeed, the algorithm will terminate immediately, without examining the remaining members of the sequence. + +[heading Exception Safety] + +All of the variants of `is_palindromic` take their parameters by value or const reference, and do not depend upon any global state. Therefore, all the routines in this file provide the strong exception guarantee. + +[heading Notes] + +* `is_palindromic` returns true for empty ranges and for single element ranges. + +* If you use version of 'is_palindromic' without custom predicate, 'is_palindromic' uses default 'operator==' for elements. If you want use custom predicate, you must redefine 'operator=='. + +[endsect] + +[/ File is_palindromic.qbk +Copyright 2016 Alexander Zaitsev +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). +] + From 338204757f6917eb5517ca50c56d2354b34ae6aa Mon Sep 17 00:00:00 2001 From: Alexander Zaitsev Date: Fri, 1 Jul 2016 00:50:09 +0300 Subject: [PATCH 6/8] Revert "Added description for is_palindromic" This reverts commit 7689af86ee2f8c6fe2e75801f795ee9d854883aa. --- .idea/Boost-Algorithm.iml | 88 ----- .idea/misc.xml | 19 -- .idea/modules.xml | 8 - .idea/vcs.xml | 6 - .idea/workspace.xml | 473 -------------------------- bin/boostbook_catalog.xml | 9 - bin/project-cache.jam | 5 - libs/algorithm/doc/algorithm.qbk | 1 - libs/algorithm/doc/is_palindromic.qbk | 84 ----- 9 files changed, 693 deletions(-) delete mode 100644 .idea/Boost-Algorithm.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml delete mode 100644 bin/boostbook_catalog.xml delete mode 100644 bin/project-cache.jam delete mode 100644 libs/algorithm/doc/is_palindromic.qbk diff --git a/.idea/Boost-Algorithm.iml b/.idea/Boost-Algorithm.iml deleted file mode 100644 index 8591463..0000000 --- a/.idea/Boost-Algorithm.iml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 87a6b24..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 6094de4..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index e95eafd..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,473 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1467297019209 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/bin/boostbook_catalog.xml b/bin/boostbook_catalog.xml deleted file mode 100644 index e487933..0000000 --- a/bin/boostbook_catalog.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/bin/project-cache.jam b/bin/project-cache.jam deleted file mode 100644 index da72244..0000000 --- a/bin/project-cache.jam +++ /dev/null @@ -1,5 +0,0 @@ -# Automatically generated by Boost.Build. -# Do not edit. - -module config-cache { -} diff --git a/libs/algorithm/doc/algorithm.qbk b/libs/algorithm/doc/algorithm.qbk index c91320a..c1d2ec4 100644 --- a/libs/algorithm/doc/algorithm.qbk +++ b/libs/algorithm/doc/algorithm.qbk @@ -49,7 +49,6 @@ Thanks to all the people who have reviewed this library and made suggestions for [include one_of.qbk] [include is_partitioned.qbk] [include partition_point.qbk] -[include is_palindromic.qbk] [xinclude autodoc.xml] diff --git a/libs/algorithm/doc/is_palindromic.qbk b/libs/algorithm/doc/is_palindromic.qbk deleted file mode 100644 index 30b4511..0000000 --- a/libs/algorithm/doc/is_palindromic.qbk +++ /dev/null @@ -1,84 +0,0 @@ -[/ File is_palindromic.qbk] - -[section:is_palindromic is_palindromic] - -[/license -Copyright (c) 2016 Alexander Zaitsev - -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) -] - -The header file 'is_palindromic.hpp' contains four variants of a single algorithm, `is_palindromic`. The algorithm tests the sequence and returns true if the sequence is palindromic. - -The routine `is_palindromic` takes a sequence and, optionally, a predicate. It will return true if the predicate returns true for tested elements by algorithm in the sequence. - -The routine come in 4 forms; the first one takes two iterators to define the range. The second form takes two iterators to define the range and a predicate. -The third form takes a single range parameter, and uses Boost.Range to traverse it. And the fourth form takes a single range parameter ( uses Boost.Range to traverse it) and a predicate. - - -[heading interface] - -The function `is_palindromic` returns true if the predicate returns true any tested by algorithm items in the sequence. -There are four versions: -1) takes two iterators. -2) takes two iterators and a predicate. -3) takes a range. -4) takes a range and a predicate. - -`` -template - bool is_palindromic ( BidirectionalIterator begin, BidirectionalIterator end ); -template - bool is_palindromic ( BidirectionalIterator begin, BidirectionalIterator end, Predicate p ); -template - bool is_palindromic ( const Range &r ); -template - bool is_palindromic ( const Range &r, Predicate p ); -`` - - -[heading Examples] - -Given the containers: -const std::list empty, -const std::vector singleElement{'z'}, -int oddNonPalindromic[] = {3,2,2}, -const int evenPalindromic[] = {1,2,2,1}, then -`` - -is_palindromic(empty)) --> true //empty range -is_palindromic(singleElement)) --> true -is_palindromic(std::begin(oddNonPalindromic), std::end(oddNonPalindromic))) --> false -is_palindromic(std::begin(evenPalindromic), std::end(evenPalindromic))) --> true -is_palindromic(empty.begin(), empty.end(), functorComparator())) --> true //empty range -is_palindromic(std::begin(oddNonPalindromic), std::end(oddNonPalindromic), funcComparator)) --> false -is_palindromic(evenPalindromic, std::equal_to())) --> true -`` - -[heading Iterator Requirements] - -`is_palindromic` work on Bidirectional and RandomAccess iterators. - -[heading Complexity] - -All of the variants of `is_palindromic` run in ['O(N)] (linear) time; that is, they compare against each element in the list once. If any of the comparisons not succeed, the algorithm will terminate immediately, without examining the remaining members of the sequence. - -[heading Exception Safety] - -All of the variants of `is_palindromic` take their parameters by value or const reference, and do not depend upon any global state. Therefore, all the routines in this file provide the strong exception guarantee. - -[heading Notes] - -* `is_palindromic` returns true for empty ranges and for single element ranges. - -* If you use version of 'is_palindromic' without custom predicate, 'is_palindromic' uses default 'operator==' for elements. If you want use custom predicate, you must redefine 'operator=='. - -[endsect] - -[/ File is_palindromic.qbk -Copyright 2016 Alexander Zaitsev -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). -] - From 810b94e163e388d7d22272945ffcfe82a015c35d Mon Sep 17 00:00:00 2001 From: Alexander Zaitsev Date: Fri, 1 Jul 2016 00:57:47 +0300 Subject: [PATCH 7/8] Fix bad commit --- libs/algorithm/doc/algorithm.qbk | 1 + libs/algorithm/doc/is_palindromic.qbk | 83 +++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 libs/algorithm/doc/is_palindromic.qbk diff --git a/libs/algorithm/doc/algorithm.qbk b/libs/algorithm/doc/algorithm.qbk index c1d2ec4..c91320a 100644 --- a/libs/algorithm/doc/algorithm.qbk +++ b/libs/algorithm/doc/algorithm.qbk @@ -49,6 +49,7 @@ Thanks to all the people who have reviewed this library and made suggestions for [include one_of.qbk] [include is_partitioned.qbk] [include partition_point.qbk] +[include is_palindromic.qbk] [xinclude autodoc.xml] diff --git a/libs/algorithm/doc/is_palindromic.qbk b/libs/algorithm/doc/is_palindromic.qbk new file mode 100644 index 0000000..e009bb3 --- /dev/null +++ b/libs/algorithm/doc/is_palindromic.qbk @@ -0,0 +1,83 @@ +[/ File is_palindromic.qbk] + +[section:is_palindromic is_palindromic] + +[/license +Copyright (c) 2016 Alexander Zaitsev + +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) +] + +The header file 'is_palindromic.hpp' contains four variants of a single algorithm, `is_palindromic`. The algorithm tests the sequence and returns true if the sequence is palindromic. + +The routine `is_palindromic` takes a sequence and, optionally, a predicate. It will return true if the predicate returns true for tested elements by algorithm in the sequence. + +The routine come in 4 forms; the first one takes two iterators to define the range. The second form takes two iterators to define the range and a predicate. +The third form takes a single range parameter, and uses Boost.Range to traverse it. And the fourth form takes a single range parameter ( uses Boost.Range to traverse it) and a predicate. + + +[heading interface] + +The function `is_palindromic` returns true if the predicate returns true any tested by algorithm items in the sequence. +There are four versions: +1) takes two iterators. +2) takes two iterators and a predicate. +3) takes a range. +4) takes a range and a predicate. + +`` +template + bool is_palindromic ( BidirectionalIterator begin, BidirectionalIterator end ); +template + bool is_palindromic ( BidirectionalIterator begin, BidirectionalIterator end, Predicate p ); +template + bool is_palindromic ( const Range &r ); +template + bool is_palindromic ( const Range &r, Predicate p ); +`` + + +[heading Examples] + +Given the containers: +const std::list empty, +const std::vector singleElement{'z'}, +int oddNonPalindromic[] = {3,2,2}, +const int evenPalindromic[] = {1,2,2,1}, then +`` + +is_palindromic(empty)) --> true //empty range +is_palindromic(singleElement)) --> true +is_palindromic(std::begin(oddNonPalindromic), std::end(oddNonPalindromic))) --> false +is_palindromic(std::begin(evenPalindromic), std::end(evenPalindromic))) --> true +is_palindromic(empty.begin(), empty.end(), functorComparator())) --> true //empty range +is_palindromic(std::begin(oddNonPalindromic), std::end(oddNonPalindromic), funcComparator)) --> false +is_palindromic(evenPalindromic, std::equal_to())) --> true +`` + +[heading Iterator Requirements] + +`is_palindromic` work on Bidirectional and RandomAccess iterators. + +[heading Complexity] + +All of the variants of `is_palindromic` run in ['O(N)] (linear) time; that is, they compare against each element in the list once. If any of the comparisons not succeed, the algorithm will terminate immediately, without examining the remaining members of the sequence. + +[heading Exception Safety] + +All of the variants of `is_palindromic` take their parameters by value or const reference, and do not depend upon any global state. Therefore, all the routines in this file provide the strong exception guarantee. + +[heading Notes] + +* `is_palindromic` returns true for empty ranges and for single element ranges. + +* If you use version of 'is_palindromic' without custom predicate, 'is_palindromic' uses default 'operator==' for elements. If you want use custom predicate, you must redefine 'operator=='. + +[endsect] + +[/ File is_palindromic.qbk +Copyright 2016 Alexander Zaitsev +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). +] From 86648f340cd41edddd53e3ce52e1261f6a9fc4ff Mon Sep 17 00:00:00 2001 From: Alexander Zaitsev Date: Sat, 2 Jul 2016 12:39:37 +0300 Subject: [PATCH 8/8] Rename is_palindromic to is_palindrome --- .../{is_palindromic.hpp => is_palindrome.hpp} | 56 +++++------ libs/algorithm/doc/algorithm.qbk | 2 +- libs/algorithm/doc/is_palindrome.qbk | 84 +++++++++++++++++ libs/algorithm/doc/is_palindromic.qbk | 83 ---------------- libs/algorithm/example/Jamfile.v2 | 2 +- .../example/is_palindrome_example.cpp | 94 +++++++++++++++++++ .../example/is_palindromic_example.cpp | 94 ------------------- libs/algorithm/test/Jamfile.v2 | 2 +- ...dromic_test.cpp => is_palindrome_test.cpp} | 26 ++--- 9 files changed, 222 insertions(+), 221 deletions(-) rename boost/algorithm/{is_palindromic.hpp => is_palindrome.hpp} (55%) create mode 100644 libs/algorithm/doc/is_palindrome.qbk delete mode 100644 libs/algorithm/doc/is_palindromic.qbk create mode 100644 libs/algorithm/example/is_palindrome_example.cpp delete mode 100644 libs/algorithm/example/is_palindromic_example.cpp rename libs/algorithm/test/{is_palindromic_test.cpp => is_palindrome_test.cpp} (54%) diff --git a/boost/algorithm/is_palindromic.hpp b/boost/algorithm/is_palindrome.hpp similarity index 55% rename from boost/algorithm/is_palindromic.hpp rename to boost/algorithm/is_palindrome.hpp index 7696a43..38029bb 100644 --- a/boost/algorithm/is_palindromic.hpp +++ b/boost/algorithm/is_palindrome.hpp @@ -8,12 +8,12 @@ See http://www.boost.org/ for latest version. */ -/// \file is_palindromic.hpp -/// \brief Checks the input sequence on palindromic. +/// \file is_palindrome.hpp +/// \brief Checks the input sequence on palindrome. /// \author Alexander Zaitsev -#ifndef BOOST_ALGORITHM_is_palindromic_HPP -#define BOOST_ALGORITHM_is_palindromic_HPP +#ifndef BOOST_ALGORITHM_is_palindrome_HPP +#define BOOST_ALGORITHM_is_palindrome_HPP #include @@ -22,18 +22,18 @@ namespace boost { namespace algorithm { -/// \fn is_palindromic ( BidirectionalIterator begin, BidirectionalIterator end, Predicate p ) -/// \return true if the entire sequence is palindromic +/// \fn is_palindrome ( BidirectionalIterator begin, BidirectionalIterator end, Predicate p ) +/// \return true if the entire sequence is palindrome /// /// \param begin The start of the input sequence /// \param end One past the end of the input sequence /// \param p A predicate used to compare the values. /// -/// \note This function will return true for empty sequences and for palindromic -/// sequences. For other sequences function will return false. +/// \note This function will return true for empty sequences and for palindromes. +/// For other sequences function will return false. /// Complexity: O(N). template -bool is_palindromic(BidirectionalIterator begin, BidirectionalIterator end, Predicate p) +bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predicate p) { if(begin == end) { @@ -57,51 +57,51 @@ bool is_palindromic(BidirectionalIterator begin, BidirectionalIterator end, Pred return true; } -/// \fn is_palindromic ( BidirectionalIterator begin, BidirectionalIterator end ) -/// \return true if the entire sequence is palindromic +/// \fn is_palindrome ( BidirectionalIterator begin, BidirectionalIterator end ) +/// \return true if the entire sequence is palindrome /// /// \param begin The start of the input sequence /// \param end One past the end of the input sequence /// -/// \note This function will return true for empty sequences and for palindromic -/// sequences. For other sequences function will return false. +/// \note This function will return true for empty sequences and for palindromes. +/// For other sequences function will return false. /// Complexity: O(N). template -bool is_palindromic(BidirectionalIterator begin, BidirectionalIterator end) +bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end) { - return is_palindromic(begin, end, + return is_palindrome(begin, end, std::equal_to::value_type> ()); } -/// \fn is_palindromic ( const R& range ) -/// \return true if the entire sequence is palindromic +/// \fn is_palindrome ( const R& range ) +/// \return true if the entire sequence is palindrome /// /// \param range The range to be tested. /// -/// \note This function will return true for empty sequences and for palindromic -/// sequences. For other sequences function will return false. +/// \note This function will return true for empty sequences and for palindromes. +/// For other sequences function will return false. /// Complexity: O(N). template -bool is_palindromic(const R& range) +bool is_palindrome(const R& range) { - return is_palindromic(boost::begin(range), boost::end(range)); + return is_palindrome(boost::begin(range), boost::end(range)); } -/// \fn is_palindromic ( const R& range, Predicate p ) -/// \return true if the entire sequence is palindromic +/// \fn is_palindrome ( const R& range, Predicate p ) +/// \return true if the entire sequence is palindrome /// /// \param range The range to be tested. /// \param p A predicate used to compare the values. /// -/// \note This function will return true for empty sequences and for palindromic -/// sequences. For other sequences function will return false. +/// \note This function will return true for empty sequences and for palindromes. +/// For other sequences function will return false. /// Complexity: O(N). template -bool is_palindromic(const R& range, Predicate p) +bool is_palindrome(const R& range, Predicate p) { - return is_palindromip(boost::begin(range), boost::end(range), p); + return is_palindrome(boost::begin(range), boost::end(range), p); } }} -#endif // BOOST_ALGORITHM_is_palindromic_HPP +#endif // BOOST_ALGORITHM_is_palindrome_HPP diff --git a/libs/algorithm/doc/algorithm.qbk b/libs/algorithm/doc/algorithm.qbk index c91320a..ea476d8 100644 --- a/libs/algorithm/doc/algorithm.qbk +++ b/libs/algorithm/doc/algorithm.qbk @@ -49,7 +49,7 @@ Thanks to all the people who have reviewed this library and made suggestions for [include one_of.qbk] [include is_partitioned.qbk] [include partition_point.qbk] -[include is_palindromic.qbk] +[include is_palindrome.qbk] [xinclude autodoc.xml] diff --git a/libs/algorithm/doc/is_palindrome.qbk b/libs/algorithm/doc/is_palindrome.qbk new file mode 100644 index 0000000..d1477a2 --- /dev/null +++ b/libs/algorithm/doc/is_palindrome.qbk @@ -0,0 +1,84 @@ +[/ File is_palindrome.qbk] + +[section:is_palindrome is_palindrome] + +[/license +Copyright (c) 2016 Alexander Zaitsev + +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) +] + +The header file 'is_palindrome.hpp' contains four variants of a single algorithm, is_palindrome. +The algorithm tests the sequence and returns true if the sequence is a palindrome; i.e, it is identical when traversed either backwards or frontwards. + +The routine `is_palindrome` takes a sequence and, optionally, a predicate. It will return true if the predicate returns true for tested elements by algorithm in the sequence. + +The routine come in 4 forms; the first one takes two iterators to define the range. The second form takes two iterators to define the range and a predicate. +The third form takes a single range parameter, and uses Boost.Range to traverse it. And the fourth form takes a single range parameter ( uses Boost.Range to traverse it) and a predicate. + + +[heading interface] + +The function `is_palindrome` returns true if the predicate returns true any tested by algorithm items in the sequence. +There are four versions: +1) takes two iterators. +2) takes two iterators and a predicate. +3) takes a range. +4) takes a range and a predicate. + +`` +template + bool is_palindrome ( BidirectionalIterator begin, BidirectionalIterator end ); +template + bool is_palindrome ( BidirectionalIterator begin, BidirectionalIterator end, Predicate p ); +template + bool is_palindrome ( const Range &r ); +template + bool is_palindrome ( const Range &r, Predicate p ); +`` + + +[heading Examples] + +Given the containers: +const std::list empty, +const std::vector singleElement{'z'}, +int oddNonPalindrome[] = {3,2,2}, +const int evenPalindrome[] = {1,2,2,1}, then +`` + +is_palindrome(empty)) --> true //empty range +is_palindrome(singleElement)) --> true +is_palindrome(std::begin(oddNonPalindrome), std::end(oddNonPalindrome))) --> false +is_palindrome(std::begin(evenPalindrome), std::end(evenPalindrome))) --> true +is_palindrome(empty.begin(), empty.end(), functorComparator())) --> true //empty range +is_palindrome(std::begin(oddNonPalindrome), std::end(oddNonPalindrome), funcComparator)) --> false +is_palindrome(evenPalindrome, std::equal_to())) --> true +`` + +[heading Iterator Requirements] + +`is_palindrome` work on Bidirectional and RandomAccess iterators. + +[heading Complexity] + +All of the variants of `is_palindrome` run in ['O(N)] (linear) time; that is, they compare against each element in the list once. If any of the comparisons not succeed, the algorithm will terminate immediately, without examining the remaining members of the sequence. + +[heading Exception Safety] + +All of the variants of `is_palindrome` take their parameters by value or const reference, and do not depend upon any global state. Therefore, all the routines in this file provide the strong exception guarantee. + +[heading Notes] + +* `is_palindrome` returns true for empty ranges and for single element ranges. + +* If you use version of 'is_palindrome' without custom predicate, 'is_palindrome' uses default 'operator==' for elements. If you want use custom predicate, you must redefine 'operator=='. + +[endsect] + +[/ File is_palindrome.qbk +Copyright 2016 Alexander Zaitsev +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). +] diff --git a/libs/algorithm/doc/is_palindromic.qbk b/libs/algorithm/doc/is_palindromic.qbk deleted file mode 100644 index e009bb3..0000000 --- a/libs/algorithm/doc/is_palindromic.qbk +++ /dev/null @@ -1,83 +0,0 @@ -[/ File is_palindromic.qbk] - -[section:is_palindromic is_palindromic] - -[/license -Copyright (c) 2016 Alexander Zaitsev - -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) -] - -The header file 'is_palindromic.hpp' contains four variants of a single algorithm, `is_palindromic`. The algorithm tests the sequence and returns true if the sequence is palindromic. - -The routine `is_palindromic` takes a sequence and, optionally, a predicate. It will return true if the predicate returns true for tested elements by algorithm in the sequence. - -The routine come in 4 forms; the first one takes two iterators to define the range. The second form takes two iterators to define the range and a predicate. -The third form takes a single range parameter, and uses Boost.Range to traverse it. And the fourth form takes a single range parameter ( uses Boost.Range to traverse it) and a predicate. - - -[heading interface] - -The function `is_palindromic` returns true if the predicate returns true any tested by algorithm items in the sequence. -There are four versions: -1) takes two iterators. -2) takes two iterators and a predicate. -3) takes a range. -4) takes a range and a predicate. - -`` -template - bool is_palindromic ( BidirectionalIterator begin, BidirectionalIterator end ); -template - bool is_palindromic ( BidirectionalIterator begin, BidirectionalIterator end, Predicate p ); -template - bool is_palindromic ( const Range &r ); -template - bool is_palindromic ( const Range &r, Predicate p ); -`` - - -[heading Examples] - -Given the containers: -const std::list empty, -const std::vector singleElement{'z'}, -int oddNonPalindromic[] = {3,2,2}, -const int evenPalindromic[] = {1,2,2,1}, then -`` - -is_palindromic(empty)) --> true //empty range -is_palindromic(singleElement)) --> true -is_palindromic(std::begin(oddNonPalindromic), std::end(oddNonPalindromic))) --> false -is_palindromic(std::begin(evenPalindromic), std::end(evenPalindromic))) --> true -is_palindromic(empty.begin(), empty.end(), functorComparator())) --> true //empty range -is_palindromic(std::begin(oddNonPalindromic), std::end(oddNonPalindromic), funcComparator)) --> false -is_palindromic(evenPalindromic, std::equal_to())) --> true -`` - -[heading Iterator Requirements] - -`is_palindromic` work on Bidirectional and RandomAccess iterators. - -[heading Complexity] - -All of the variants of `is_palindromic` run in ['O(N)] (linear) time; that is, they compare against each element in the list once. If any of the comparisons not succeed, the algorithm will terminate immediately, without examining the remaining members of the sequence. - -[heading Exception Safety] - -All of the variants of `is_palindromic` take their parameters by value or const reference, and do not depend upon any global state. Therefore, all the routines in this file provide the strong exception guarantee. - -[heading Notes] - -* `is_palindromic` returns true for empty ranges and for single element ranges. - -* If you use version of 'is_palindromic' without custom predicate, 'is_palindromic' uses default 'operator==' for elements. If you want use custom predicate, you must redefine 'operator=='. - -[endsect] - -[/ File is_palindromic.qbk -Copyright 2016 Alexander Zaitsev -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). -] diff --git a/libs/algorithm/example/Jamfile.v2 b/libs/algorithm/example/Jamfile.v2 index 079c972..957ef4a 100644 --- a/libs/algorithm/example/Jamfile.v2 +++ b/libs/algorithm/example/Jamfile.v2 @@ -25,4 +25,4 @@ exe ordered_example : ordered_example.cpp ; exe clamp_example : clamp_example.cpp ; exe all_example : all_example.cpp ; exe search_example : search_example.cpp ; -exe is_palindromic_example : is_palindromic_example.cpp; +exe is_palindrome_example : is_palindrome_example.cpp; diff --git a/libs/algorithm/example/is_palindrome_example.cpp b/libs/algorithm/example/is_palindrome_example.cpp new file mode 100644 index 0000000..e995a9e --- /dev/null +++ b/libs/algorithm/example/is_palindrome_example.cpp @@ -0,0 +1,94 @@ +/* + Copyright (c) Alexander Zaitsev , 2016 + + 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 +#include +#include +#include +#include + +#include + + +namespace ba = boost::algorithm; + +template +bool funcComparator(const T& v1, const T& v2) +{ + return v1 == v2; +} + +struct functorComparator +{ + template + bool operator()(const T& v1, const T& v2) const + { + return v1 == v2; + } +}; + + +int main ( int /*argc*/, char * /*argv*/ [] ) +{ + //You can this algorithm with iterators(minimum Bidirectional) + std::vector vec{1,2,1}; + if(ba::is_palindrome(vec.begin(), vec.end())) + std::cout << "This container is palindrome" << std::endl; + else + std::cout << "This container is not palindrome" << std::endl; + + + //Of course, you can use const iterators + if(ba::is_palindrome(vec.cbegin(), vec.cend())) + std::cout << "This container is palindrome" << std::endl; + else + std::cout << "This container is not palindrome" << std::endl; + + + //Example with bidirectional iterators + std::list list{1,2,1}; + if(ba::is_palindrome(list.begin(), list.end())) + std::cout << "This container is palindrome" << std::endl; + else + std::cout << "This container is not palindrome" << std::endl; + + + //You can use custom comparators like functions, functors, lambdas + auto lambdaComparator = [](int v1, int v2){ return v1 == v2; }; + auto objFunc = std::function(lambdaComparator); + + if(ba::is_palindrome(vec.begin(), vec.end(), lambdaComparator)) + std::cout << "This container is palindrome" << std::endl; + else + std::cout << "This container is not palindrome" << std::endl; + + if(ba::is_palindrome(vec.begin(), vec.end(), funcComparator)) + std::cout << "This container is palindrome" << std::endl; + else + std::cout << "This container is not palindrome" << std::endl; + + if(ba::is_palindrome(vec.begin(), vec.end(), functorComparator())) + std::cout << "This container is palindrome" << std::endl; + else + std::cout << "This container is not palindrome" << std::endl; + + if(ba::is_palindrome(vec.begin(), vec.end(), objFunc)) + std::cout << "This container is palindrome" << std::endl; + else + std::cout << "This container is not palindrome" << std::endl; + + + //You can use ranges + if(ba::is_palindrome(vec)) + std::cout << "This container is palindrome" << std::endl; + else + std::cout << "This container is not palindrome" << std::endl; + + return 0; +} diff --git a/libs/algorithm/example/is_palindromic_example.cpp b/libs/algorithm/example/is_palindromic_example.cpp deleted file mode 100644 index a00c444..0000000 --- a/libs/algorithm/example/is_palindromic_example.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - Copyright (c) Alexander Zaitsev , 2016 - - 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 -#include -#include -#include -#include - -#include - - -namespace ba = boost::algorithm; - -template -bool funcComparator(const T& v1, const T& v2) -{ - return v1 == v2; -} - -struct functorComparator -{ - template - bool operator()(const T& v1, const T& v2) const - { - return v1 == v2; - } -}; - - -int main ( int /*argc*/, char * /*argv*/ [] ) -{ - //You can this algorithm with iterators(minimum Bidirectional) - std::vector vec{1,2,1}; - if(ba::is_palindromic(vec.begin(), vec.end())) - std::cout << "This container is palindromic" << std::endl; - else - std::cout << "This container is not palindromic" << std::endl; - - - //Of course, you can use const iterators - if(ba::is_palindromic(vec.cbegin(), vec.cend())) - std::cout << "This container is palindromic" << std::endl; - else - std::cout << "This container is not palindromic" << std::endl; - - - //Example with bidirectional iterators - std::list list{1,2,1}; - if(ba::is_palindromic(list.begin(), list.end())) - std::cout << "This container is palindromic" << std::endl; - else - std::cout << "This container is not palindromic" << std::endl; - - - //You can use custom comparators like functions, functors, lambdas - auto lambdaComparator = [](int v1, int v2){ return v1 == v2; }; - auto objFunc = std::function(lambdaComparator); - - if(ba::is_palindromic(vec.begin(), vec.end(), lambdaComparator)) - std::cout << "This container is palindromic" << std::endl; - else - std::cout << "This container is not palindromic" << std::endl; - - if(ba::is_palindromic(vec.begin(), vec.end(), funcComparator)) - std::cout << "This container is palindromic" << std::endl; - else - std::cout << "This container is not palindromic" << std::endl; - - if(ba::is_palindromic(vec.begin(), vec.end(), functorComparator())) - std::cout << "This container is palindromic" << std::endl; - else - std::cout << "This container is not palindromic" << std::endl; - - if(ba::is_palindromic(vec.begin(), vec.end(), objFunc)) - std::cout << "This container is palindromic" << std::endl; - else - std::cout << "This container is not palindromic" << std::endl; - - - //You can use ranges - if(ba::is_palindromic(vec)) - std::cout << "This container is palindromic" << std::endl; - else - std::cout << "This container is not palindromic" << std::endl; - - return 0; -} diff --git a/libs/algorithm/test/Jamfile.v2 b/libs/algorithm/test/Jamfile.v2 index 84c5b5e..60a3718 100644 --- a/libs/algorithm/test/Jamfile.v2 +++ b/libs/algorithm/test/Jamfile.v2 @@ -64,4 +64,4 @@ run partition_copy_test1.cpp ; run find_if_not_test1.cpp ; -run is_palindromic_test.cpp ; +run is_palindrome_test.cpp ; diff --git a/libs/algorithm/test/is_palindromic_test.cpp b/libs/algorithm/test/is_palindrome_test.cpp similarity index 54% rename from libs/algorithm/test/is_palindromic_test.cpp rename to libs/algorithm/test/is_palindrome_test.cpp index e24fa69..673e95b 100644 --- a/libs/algorithm/test/is_palindromic_test.cpp +++ b/libs/algorithm/test/is_palindrome_test.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include namespace ba = boost::algorithm; @@ -35,32 +35,32 @@ struct functorComparator }; -static void test_is_palindromic() +static void test_is_palindrome() { const std::list empty; const std::vector singleElement{'z'}; - int oddNonPalindromic[] = {3,2,2}; - const int evenPalindromic[] = {1,2,2,1}; + int oddNonPalindrome[] = {3,2,2}; + const int evenPalindrome[] = {1,2,2,1}; // Test a default operator== - BOOST_CHECK ( ba::is_palindromic(empty)); - BOOST_CHECK ( ba::is_palindromic(singleElement)); - BOOST_CHECK (!ba::is_palindromic(std::begin(oddNonPalindromic), std::end(oddNonPalindromic))); - BOOST_CHECK ( ba::is_palindromic(std::begin(evenPalindromic), std::end(evenPalindromic))); + BOOST_CHECK ( ba::is_palindrome(empty)); + BOOST_CHECK ( ba::is_palindrome(singleElement)); + BOOST_CHECK (!ba::is_palindrome(std::begin(oddNonPalindrome), std::end(oddNonPalindrome))); + BOOST_CHECK ( ba::is_palindrome(std::begin(evenPalindrome), std::end(evenPalindrome))); //Test the custom comparators - BOOST_CHECK ( ba::is_palindromic(empty.begin(), empty.end(), functorComparator())); - BOOST_CHECK (!ba::is_palindromic(std::begin(oddNonPalindromic), std::end(oddNonPalindromic), funcComparator)); - BOOST_CHECK ( ba::is_palindromic(evenPalindromic, std::equal_to())); + BOOST_CHECK ( ba::is_palindrome(empty.begin(), empty.end(), functorComparator())); + BOOST_CHECK (!ba::is_palindrome(std::begin(oddNonPalindrome), std::end(oddNonPalindrome), funcComparator)); + BOOST_CHECK ( ba::is_palindrome(evenPalindrome, std::equal_to())); //Only C++14 or newer //auto lambdaComparator = [](const auto& v1, const auto& v2){ return v1 == v2; }; - //BOOST_CHECK ( ba::is_palindromic(singleElement, lambdaComparator)); + //BOOST_CHECK ( ba::is_palindrome(singleElement, lambdaComparator)); } int test_main( int, char * [] ) { - test_is_palindromic(); + test_is_palindrome(); return 0; }