diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-09-13 11:24:46 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-09-13 11:25:39 +0900 |
commit | 4fadd968fa12130524c8380f33fcfe25d4de79e5 (patch) | |
tree | fd26a490cd15388d42fc6652b3c5c13012e7f93e /boost/move/algo/unique.hpp | |
parent | b5c87084afaef42b2d058f68091be31988a6a874 (diff) | |
download | boost-upstream/1.65.0.tar.gz boost-upstream/1.65.0.tar.bz2 boost-upstream/1.65.0.zip |
Imported Upstream version 1.65.0upstream/1.65.0
Change-Id: Icf8400b375482cb11bcf77440a6934ba360d6ba4
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/move/algo/unique.hpp')
-rw-r--r-- | boost/move/algo/unique.hpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/boost/move/algo/unique.hpp b/boost/move/algo/unique.hpp new file mode 100644 index 0000000000..8022a654e2 --- /dev/null +++ b/boost/move/algo/unique.hpp @@ -0,0 +1,55 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2017-2017. +// 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/libs/move for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_MOVE_ALGO_UNIQUE_HPP +#define BOOST_MOVE_ALGO_UNIQUE_HPP + +#include <boost/move/detail/config_begin.hpp> +#include <boost/move/utility_core.hpp> + +namespace boost { +namespace movelib { + +//! <b>Requires</b>: The comparison function shall be an equivalence relation. The type of *first shall satisfy +//! the MoveAssignable requirements +//! +//! <b>Effects</b>: For a nonempty range, eliminates all but the first element from every consecutive group +//! of equivalent elements referred to by the iterator i in the range [first + 1, last) for which the +//! following conditions hold: pred(*(i - 1), *i) != false. +//! +//! <b>Returns</b>: The end of the resulting range. +//! +//! <b>Complexity</b>: For nonempty ranges, exactly (last - first) - 1 applications of the corresponding predicate. +template<class ForwardIterator, class BinaryPredicate> +ForwardIterator unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred) +{ + if (first != last) { + ForwardIterator next(first); + ++next; + for (; next != last; ++next, ++first) { + if (pred(*first, *next)) { //Find first equal element + while (++next != last) + if (!pred(*first, *next)) + *++first = ::boost::move(*next); + break; + } + } + ++first; + } + return first; +} + +} //namespace movelib { +} //namespace boost { + +#include <boost/move/detail/config_end.hpp> + +#endif //#define BOOST_MOVE_ALGO_UNIQUE_HPP |