mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
support STL container: set operation algorithms
This commit is contained in:
parent
ee8602f6a3
commit
271f348972
17 changed files with 1488 additions and 76 deletions
115
sprout/algorithm/find_difference.hpp
Normal file
115
sprout/algorithm/find_difference.hpp
Normal file
|
@ -0,0 +1,115 @@
|
|||
#ifndef SPROUT_ALGORITHM_FIND_DIFFERENCE_HPP
|
||||
#define SPROUT_ALGORITHM_FIND_DIFFERENCE_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/utility/pair.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
find_difference_impl_check(
|
||||
sprout::tuples::tuple<InputIterator1, InputIterator2, bool> const& current,
|
||||
InputIterator1 last1, InputIterator2 last2
|
||||
)
|
||||
{
|
||||
return sprout::tuples::get<2>(current)
|
||||
? sprout::pair<InputIterator1, InputIterator2>(
|
||||
sprout::tuples::get<0>(current),
|
||||
sprout::tuples::get<1>(current)
|
||||
)
|
||||
: sprout::pair<InputIterator1, InputIterator2>(last1, last2)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<InputIterator1, InputIterator2, bool>
|
||||
find_difference_impl_1(
|
||||
sprout::tuples::tuple<InputIterator1, InputIterator2, bool> const& current,
|
||||
InputIterator1 last1, InputIterator2 last2, Compare comp, typename std::iterator_traits<InputIterator1>::difference_type n
|
||||
)
|
||||
{
|
||||
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, bool> type;
|
||||
return sprout::tuples::get<2>(current) || sprout::tuples::get<0>(current) == last1 ? current
|
||||
: n == 1 ? sprout::tuples::get<1>(current) == last2
|
||||
? type(sprout::tuples::get<0>(current), sprout::tuples::get<1>(current), true)
|
||||
: comp(*sprout::tuples::get<0>(current), *sprout::tuples::get<1>(current))
|
||||
? type(sprout::tuples::get<0>(current), sprout::tuples::get<1>(current), true)
|
||||
: comp(*sprout::tuples::get<1>(current), *sprout::tuples::get<0>(current))
|
||||
? type(sprout::tuples::get<0>(current), sprout::next(sprout::tuples::get<1>(current)), false)
|
||||
: type(sprout::next(sprout::tuples::get<0>(current)), sprout::next(sprout::tuples::get<1>(current)), false)
|
||||
: sprout::detail::find_difference_impl_1(
|
||||
sprout::detail::find_difference_impl_1(
|
||||
current,
|
||||
last1, last2, comp, n / 2
|
||||
),
|
||||
last1, last2, comp, n - n / 2
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<InputIterator1, InputIterator2, bool>
|
||||
find_difference_impl(
|
||||
sprout::tuples::tuple<InputIterator1, InputIterator2, bool> const& current,
|
||||
InputIterator1 last1, InputIterator2 last2, Compare comp, typename std::iterator_traits<InputIterator1>::difference_type n
|
||||
)
|
||||
{
|
||||
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, bool> type;
|
||||
return sprout::tuples::get<2>(current) || sprout::tuples::get<0>(current) == last1 ? current
|
||||
: sprout::detail::find_difference_impl(
|
||||
sprout::detail::find_difference_impl_1(
|
||||
current,
|
||||
last1, last2, comp, n
|
||||
),
|
||||
last1, last2, comp, n * 2
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
find_difference(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Compare comp
|
||||
)
|
||||
{
|
||||
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, bool> type;
|
||||
return sprout::detail::find_difference_impl_check(
|
||||
sprout::detail::find_difference_impl(type(first1, first2, false), last1, last2, comp, 1),
|
||||
last1, last2
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// find_difference
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log N)
|
||||
//
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
find_difference(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Compare comp
|
||||
)
|
||||
{
|
||||
return sprout::detail::find_difference(first1, last1, first2, last2, comp);
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
find_difference(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2
|
||||
)
|
||||
{
|
||||
return sprout::find_difference(first1, last1, first2, last2, sprout::less<>());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIND_DIFFERENCE_HPP
|
113
sprout/algorithm/find_intersection.hpp
Normal file
113
sprout/algorithm/find_intersection.hpp
Normal file
|
@ -0,0 +1,113 @@
|
|||
#ifndef SPROUT_ALGORITHM_FIND_INTERSECTION_HPP
|
||||
#define SPROUT_ALGORITHM_FIND_INTERSECTION_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/utility/pair.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
find_intersection_impl_check(
|
||||
sprout::tuples::tuple<InputIterator1, InputIterator2, bool> const& current,
|
||||
InputIterator1 last1, InputIterator2 last2
|
||||
)
|
||||
{
|
||||
return sprout::tuples::get<2>(current)
|
||||
? sprout::pair<InputIterator1, InputIterator2>(
|
||||
sprout::tuples::get<0>(current),
|
||||
sprout::tuples::get<1>(current)
|
||||
)
|
||||
: sprout::pair<InputIterator1, InputIterator2>(last1, last2)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<InputIterator1, InputIterator2, bool>
|
||||
find_intersection_impl_1(
|
||||
sprout::tuples::tuple<InputIterator1, InputIterator2, bool> const& current,
|
||||
InputIterator1 last1, InputIterator2 last2, Compare comp, typename std::iterator_traits<InputIterator1>::difference_type n
|
||||
)
|
||||
{
|
||||
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, bool> type;
|
||||
return sprout::tuples::get<2>(current) || sprout::tuples::get<0>(current) == last1 || sprout::tuples::get<1>(current) == last2 ? current
|
||||
: n == 1 ? comp(*sprout::tuples::get<0>(current), *sprout::tuples::get<1>(current))
|
||||
? type(sprout::next(sprout::tuples::get<0>(current)), sprout::tuples::get<1>(current), false)
|
||||
: comp(*sprout::tuples::get<1>(current), *sprout::tuples::get<0>(current))
|
||||
? type(sprout::tuples::get<0>(current), sprout::next(sprout::tuples::get<1>(current)), false)
|
||||
: type(sprout::tuples::get<0>(current), sprout::tuples::get<1>(current), true)
|
||||
: sprout::detail::find_intersection_impl_1(
|
||||
sprout::detail::find_intersection_impl_1(
|
||||
current,
|
||||
last1, last2, comp, n / 2
|
||||
),
|
||||
last1, last2, comp, n - n / 2
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<InputIterator1, InputIterator2, bool>
|
||||
find_intersection_impl(
|
||||
sprout::tuples::tuple<InputIterator1, InputIterator2, bool> const& current,
|
||||
InputIterator1 last1, InputIterator2 last2, Compare comp, typename std::iterator_traits<InputIterator1>::difference_type n
|
||||
)
|
||||
{
|
||||
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, bool> type;
|
||||
return sprout::tuples::get<2>(current) || sprout::tuples::get<0>(current) == last1 || sprout::tuples::get<1>(current) == last2 ? current
|
||||
: sprout::detail::find_intersection_impl(
|
||||
sprout::detail::find_intersection_impl_1(
|
||||
current,
|
||||
last1, last2, comp, n
|
||||
),
|
||||
last1, last2, comp, n * 2
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
find_intersection(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Compare comp
|
||||
)
|
||||
{
|
||||
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, bool> type;
|
||||
return sprout::detail::find_intersection_impl_check(
|
||||
sprout::detail::find_intersection_impl(type(first1, first2, false), last1, last2, comp, 1),
|
||||
last1, last2
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// find_intersection
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log N)
|
||||
//
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
find_intersection(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Compare comp
|
||||
)
|
||||
{
|
||||
return sprout::detail::find_intersection(first1, last1, first2, last2, comp);
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
find_intersection(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2
|
||||
)
|
||||
{
|
||||
return sprout::find_intersection(first1, last1, first2, last2, sprout::less<>());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIND_INTERSECTION_HPP
|
103
sprout/algorithm/find_symmetric_difference.hpp
Normal file
103
sprout/algorithm/find_symmetric_difference.hpp
Normal file
|
@ -0,0 +1,103 @@
|
|||
#ifndef SPROUT_ALGORITHM_FIND_SYMMETRIC_DIFFERENCE_HPP
|
||||
#define SPROUT_ALGORITHM_FIND_SYMMETRIC_DIFFERENCE_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/utility/pair.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
find_symmetric_difference_impl_check(sprout::tuples::tuple<InputIterator1, InputIterator2, bool> const& current) {
|
||||
return sprout::pair<InputIterator1, InputIterator2>(
|
||||
sprout::tuples::get<0>(current),
|
||||
sprout::tuples::get<1>(current)
|
||||
);
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<InputIterator1, InputIterator2, bool>
|
||||
find_symmetric_difference_impl_1(
|
||||
sprout::tuples::tuple<InputIterator1, InputIterator2, bool> const& current,
|
||||
InputIterator1 last1, InputIterator2 last2, Compare comp, typename std::iterator_traits<InputIterator1>::difference_type n
|
||||
)
|
||||
{
|
||||
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, bool> type;
|
||||
return sprout::tuples::get<2>(current) || sprout::tuples::get<0>(current) == last1 || sprout::tuples::get<1>(current) == last2 ? current
|
||||
: n == 1 ? comp(*sprout::tuples::get<0>(current), *sprout::tuples::get<1>(current)) || comp(*sprout::tuples::get<1>(current), *sprout::tuples::get<0>(current))
|
||||
? type(sprout::tuples::get<0>(current), sprout::tuples::get<1>(current), true)
|
||||
: type(sprout::next(sprout::tuples::get<0>(current)), sprout::next(sprout::tuples::get<1>(current)), false)
|
||||
: sprout::detail::find_symmetric_difference_impl_1(
|
||||
sprout::detail::find_symmetric_difference_impl_1(
|
||||
current,
|
||||
last1, last2, comp, n / 2
|
||||
),
|
||||
last1, last2, comp, n - n / 2
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<InputIterator1, InputIterator2, bool>
|
||||
find_symmetric_difference_impl(
|
||||
sprout::tuples::tuple<InputIterator1, InputIterator2, bool> const& current,
|
||||
InputIterator1 last1, InputIterator2 last2, Compare comp, typename std::iterator_traits<InputIterator1>::difference_type n
|
||||
)
|
||||
{
|
||||
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, bool> type;
|
||||
return sprout::tuples::get<2>(current) || sprout::tuples::get<0>(current) == last1 ? current
|
||||
: sprout::detail::find_symmetric_difference_impl(
|
||||
sprout::detail::find_symmetric_difference_impl_1(
|
||||
current,
|
||||
last1, last2, comp, n
|
||||
),
|
||||
last1, last2, comp, n * 2
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
find_symmetric_difference(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Compare comp
|
||||
)
|
||||
{
|
||||
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, bool> type;
|
||||
return sprout::detail::find_symmetric_difference_impl_check(
|
||||
sprout::detail::find_symmetric_difference_impl(type(first1, first2, false), last1, last2, comp, 1)
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// find_symmetric_difference
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log N)
|
||||
//
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
find_symmetric_difference(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Compare comp
|
||||
)
|
||||
{
|
||||
return sprout::detail::find_symmetric_difference(first1, last1, first2, last2, comp);
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
find_symmetric_difference(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2
|
||||
)
|
||||
{
|
||||
return sprout::find_symmetric_difference(first1, last1, first2, last2, sprout::less<>());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_FIND_SYMMETRIC_DIFFERENCE_HPP
|
|
@ -6,6 +6,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/iterator/set_difference_iterator.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
|
@ -63,12 +64,7 @@ namespace sprout {
|
|||
sprout::next(first1), last1, first2, last2, result, comp,
|
||||
size, args..., *first1
|
||||
)
|
||||
: first2 != last2
|
||||
? sprout::fixed::detail::set_difference_impl(
|
||||
first1, last1, sprout::next(first2), last2, result, comp,
|
||||
size, args...
|
||||
)
|
||||
: sprout::detail::container_complate(result, args...)
|
||||
: sprout::detail::container_complate(result, args...)
|
||||
: sprout::detail::container_complate(result, args...)
|
||||
;
|
||||
}
|
||||
|
@ -91,6 +87,24 @@ namespace sprout {
|
|||
sprout::size(result)
|
||||
);
|
||||
}
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2, typename Result, typename Compare>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
!sprout::is_fixed_container<Result>::value,
|
||||
typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
>::type
|
||||
set_difference(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Result const& result, Compare comp
|
||||
)
|
||||
{
|
||||
return sprout::remake<Result>(
|
||||
result, sprout::size(result),
|
||||
sprout::make_set_difference_iterator(first1, last1, first2, last2, comp),
|
||||
sprout::make_set_difference_iterator(last1, last1, last2, last2, comp)
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// set_difference
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/iterator/set_intersection_iterator.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
|
@ -59,16 +60,8 @@ namespace sprout {
|
|||
sprout::next(first1), last1, sprout::next(first2), last2, result, comp,
|
||||
size, args..., *first1
|
||||
)
|
||||
: sprout::fixed::detail::set_intersection_impl(
|
||||
sprout::next(first1), last1, first2, last2, result, comp,
|
||||
size, args...
|
||||
)
|
||||
: first2 != last2
|
||||
? sprout::fixed::detail::set_intersection_impl(
|
||||
first1, last1, sprout::next(first2), last2, result, comp,
|
||||
size, args...
|
||||
)
|
||||
: sprout::detail::container_complate(result, args...)
|
||||
: sprout::detail::container_complate(result, args...)
|
||||
: sprout::detail::container_complate(result, args...)
|
||||
;
|
||||
}
|
||||
|
@ -91,6 +84,24 @@ namespace sprout {
|
|||
sprout::size(result)
|
||||
);
|
||||
}
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2, typename Result, typename Compare>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
!sprout::is_fixed_container<Result>::value,
|
||||
typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
>::type
|
||||
set_intersection(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Result const& result, Compare comp
|
||||
)
|
||||
{
|
||||
return sprout::remake<Result>(
|
||||
result, sprout::size(result),
|
||||
sprout::make_set_intersection_iterator(first1, last1, first2, last2, comp),
|
||||
sprout::make_set_intersection_iterator(last1, last1, last2, last2, comp)
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// set_intersection
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/iterator/set_symmetric_difference_iterator.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
|
@ -91,6 +92,24 @@ namespace sprout {
|
|||
sprout::size(result)
|
||||
);
|
||||
}
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2, typename Result, typename Compare>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
!sprout::is_fixed_container<Result>::value,
|
||||
typename sprout::fixed::result_of::algorithm<Result>::type
|
||||
>::type
|
||||
set_symmetric_difference(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Result const& result, Compare comp
|
||||
)
|
||||
{
|
||||
return sprout::remake<Result>(
|
||||
result, sprout::size(result),
|
||||
sprout::make_set_symmetric_difference_iterator(first1, last1, first2, last2, comp),
|
||||
sprout::make_set_symmetric_difference_iterator(last1, last1, last2, last2, comp)
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// set_symmetric_difference
|
||||
|
|
41
sprout/algorithm/next_difference.hpp
Normal file
41
sprout/algorithm/next_difference.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#ifndef SPROUT_ALGORITHM_NEXT_DIFFERENCE_HPP
|
||||
#define SPROUT_ALGORITHM_NEXT_DIFFERENCE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/utility/pair.hpp>
|
||||
#include <sprout/algorithm/find_difference.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// next_difference
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log(N1+N2))
|
||||
//
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
next_difference(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Compare comp
|
||||
)
|
||||
{
|
||||
typedef sprout::pair<InputIterator1, InputIterator2> type;
|
||||
return first1 == last1 ? type(last1, last2)
|
||||
: sprout::find_difference(sprout::next(first1), last1, first2, last2, comp)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
next_difference(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2
|
||||
)
|
||||
{
|
||||
return sprout::next_difference(first1, last1, first2, last2, sprout::less<>());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_NEXT_DIFFERENCE_HPP
|
41
sprout/algorithm/next_intersection.hpp
Normal file
41
sprout/algorithm/next_intersection.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#ifndef SPROUT_ALGORITHM_NEXT_INTERSECTION_HPP
|
||||
#define SPROUT_ALGORITHM_NEXT_INTERSECTION_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/utility/pair.hpp>
|
||||
#include <sprout/algorithm/find_intersection.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// next_intersection
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log(N1+N2))
|
||||
//
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
next_intersection(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Compare comp
|
||||
)
|
||||
{
|
||||
typedef sprout::pair<InputIterator1, InputIterator2> type;
|
||||
return first1 == last1 || first2 == last2 ? type(last1, last2)
|
||||
: sprout::find_intersection(sprout::next(first1), last1, sprout::next(first2), last2, comp)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
next_intersection(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2
|
||||
)
|
||||
{
|
||||
return sprout::next_intersection(first1, last1, first2, last2, sprout::less<>());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_NEXT_INTERSECTION_HPP
|
48
sprout/algorithm/next_symmetric_difference.hpp
Normal file
48
sprout/algorithm/next_symmetric_difference.hpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#ifndef SPROUT_ALGORITHM_NEXT_SYMMETRIC_DIFFERENCE_HPP
|
||||
#define SPROUT_ALGORITHM_NEXT_SYMMETRIC_DIFFERENCE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/utility/pair.hpp>
|
||||
#include <sprout/algorithm/find_symmetric_difference.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// next_symmetric_difference
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log(N1+N2))
|
||||
//
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
next_symmetric_difference(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Compare comp
|
||||
)
|
||||
{
|
||||
typedef sprout::pair<InputIterator1, InputIterator2> type;
|
||||
return first1 != last1
|
||||
? first2 != last2
|
||||
? comp(*first1, *first2)
|
||||
? sprout::find_symmetric_difference(sprout::next(first1), last1, first2, last2, comp)
|
||||
: sprout::find_symmetric_difference(first1, last1, sprout::next(first2), last2, comp)
|
||||
: type(sprout::next(first1), first2)
|
||||
: first2 != last2
|
||||
? type(first1, sprout::next(first2))
|
||||
: type(last1, last2)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
next_symmetric_difference(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2
|
||||
)
|
||||
{
|
||||
return sprout::next_symmetric_difference(first1, last1, first2, last2, sprout::less<>());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_NEXT_SYMMETRIC_DIFFERENCE_HPP
|
49
sprout/algorithm/next_union.hpp
Normal file
49
sprout/algorithm/next_union.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#ifndef SPROUT_ALGORITHM_NEXT_UNION_HPP
|
||||
#define SPROUT_ALGORITHM_NEXT_UNION_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/utility/pair.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// next_union
|
||||
//
|
||||
// recursion depth:
|
||||
// O(1)
|
||||
//
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
next_union(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Compare comp
|
||||
)
|
||||
{
|
||||
typedef sprout::pair<InputIterator1, InputIterator2> type;
|
||||
return first1 != last1
|
||||
? first2 != last2
|
||||
? comp(*first1, *first2)
|
||||
? type(sprout::next(first1), first2)
|
||||
: comp(*first2, *first1)
|
||||
? type(first1, sprout::next(first2))
|
||||
: type(sprout::next(first1), sprout::next(first2))
|
||||
: type(sprout::next(first1), first2)
|
||||
: first2 != last2
|
||||
? type(first1, sprout::next(first2))
|
||||
: type(last1, last2)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
next_union(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2
|
||||
)
|
||||
{
|
||||
return sprout::next_union(first1, last1, first2, last2, sprout::less<>());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_NEXT_UNION_HPP
|
|
@ -46,6 +46,13 @@
|
|||
#include <sprout/algorithm/is_decreasing.hpp>
|
||||
#include <sprout/algorithm/is_strictly_increasing.hpp>
|
||||
#include <sprout/algorithm/is_strictly_decreasing.hpp>
|
||||
#include <sprout/algorithm/find_intersection.hpp>
|
||||
#include <sprout/algorithm/find_difference.hpp>
|
||||
#include <sprout/algorithm/find_symmetric_difference.hpp>
|
||||
#include <sprout/algorithm/next_union.hpp>
|
||||
#include <sprout/algorithm/next_intersection.hpp>
|
||||
#include <sprout/algorithm/next_difference.hpp>
|
||||
#include <sprout/algorithm/next_symmetric_difference.hpp>
|
||||
#include <sprout/algorithm/clamp.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_NON_MODIFYIING_HPP
|
||||
|
|
202
sprout/algorithm/set_intersection_iterator.hpp
Normal file
202
sprout/algorithm/set_intersection_iterator.hpp
Normal file
|
@ -0,0 +1,202 @@
|
|||
#ifndef SPROUT_ITERATOR_SET_INTERSECTION_ITERATOR_HPP
|
||||
#define SPROUT_ITERATOR_SET_INTERSECTION_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/type_traits/common.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/pair.hpp>
|
||||
#include <sprout/algorithm/find_intersection.hpp>
|
||||
#include <sprout/algorithm/next_intersection.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// set_intersection_iterator
|
||||
//
|
||||
template<
|
||||
typename LIterator, typename RIterator,
|
||||
typename Compare = sprout::less<>
|
||||
>
|
||||
class set_intersection_iterator
|
||||
: public std::iterator<
|
||||
typename sprout::min_iterator_category<
|
||||
typename sprout::common_iterator_category<LIterator, RIterator>::type,
|
||||
std::forward_iterator_tag
|
||||
>::type,
|
||||
typename sprout::common_iterator_value_type<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_difference_type<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_pointer<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_reference<LIterator, RIterator>::type
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef LIterator iterator_type;
|
||||
typedef RIterator iterator2_type;
|
||||
typedef Compare compare_type;
|
||||
typedef typename sprout::min_iterator_category<
|
||||
typename sprout::common_iterator_category<LIterator, RIterator>::type,
|
||||
std::forward_iterator_tag
|
||||
>::type iterator_category;
|
||||
typedef typename sprout::common_iterator_value_type<LIterator, RIterator>::type value_type;
|
||||
typedef typename sprout::common_iterator_difference_type<LIterator, RIterator>::type difference_type;
|
||||
typedef typename sprout::common_iterator_pointer<LIterator, RIterator>::type pointer;
|
||||
typedef typename sprout::common_iterator_reference<LIterator, RIterator>::type reference;
|
||||
protected:
|
||||
typedef sprout::pair<iterator_type, iterator2_type> pair_type;
|
||||
protected:
|
||||
pair_type current;
|
||||
iterator_type lst1;
|
||||
iterator2_type lst2;
|
||||
Compare comp;
|
||||
private:
|
||||
SPROUT_CONSTEXPR set_intersection_iterator(set_intersection_iterator const& other, pair_type const& next)
|
||||
: current(next)
|
||||
, lst1(other.lst1), lst2(other.lst2)
|
||||
, comp(other.comp)
|
||||
{}
|
||||
public:
|
||||
set_intersection_iterator()
|
||||
: current(), lst1(), lst2(), comp()
|
||||
{}
|
||||
set_intersection_iterator(set_intersection_iterator const&) = default;
|
||||
SPROUT_CONSTEXPR set_intersection_iterator(
|
||||
iterator_type it1, iterator_type lst1,
|
||||
iterator2_type it2, iterator2_type lst2,
|
||||
Compare comp = Compare()
|
||||
)
|
||||
: current(sprout::find_intersection(it1, lst1, it2, lst2, comp))
|
||||
, lst1(lst1), lst2(lst2)
|
||||
, comp(comp)
|
||||
{}
|
||||
template<typename U, typename V, typename W>
|
||||
SPROUT_CONSTEXPR set_intersection_iterator(set_intersection_iterator<U, V, W> const& it)
|
||||
: current(it.base(), it.base2())
|
||||
, lst1(it.last1()), lst2(it.last2())
|
||||
, comp(it.compare())
|
||||
{}
|
||||
template<typename U, typename V, typename W>
|
||||
set_intersection_iterator& operator=(set_intersection_iterator<U, V, W> const& it) {
|
||||
set_intersection_iterator temp(it);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type base() const {
|
||||
return current.first;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type last1() const {
|
||||
return lst1;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator2_type base2() const {
|
||||
return current.second;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator2_type last2() const {
|
||||
return lst2;
|
||||
}
|
||||
SPROUT_CONSTEXPR Compare compare() const {
|
||||
return comp;
|
||||
}
|
||||
SPROUT_CONSTEXPR bool is_in_left() const {
|
||||
return true;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return *current.first;
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
return &*(*this);
|
||||
}
|
||||
set_intersection_iterator& operator++() {
|
||||
current = sprout::next_intersection(current.first, lst1, current.second, lst2, comp);
|
||||
return *this;
|
||||
}
|
||||
set_intersection_iterator operator++(int) {
|
||||
set_intersection_iterator result(*this);
|
||||
current = sprout::next_intersection(current.first, lst1, current.second, lst2, comp);
|
||||
return result;
|
||||
}
|
||||
SPROUT_CONSTEXPR set_intersection_iterator next() const {
|
||||
return set_intersection_iterator(
|
||||
*this,
|
||||
sprout::next_intersection(current.first, lst1, current.second, lst2, comp)
|
||||
);
|
||||
}
|
||||
void swap(set_intersection_iterator& other)
|
||||
SPROUT_NOEXCEPT_EXPR(
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::swap(current, other.current))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(lst1, other.lst1))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(lst2, other.lst2))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(comp, other.comp))
|
||||
)
|
||||
{
|
||||
sprout::swap(current, other.current);
|
||||
sprout::swap(lst1, other.lst1);
|
||||
sprout::swap(lst2, other.lst2);
|
||||
sprout::swap(comp, other.comp);
|
||||
}
|
||||
};
|
||||
|
||||
template<
|
||||
typename LIterator1, typename RIterator1, typename Compare1,
|
||||
typename LIterator2, typename RIterator2, typename Compare2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator==(
|
||||
sprout::set_intersection_iterator<LIterator1, RIterator1, Compare1> const& lhs,
|
||||
sprout::set_intersection_iterator<LIterator2, RIterator2, Compare2> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.base() == rhs.base() && lhs.base2() == rhs.base2();
|
||||
}
|
||||
template<
|
||||
typename LIterator1, typename RIterator1, typename Compare1,
|
||||
typename LIterator2, typename RIterator2, typename Compare2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator!=(
|
||||
sprout::set_intersection_iterator<LIterator1, RIterator1, Compare1> const& lhs,
|
||||
sprout::set_intersection_iterator<LIterator2, RIterator2, Compare2> const& rhs
|
||||
)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// make_set_intersection_iterator
|
||||
//
|
||||
template<typename LIterator, typename RIterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::set_intersection_iterator<LIterator, RIterator, Compare>
|
||||
make_set_intersection_iterator(LIterator it1, LIterator lst1, RIterator it2, RIterator lst2, Compare comp) {
|
||||
return sprout::set_intersection_iterator<LIterator, RIterator, Compare>(it1, lst1, it2, lst2, comp);
|
||||
}
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::set_intersection_iterator<LIterator, RIterator>
|
||||
make_set_intersection_iterator(LIterator it1, LIterator lst1, RIterator it2, RIterator lst2) {
|
||||
return sprout::set_intersection_iterator<LIterator, RIterator>(it1, lst1, it2, lst2);
|
||||
}
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename LIterator, typename RIterator, typename Compare>
|
||||
inline void
|
||||
swap(
|
||||
sprout::set_intersection_iterator<LIterator, RIterator, Compare>& lhs,
|
||||
sprout::set_intersection_iterator<LIterator, RIterator, Compare>& rhs
|
||||
)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_next
|
||||
//
|
||||
template<typename LIterator, typename RIterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::set_intersection_iterator<LIterator, RIterator, Compare>
|
||||
iterator_next(sprout::set_intersection_iterator<LIterator, RIterator, Compare> const& it) {
|
||||
return it.next();
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_SET_INTERSECTION_ITERATOR_HPP
|
|
@ -16,6 +16,10 @@
|
|||
#include <sprout/iterator/joint_iterator.hpp>
|
||||
#include <sprout/iterator/alternate_iterator.hpp>
|
||||
#include <sprout/iterator/merge_iterator.hpp>
|
||||
#include <sprout/iterator/set_union_iterator.hpp>
|
||||
#include <sprout/iterator/set_intersection_iterator.hpp>
|
||||
#include <sprout/iterator/set_difference_iterator.hpp>
|
||||
#include <sprout/iterator/set_symmetric_difference_iterator.hpp>
|
||||
#include <sprout/iterator/size_enum_iterator.hpp>
|
||||
#include <sprout/iterator/bytes_iterator.hpp>
|
||||
#include <sprout/iterator/remake_iterator.hpp>
|
||||
|
|
202
sprout/iterator/set_difference_iterator.hpp
Normal file
202
sprout/iterator/set_difference_iterator.hpp
Normal file
|
@ -0,0 +1,202 @@
|
|||
#ifndef SPROUT_ITERATOR_SET_DIFFERENCE_ITERATOR_HPP
|
||||
#define SPROUT_ITERATOR_SET_DIFFERENCE_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/type_traits/common.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/pair.hpp>
|
||||
#include <sprout/algorithm/find_difference.hpp>
|
||||
#include <sprout/algorithm/next_difference.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// set_difference_iterator
|
||||
//
|
||||
template<
|
||||
typename LIterator, typename RIterator,
|
||||
typename Compare = sprout::less<>
|
||||
>
|
||||
class set_difference_iterator
|
||||
: public std::iterator<
|
||||
typename sprout::min_iterator_category<
|
||||
typename sprout::common_iterator_category<LIterator, RIterator>::type,
|
||||
std::forward_iterator_tag
|
||||
>::type,
|
||||
typename sprout::common_iterator_value_type<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_difference_type<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_pointer<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_reference<LIterator, RIterator>::type
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef LIterator iterator_type;
|
||||
typedef RIterator iterator2_type;
|
||||
typedef Compare compare_type;
|
||||
typedef typename sprout::min_iterator_category<
|
||||
typename sprout::common_iterator_category<LIterator, RIterator>::type,
|
||||
std::forward_iterator_tag
|
||||
>::type iterator_category;
|
||||
typedef typename sprout::common_iterator_value_type<LIterator, RIterator>::type value_type;
|
||||
typedef typename sprout::common_iterator_difference_type<LIterator, RIterator>::type difference_type;
|
||||
typedef typename sprout::common_iterator_pointer<LIterator, RIterator>::type pointer;
|
||||
typedef typename sprout::common_iterator_reference<LIterator, RIterator>::type reference;
|
||||
protected:
|
||||
typedef sprout::pair<iterator_type, iterator2_type> pair_type;
|
||||
protected:
|
||||
pair_type current;
|
||||
iterator_type lst1;
|
||||
iterator2_type lst2;
|
||||
Compare comp;
|
||||
private:
|
||||
SPROUT_CONSTEXPR set_difference_iterator(set_difference_iterator const& other, pair_type const& next)
|
||||
: current(next)
|
||||
, lst1(other.lst1), lst2(other.lst2)
|
||||
, comp(other.comp)
|
||||
{}
|
||||
public:
|
||||
set_difference_iterator()
|
||||
: current(), lst1(), lst2(), comp()
|
||||
{}
|
||||
set_difference_iterator(set_difference_iterator const&) = default;
|
||||
SPROUT_CONSTEXPR set_difference_iterator(
|
||||
iterator_type it1, iterator_type lst1,
|
||||
iterator2_type it2, iterator2_type lst2,
|
||||
Compare comp = Compare()
|
||||
)
|
||||
: current(sprout::find_difference(it1, lst1, it2, lst2, comp))
|
||||
, lst1(lst1), lst2(lst2)
|
||||
, comp(comp)
|
||||
{}
|
||||
template<typename U, typename V, typename W>
|
||||
SPROUT_CONSTEXPR set_difference_iterator(set_difference_iterator<U, V, W> const& it)
|
||||
: current(it.base(), it.base2())
|
||||
, lst1(it.last1()), lst2(it.last2())
|
||||
, comp(it.compare())
|
||||
{}
|
||||
template<typename U, typename V, typename W>
|
||||
set_difference_iterator& operator=(set_difference_iterator<U, V, W> const& it) {
|
||||
set_difference_iterator temp(it);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type base() const {
|
||||
return current.first;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type last1() const {
|
||||
return lst1;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator2_type base2() const {
|
||||
return current.second;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator2_type last2() const {
|
||||
return lst2;
|
||||
}
|
||||
SPROUT_CONSTEXPR Compare compare() const {
|
||||
return comp;
|
||||
}
|
||||
SPROUT_CONSTEXPR bool is_in_left() const {
|
||||
return true;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return *current.first;
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
return &*(*this);
|
||||
}
|
||||
set_difference_iterator& operator++() {
|
||||
current = sprout::next_difference(current.first, lst1, current.second, lst2, comp);
|
||||
return *this;
|
||||
}
|
||||
set_difference_iterator operator++(int) {
|
||||
set_difference_iterator result(*this);
|
||||
current = sprout::next_difference(current.first, lst1, current.second, lst2, comp);
|
||||
return result;
|
||||
}
|
||||
SPROUT_CONSTEXPR set_difference_iterator next() const {
|
||||
return set_difference_iterator(
|
||||
*this,
|
||||
sprout::next_difference(current.first, lst1, current.second, lst2, comp)
|
||||
);
|
||||
}
|
||||
void swap(set_difference_iterator& other)
|
||||
SPROUT_NOEXCEPT_EXPR(
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::swap(current, other.current))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(lst1, other.lst1))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(lst2, other.lst2))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(comp, other.comp))
|
||||
)
|
||||
{
|
||||
sprout::swap(current, other.current);
|
||||
sprout::swap(lst1, other.lst1);
|
||||
sprout::swap(lst2, other.lst2);
|
||||
sprout::swap(comp, other.comp);
|
||||
}
|
||||
};
|
||||
|
||||
template<
|
||||
typename LIterator1, typename RIterator1, typename Compare1,
|
||||
typename LIterator2, typename RIterator2, typename Compare2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator==(
|
||||
sprout::set_difference_iterator<LIterator1, RIterator1, Compare1> const& lhs,
|
||||
sprout::set_difference_iterator<LIterator2, RIterator2, Compare2> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.base() == rhs.base() && lhs.base2() == rhs.base2();
|
||||
}
|
||||
template<
|
||||
typename LIterator1, typename RIterator1, typename Compare1,
|
||||
typename LIterator2, typename RIterator2, typename Compare2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator!=(
|
||||
sprout::set_difference_iterator<LIterator1, RIterator1, Compare1> const& lhs,
|
||||
sprout::set_difference_iterator<LIterator2, RIterator2, Compare2> const& rhs
|
||||
)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// make_set_difference_iterator
|
||||
//
|
||||
template<typename LIterator, typename RIterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::set_difference_iterator<LIterator, RIterator, Compare>
|
||||
make_set_difference_iterator(LIterator it1, LIterator lst1, RIterator it2, RIterator lst2, Compare comp) {
|
||||
return sprout::set_difference_iterator<LIterator, RIterator, Compare>(it1, lst1, it2, lst2, comp);
|
||||
}
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::set_difference_iterator<LIterator, RIterator>
|
||||
make_set_difference_iterator(LIterator it1, LIterator lst1, RIterator it2, RIterator lst2) {
|
||||
return sprout::set_difference_iterator<LIterator, RIterator>(it1, lst1, it2, lst2);
|
||||
}
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename LIterator, typename RIterator, typename Compare>
|
||||
inline void
|
||||
swap(
|
||||
sprout::set_difference_iterator<LIterator, RIterator, Compare>& lhs,
|
||||
sprout::set_difference_iterator<LIterator, RIterator, Compare>& rhs
|
||||
)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_next
|
||||
//
|
||||
template<typename LIterator, typename RIterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::set_difference_iterator<LIterator, RIterator, Compare>
|
||||
iterator_next(sprout::set_difference_iterator<LIterator, RIterator, Compare> const& it) {
|
||||
return it.next();
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_SET_DIFFERENCE_ITERATOR_HPP
|
202
sprout/iterator/set_intersection_iterator.hpp
Normal file
202
sprout/iterator/set_intersection_iterator.hpp
Normal file
|
@ -0,0 +1,202 @@
|
|||
#ifndef SPROUT_ITERATOR_SET_INTERSECTION_ITERATOR_HPP
|
||||
#define SPROUT_ITERATOR_SET_INTERSECTION_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/type_traits/common.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/pair.hpp>
|
||||
#include <sprout/algorithm/find_intersection.hpp>
|
||||
#include <sprout/algorithm/next_intersection.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// set_intersection_iterator
|
||||
//
|
||||
template<
|
||||
typename LIterator, typename RIterator,
|
||||
typename Compare = sprout::less<>
|
||||
>
|
||||
class set_intersection_iterator
|
||||
: public std::iterator<
|
||||
typename sprout::min_iterator_category<
|
||||
typename sprout::common_iterator_category<LIterator, RIterator>::type,
|
||||
std::forward_iterator_tag
|
||||
>::type,
|
||||
typename sprout::common_iterator_value_type<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_difference_type<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_pointer<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_reference<LIterator, RIterator>::type
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef LIterator iterator_type;
|
||||
typedef RIterator iterator2_type;
|
||||
typedef Compare compare_type;
|
||||
typedef typename sprout::min_iterator_category<
|
||||
typename sprout::common_iterator_category<LIterator, RIterator>::type,
|
||||
std::forward_iterator_tag
|
||||
>::type iterator_category;
|
||||
typedef typename sprout::common_iterator_value_type<LIterator, RIterator>::type value_type;
|
||||
typedef typename sprout::common_iterator_difference_type<LIterator, RIterator>::type difference_type;
|
||||
typedef typename sprout::common_iterator_pointer<LIterator, RIterator>::type pointer;
|
||||
typedef typename sprout::common_iterator_reference<LIterator, RIterator>::type reference;
|
||||
protected:
|
||||
typedef sprout::pair<iterator_type, iterator2_type> pair_type;
|
||||
protected:
|
||||
pair_type current;
|
||||
iterator_type lst1;
|
||||
iterator2_type lst2;
|
||||
Compare comp;
|
||||
private:
|
||||
SPROUT_CONSTEXPR set_intersection_iterator(set_intersection_iterator const& other, pair_type const& next)
|
||||
: current(next)
|
||||
, lst1(other.lst1), lst2(other.lst2)
|
||||
, comp(other.comp)
|
||||
{}
|
||||
public:
|
||||
set_intersection_iterator()
|
||||
: current(), lst1(), lst2(), comp()
|
||||
{}
|
||||
set_intersection_iterator(set_intersection_iterator const&) = default;
|
||||
SPROUT_CONSTEXPR set_intersection_iterator(
|
||||
iterator_type it1, iterator_type lst1,
|
||||
iterator2_type it2, iterator2_type lst2,
|
||||
Compare comp = Compare()
|
||||
)
|
||||
: current(sprout::find_intersection(it1, lst1, it2, lst2, comp))
|
||||
, lst1(lst1), lst2(lst2)
|
||||
, comp(comp)
|
||||
{}
|
||||
template<typename U, typename V, typename W>
|
||||
SPROUT_CONSTEXPR set_intersection_iterator(set_intersection_iterator<U, V, W> const& it)
|
||||
: current(it.base(), it.base2())
|
||||
, lst1(it.last1()), lst2(it.last2())
|
||||
, comp(it.compare())
|
||||
{}
|
||||
template<typename U, typename V, typename W>
|
||||
set_intersection_iterator& operator=(set_intersection_iterator<U, V, W> const& it) {
|
||||
set_intersection_iterator temp(it);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type base() const {
|
||||
return current.first;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type last1() const {
|
||||
return lst1;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator2_type base2() const {
|
||||
return current.second;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator2_type last2() const {
|
||||
return lst2;
|
||||
}
|
||||
SPROUT_CONSTEXPR Compare compare() const {
|
||||
return comp;
|
||||
}
|
||||
SPROUT_CONSTEXPR bool is_in_left() const {
|
||||
return true;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return *current.first;
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
return &*(*this);
|
||||
}
|
||||
set_intersection_iterator& operator++() {
|
||||
current = sprout::next_intersection(current.first, lst1, current.second, lst2, comp);
|
||||
return *this;
|
||||
}
|
||||
set_intersection_iterator operator++(int) {
|
||||
set_intersection_iterator result(*this);
|
||||
current = sprout::next_intersection(current.first, lst1, current.second, lst2, comp);
|
||||
return result;
|
||||
}
|
||||
SPROUT_CONSTEXPR set_intersection_iterator next() const {
|
||||
return set_intersection_iterator(
|
||||
*this,
|
||||
sprout::next_intersection(current.first, lst1, current.second, lst2, comp)
|
||||
);
|
||||
}
|
||||
void swap(set_intersection_iterator& other)
|
||||
SPROUT_NOEXCEPT_EXPR(
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::swap(current, other.current))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(lst1, other.lst1))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(lst2, other.lst2))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(comp, other.comp))
|
||||
)
|
||||
{
|
||||
sprout::swap(current, other.current);
|
||||
sprout::swap(lst1, other.lst1);
|
||||
sprout::swap(lst2, other.lst2);
|
||||
sprout::swap(comp, other.comp);
|
||||
}
|
||||
};
|
||||
|
||||
template<
|
||||
typename LIterator1, typename RIterator1, typename Compare1,
|
||||
typename LIterator2, typename RIterator2, typename Compare2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator==(
|
||||
sprout::set_intersection_iterator<LIterator1, RIterator1, Compare1> const& lhs,
|
||||
sprout::set_intersection_iterator<LIterator2, RIterator2, Compare2> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.base() == rhs.base() && lhs.base2() == rhs.base2();
|
||||
}
|
||||
template<
|
||||
typename LIterator1, typename RIterator1, typename Compare1,
|
||||
typename LIterator2, typename RIterator2, typename Compare2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator!=(
|
||||
sprout::set_intersection_iterator<LIterator1, RIterator1, Compare1> const& lhs,
|
||||
sprout::set_intersection_iterator<LIterator2, RIterator2, Compare2> const& rhs
|
||||
)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// make_set_intersection_iterator
|
||||
//
|
||||
template<typename LIterator, typename RIterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::set_intersection_iterator<LIterator, RIterator, Compare>
|
||||
make_set_intersection_iterator(LIterator it1, LIterator lst1, RIterator it2, RIterator lst2, Compare comp) {
|
||||
return sprout::set_intersection_iterator<LIterator, RIterator, Compare>(it1, lst1, it2, lst2, comp);
|
||||
}
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::set_intersection_iterator<LIterator, RIterator>
|
||||
make_set_intersection_iterator(LIterator it1, LIterator lst1, RIterator it2, RIterator lst2) {
|
||||
return sprout::set_intersection_iterator<LIterator, RIterator>(it1, lst1, it2, lst2);
|
||||
}
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename LIterator, typename RIterator, typename Compare>
|
||||
inline void
|
||||
swap(
|
||||
sprout::set_intersection_iterator<LIterator, RIterator, Compare>& lhs,
|
||||
sprout::set_intersection_iterator<LIterator, RIterator, Compare>& rhs
|
||||
)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_next
|
||||
//
|
||||
template<typename LIterator, typename RIterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::set_intersection_iterator<LIterator, RIterator, Compare>
|
||||
iterator_next(sprout::set_intersection_iterator<LIterator, RIterator, Compare> const& it) {
|
||||
return it.next();
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_SET_INTERSECTION_ITERATOR_HPP
|
270
sprout/iterator/set_symmetric_difference_iterator.hpp
Normal file
270
sprout/iterator/set_symmetric_difference_iterator.hpp
Normal file
|
@ -0,0 +1,270 @@
|
|||
#ifndef SPROUT_ITERATOR_SET_SYMMETRIC_DIFFERENCE_ITERATOR_HPP
|
||||
#define SPROUT_ITERATOR_SET_SYMMETRIC_DIFFERENCE_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/type_traits/common.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/pair.hpp>
|
||||
#include <sprout/algorithm/find_symmetric_difference.hpp>
|
||||
#include <sprout/algorithm/next_symmetric_difference.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<
|
||||
typename LIterator, typename RIterator,
|
||||
typename Compare
|
||||
>
|
||||
class set_symmetric_difference_iterator_impl {
|
||||
protected:
|
||||
typedef LIterator iterator_type;
|
||||
typedef RIterator iterator2_type;
|
||||
typedef Compare compare_type;
|
||||
typedef typename sprout::min_iterator_category<
|
||||
typename sprout::common_iterator_category<LIterator, RIterator>::type,
|
||||
std::forward_iterator_tag
|
||||
>::type iterator_category;
|
||||
typedef typename sprout::common_iterator_value_type<LIterator, RIterator>::type value_type;
|
||||
typedef typename sprout::common_iterator_difference_type<LIterator, RIterator>::type difference_type;
|
||||
typedef typename sprout::common_iterator_pointer<LIterator, RIterator>::type pointer;
|
||||
typedef typename sprout::common_iterator_reference<LIterator, RIterator>::type reference;
|
||||
protected:
|
||||
typedef sprout::pair<iterator_type, iterator2_type> pair_type;
|
||||
protected:
|
||||
static SPROUT_CONSTEXPR bool check_in_left(
|
||||
iterator_type it1, iterator_type lst1,
|
||||
iterator2_type it2, iterator2_type lst2,
|
||||
Compare comp
|
||||
)
|
||||
{
|
||||
return it1 != lst1 ? (it2 != lst2 ? comp(*it1, *it2) : true)
|
||||
: !(it2 != lst2)
|
||||
;
|
||||
}
|
||||
protected:
|
||||
pair_type current;
|
||||
iterator_type lst1;
|
||||
iterator2_type lst2;
|
||||
Compare comp;
|
||||
protected:
|
||||
bool in_left;
|
||||
protected:
|
||||
set_symmetric_difference_iterator_impl()
|
||||
: current(), lst1(), lst2(), comp(), in_left(true)
|
||||
{}
|
||||
set_symmetric_difference_iterator_impl(set_symmetric_difference_iterator_impl const&) = default;
|
||||
SPROUT_CONSTEXPR set_symmetric_difference_iterator_impl(
|
||||
pair_type const& current,
|
||||
iterator_type lst1, iterator2_type lst2,
|
||||
Compare comp
|
||||
)
|
||||
: current(current)
|
||||
, lst1(lst1), lst2(lst2)
|
||||
, comp(comp)
|
||||
, in_left(check_in_left(current.first, lst1, current.second, lst2, comp))
|
||||
{}
|
||||
SPROUT_CONSTEXPR set_symmetric_difference_iterator_impl(
|
||||
pair_type const& current,
|
||||
iterator_type lst1, iterator2_type lst2,
|
||||
Compare comp,
|
||||
bool in_left
|
||||
)
|
||||
: current(current)
|
||||
, lst1(lst1), lst2(lst2)
|
||||
, comp(comp)
|
||||
, in_left(in_left)
|
||||
{}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// set_symmetric_difference_iterator
|
||||
//
|
||||
template<
|
||||
typename LIterator, typename RIterator,
|
||||
typename Compare = sprout::less<>
|
||||
>
|
||||
class set_symmetric_difference_iterator
|
||||
: public std::iterator<
|
||||
typename sprout::min_iterator_category<
|
||||
typename sprout::common_iterator_category<LIterator, RIterator>::type,
|
||||
std::forward_iterator_tag
|
||||
>::type,
|
||||
typename sprout::common_iterator_value_type<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_difference_type<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_pointer<LIterator, RIterator>::type,
|
||||
typename sprout::common_iterator_reference<LIterator, RIterator>::type
|
||||
>
|
||||
, private sprout::detail::set_symmetric_difference_iterator_impl<LIterator, RIterator, Compare>
|
||||
{
|
||||
private:
|
||||
typedef sprout::detail::set_symmetric_difference_iterator_impl<LIterator, RIterator, Compare> impl_type;
|
||||
public:
|
||||
typedef typename impl_type::iterator_type iterator_type;
|
||||
typedef typename impl_type::iterator2_type iterator2_type;
|
||||
typedef typename impl_type::compare_type compare_type;
|
||||
typedef typename impl_type::iterator_category iterator_category;
|
||||
typedef typename impl_type::value_type value_type;
|
||||
typedef typename impl_type::difference_type difference_type;
|
||||
typedef typename impl_type::pointer pointer;
|
||||
typedef typename impl_type::reference reference;
|
||||
protected:
|
||||
typedef typename impl_type::pair_type pair_type;
|
||||
private:
|
||||
using impl_type::check_in_left;
|
||||
protected:
|
||||
using impl_type::current;
|
||||
using impl_type::lst1;
|
||||
using impl_type::lst2;
|
||||
using impl_type::comp;
|
||||
private:
|
||||
using impl_type::in_left;
|
||||
private:
|
||||
SPROUT_CONSTEXPR set_symmetric_difference_iterator(set_symmetric_difference_iterator const& other, pair_type const& next)
|
||||
: impl_type(next, other.lst1, other.lst2, other.comp)
|
||||
{}
|
||||
public:
|
||||
set_symmetric_difference_iterator()
|
||||
: impl_type()
|
||||
{}
|
||||
set_symmetric_difference_iterator(set_symmetric_difference_iterator const&) = default;
|
||||
SPROUT_CONSTEXPR set_symmetric_difference_iterator(
|
||||
iterator_type it1, iterator_type lst1,
|
||||
iterator2_type it2, iterator2_type lst2,
|
||||
Compare comp = Compare()
|
||||
)
|
||||
: impl_type(sprout::find_symmetric_difference(it1, lst1, it2, lst2, comp), lst1, lst2, comp)
|
||||
{}
|
||||
template<typename U, typename V, typename W>
|
||||
SPROUT_CONSTEXPR set_symmetric_difference_iterator(set_symmetric_difference_iterator<U, V, W> const& it)
|
||||
: impl_type(pair_type(it.base(), it.base2()), it.last1(), it.last2(), it.compare(), it.is_in_left())
|
||||
{}
|
||||
template<typename U, typename V, typename W>
|
||||
set_symmetric_difference_iterator& operator=(set_symmetric_difference_iterator<U, V, W> const& it) {
|
||||
set_symmetric_difference_iterator temp(it);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type base() const {
|
||||
return current.first;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type last1() const {
|
||||
return lst1;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator2_type base2() const {
|
||||
return current.second;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator2_type last2() const {
|
||||
return lst2;
|
||||
}
|
||||
SPROUT_CONSTEXPR Compare compare() const {
|
||||
return comp;
|
||||
}
|
||||
SPROUT_CONSTEXPR bool is_in_left() const {
|
||||
return in_left;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return is_in_left() ? *current.first : *current.second;
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
return &*(*this);
|
||||
}
|
||||
set_symmetric_difference_iterator& operator++() {
|
||||
current = sprout::next_symmetric_difference(current.first, lst1, current.second, lst2, comp);
|
||||
in_left = check_in_left(current.first, lst1, current.second, lst2, comp);
|
||||
return *this;
|
||||
}
|
||||
set_symmetric_difference_iterator operator++(int) {
|
||||
set_symmetric_difference_iterator result(*this);
|
||||
current = sprout::next_symmetric_difference(current.first, lst1, current.second, lst2, comp);
|
||||
in_left = check_in_left(current.first, lst1, current.second, lst2, comp);
|
||||
return result;
|
||||
}
|
||||
SPROUT_CONSTEXPR set_symmetric_difference_iterator next() const {
|
||||
return set_symmetric_difference_iterator(
|
||||
*this,
|
||||
sprout::next_symmetric_difference(current.first, lst1, current.second, lst2, comp)
|
||||
);
|
||||
}
|
||||
void swap(set_symmetric_difference_iterator& other)
|
||||
SPROUT_NOEXCEPT_EXPR(
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::swap(current, other.current))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(lst1, other.lst1))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(lst2, other.lst2))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(comp, other.comp))
|
||||
)
|
||||
{
|
||||
sprout::swap(current, other.current);
|
||||
sprout::swap(lst1, other.lst1);
|
||||
sprout::swap(lst2, other.lst2);
|
||||
sprout::swap(comp, other.comp);
|
||||
sprout::swap(in_left, other.in_left);
|
||||
}
|
||||
};
|
||||
|
||||
template<
|
||||
typename LIterator1, typename RIterator1, typename Compare1,
|
||||
typename LIterator2, typename RIterator2, typename Compare2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator==(
|
||||
sprout::set_symmetric_difference_iterator<LIterator1, RIterator1, Compare1> const& lhs,
|
||||
sprout::set_symmetric_difference_iterator<LIterator2, RIterator2, Compare2> const& rhs
|
||||
)
|
||||
{
|
||||
return lhs.base() == rhs.base() && lhs.base2() == rhs.base2();
|
||||
}
|
||||
template<
|
||||
typename LIterator1, typename RIterator1, typename Compare1,
|
||||
typename LIterator2, typename RIterator2, typename Compare2
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool operator!=(
|
||||
sprout::set_symmetric_difference_iterator<LIterator1, RIterator1, Compare1> const& lhs,
|
||||
sprout::set_symmetric_difference_iterator<LIterator2, RIterator2, Compare2> const& rhs
|
||||
)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// make_set_symmetric_difference_iterator
|
||||
//
|
||||
template<typename LIterator, typename RIterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::set_symmetric_difference_iterator<LIterator, RIterator, Compare>
|
||||
make_set_symmetric_difference_iterator(LIterator it1, LIterator lst1, RIterator it2, RIterator lst2, Compare comp) {
|
||||
return sprout::set_symmetric_difference_iterator<LIterator, RIterator, Compare>(it1, lst1, it2, lst2, comp);
|
||||
}
|
||||
template<typename LIterator, typename RIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::set_symmetric_difference_iterator<LIterator, RIterator>
|
||||
make_set_symmetric_difference_iterator(LIterator it1, LIterator lst1, RIterator it2, RIterator lst2) {
|
||||
return sprout::set_symmetric_difference_iterator<LIterator, RIterator>(it1, lst1, it2, lst2);
|
||||
}
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename LIterator, typename RIterator, typename Compare>
|
||||
inline void
|
||||
swap(
|
||||
sprout::set_symmetric_difference_iterator<LIterator, RIterator, Compare>& lhs,
|
||||
sprout::set_symmetric_difference_iterator<LIterator, RIterator, Compare>& rhs
|
||||
)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_next
|
||||
//
|
||||
template<typename LIterator, typename RIterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::set_symmetric_difference_iterator<LIterator, RIterator, Compare>
|
||||
iterator_next(sprout::set_symmetric_difference_iterator<LIterator, RIterator, Compare> const& it) {
|
||||
return it.next();
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_SET_SYMMETRIC_DIFFERENCE_ITERATOR_HPP
|
|
@ -7,7 +7,10 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/type_traits/common.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/pair.hpp>
|
||||
#include <sprout/algorithm/next_union.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -41,6 +44,8 @@ namespace sprout {
|
|||
typedef typename sprout::common_iterator_difference_type<LIterator, RIterator>::type difference_type;
|
||||
typedef typename sprout::common_iterator_pointer<LIterator, RIterator>::type pointer;
|
||||
typedef typename sprout::common_iterator_reference<LIterator, RIterator>::type reference;
|
||||
protected:
|
||||
typedef sprout::pair<iterator_type, iterator2_type> pair_type;
|
||||
private:
|
||||
static SPROUT_CONSTEXPR bool check_in_left(
|
||||
iterator_type it1, iterator_type lst1,
|
||||
|
@ -53,15 +58,22 @@ namespace sprout {
|
|||
;
|
||||
}
|
||||
protected:
|
||||
iterator_type current1;
|
||||
pair_type current;
|
||||
iterator_type lst1;
|
||||
iterator2_type current2;
|
||||
iterator2_type lst2;
|
||||
Compare comp;
|
||||
private:
|
||||
bool in_left;
|
||||
private:
|
||||
SPROUT_CONSTEXPR set_union_iterator(set_union_iterator const& other, pair_type const& next)
|
||||
: current(next)
|
||||
, lst1(other.lst1), lst2(other.lst2)
|
||||
, comp(other.comp)
|
||||
, in_left(check_in_left(next.first, lst1, next.second, lst2, comp))
|
||||
{}
|
||||
public:
|
||||
set_union_iterator()
|
||||
: current1(), lst1(), current2(), lst2(), comp(), in_left(true)
|
||||
: current(), lst1(), lst2(), comp(), in_left(true)
|
||||
{}
|
||||
set_union_iterator(set_union_iterator const&) = default;
|
||||
SPROUT_CONSTEXPR set_union_iterator(
|
||||
|
@ -69,15 +81,15 @@ namespace sprout {
|
|||
iterator2_type it2, iterator2_type lst2,
|
||||
Compare comp = Compare()
|
||||
)
|
||||
: current1(it1), lst1(lst1)
|
||||
, current2(it2), lst2(lst2)
|
||||
: current(it1, it2)
|
||||
, lst1(lst1), lst2(lst2)
|
||||
, comp(comp)
|
||||
, in_left(check_in_left(it1, lst1, it2, lst2, comp))
|
||||
{}
|
||||
template<typename U, typename V, typename W>
|
||||
SPROUT_CONSTEXPR set_union_iterator(set_union_iterator<U, V, W> const& it)
|
||||
: current1(it.base()), lst1(it.last1())
|
||||
, current2(it.base2()), lst2(it.last2())
|
||||
: current(it.base(), it.base2())
|
||||
, lst1(it.last1()), lst2(it.last2())
|
||||
, comp(it.compare())
|
||||
, in_left(it.is_in_left())
|
||||
{}
|
||||
|
@ -88,13 +100,13 @@ namespace sprout {
|
|||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type base() const {
|
||||
return current1;
|
||||
return current.first;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator_type last1() const {
|
||||
return lst1;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator2_type base2() const {
|
||||
return current2;
|
||||
return current.second;
|
||||
}
|
||||
SPROUT_CONSTEXPR iterator2_type last2() const {
|
||||
return lst2;
|
||||
|
@ -106,79 +118,38 @@ namespace sprout {
|
|||
return in_left;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return is_in_left() ? *current1 : *current2;
|
||||
return is_in_left() ? *current.first : *current.second;
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
return &*(*this);
|
||||
}
|
||||
set_union_iterator& operator++() {
|
||||
if (current1 != lst1) {
|
||||
if (current2 != lst2) {
|
||||
if (comp(*current1, *current2)) {
|
||||
++current1;
|
||||
} else if (comp(*current2, *current1)) {
|
||||
++current2;
|
||||
} else {
|
||||
++current1;
|
||||
++current2;
|
||||
}
|
||||
} else {
|
||||
++current1;
|
||||
}
|
||||
} else if (current2 != lst2) {
|
||||
++current2;
|
||||
}
|
||||
in_left = check_in_left(current1, lst1, current2, lst2, comp);
|
||||
current = sprout::next_union(current.first, lst1, current.second, lst2, comp);
|
||||
in_left = check_in_left(current.first, lst1, current.second, lst2, comp);
|
||||
return *this;
|
||||
}
|
||||
set_union_iterator operator++(int) {
|
||||
set_union_iterator result(*this);
|
||||
if (current1 != lst1) {
|
||||
if (current2 != lst2) {
|
||||
if (comp(*current1, *current2)) {
|
||||
++current1;
|
||||
} else if (comp(*current2, *current1)) {
|
||||
++current2;
|
||||
} else {
|
||||
++current1;
|
||||
++current2;
|
||||
}
|
||||
} else {
|
||||
++current1;
|
||||
}
|
||||
} else if (current2 != lst2) {
|
||||
++current2;
|
||||
}
|
||||
in_left = check_in_left(current1, lst1, current2, lst2, comp);
|
||||
current = sprout::next_union(current.first, lst1, current.second, lst2, comp);
|
||||
in_left = check_in_left(current.first, lst1, current.second, lst2, comp);
|
||||
return result;
|
||||
}
|
||||
SPROUT_CONSTEXPR set_union_iterator next() const {
|
||||
return current1 != lst1
|
||||
? current2 != lst2
|
||||
? comp(*current1, *current2)
|
||||
? set_union_iterator(sprout::next(current1), lst1, current2, lst2, comp)
|
||||
: comp(*current2, *current1)
|
||||
? set_union_iterator(current1, lst1, sprout::next(current2), lst2, comp)
|
||||
: set_union_iterator(sprout::next(current1), lst1, sprout::next(current2), lst2, comp)
|
||||
: set_union_iterator(sprout::next(current1), lst1, current2, lst2, comp)
|
||||
: current2 != lst2
|
||||
? set_union_iterator(current1, lst1, sprout::next(current2), lst2, comp)
|
||||
: *this
|
||||
;
|
||||
return set_union_iterator(
|
||||
*this,
|
||||
sprout::next_union(current.first, lst1, current.second, lst2, comp)
|
||||
);
|
||||
}
|
||||
void swap(set_union_iterator& other)
|
||||
SPROUT_NOEXCEPT_EXPR(
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::swap(current1, other.current1))
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::swap(current, other.current))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(lst1, other.lst1))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(current2, other.current2))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(lst2, other.lst2))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(comp, other.comp))
|
||||
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(in_left, other.in_left))
|
||||
)
|
||||
{
|
||||
sprout::swap(current1, other.current1);
|
||||
sprout::swap(current, other.current);
|
||||
sprout::swap(lst1, other.lst1);
|
||||
sprout::swap(current2, other.current2);
|
||||
sprout::swap(lst2, other.lst2);
|
||||
sprout::swap(comp, other.comp);
|
||||
sprout::swap(in_left, other.in_left);
|
||||
|
|
Loading…
Reference in a new issue