workaround for clang3.2 (make_heap, make_partial_heap)

This commit is contained in:
bolero-MURAKAMI 2012-11-14 10:40:01 +09:00
parent 926facbb83
commit 2ddd4014ce

View file

@ -8,10 +8,130 @@
#include <sprout/iterator/operation.hpp>
#include <sprout/algorithm/fixed/result_of.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
#ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE
# include <sprout/workaround/recursive_function_template.hpp>
#endif
namespace sprout {
namespace fixed {
namespace detail {
#ifdef SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE
template<int D = 16, typename Container, typename Compare, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type
make_heap_impl(
Container const& cont, Compare comp,
typename sprout::container_traits<Container>::difference_type offset,
typename sprout::container_traits<Container>::difference_type size,
typename sprout::container_traits<Container>::difference_type n = 0,
typename sprout::container_traits<Container>::difference_type l = 1,
typename sprout::container_traits<Container>::difference_type r = 2
);
template<int D = 16, typename Container, typename Compare, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type
make_heap_impl(
Container const& cont, Compare comp,
typename sprout::container_traits<Container>::difference_type offset,
typename sprout::container_traits<Container>::difference_type size,
typename sprout::container_traits<Container>::difference_type n = 0,
typename sprout::container_traits<Container>::difference_type l = 1,
typename sprout::container_traits<Container>::difference_type r = 2
);
template<int D, typename Container, typename Compare, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE(D)>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type
make_heap_impl_1(
Container const& cont, Compare comp,
typename sprout::container_traits<Container>::difference_type offset,
typename sprout::container_traits<Container>::difference_type size,
typename sprout::container_traits<Container>::difference_type n,
typename sprout::container_traits<Container>::difference_type l,
typename sprout::container_traits<Container>::difference_type r
)
{
return comp(*sprout::next(sprout::internal_begin(cont), offset + l), *sprout::next(sprout::internal_begin(cont), offset + r))
? comp(*sprout::next(sprout::internal_begin(cont), offset + n), *sprout::next(sprout::internal_begin(cont), offset + r))
? sprout::fixed::detail::make_heap_impl<D + 1>(
sprout::fixed::swap_element(
cont,
sprout::next(sprout::internal_begin(cont), offset + n),
sprout::next(sprout::internal_begin(cont), offset + r)
),
comp,
offset, size, r, r * 2 + 1, r * 2 + 2
)
: sprout::deep_copy(cont)
: comp(*sprout::next(sprout::internal_begin(cont), offset + n), *sprout::next(sprout::internal_begin(cont), offset + l))
? sprout::fixed::detail::make_heap_impl<D + 1>(
sprout::fixed::swap_element(
cont,
sprout::next(sprout::internal_begin(cont), offset + n),
sprout::next(sprout::internal_begin(cont), offset + l)
),
comp,
offset, size, l, l * 2 + 1, l * 2 + 2
)
: sprout::deep_copy(cont)
;
}
template<int D, typename Container, typename Compare, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK(D)>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type
make_heap_impl_1(
Container const& cont, Compare comp,
typename sprout::container_traits<Container>::difference_type offset,
typename sprout::container_traits<Container>::difference_type size,
typename sprout::container_traits<Container>::difference_type n,
typename sprout::container_traits<Container>::difference_type l,
typename sprout::container_traits<Container>::difference_type r
)
{
return sprout::throw_recursive_function_template_instantiation_exeeded();
}
template<int D, typename Container, typename Compare, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_CONTINUE_DECL(D)>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type
make_heap_impl(
Container const& cont, Compare comp,
typename sprout::container_traits<Container>::difference_type offset,
typename sprout::container_traits<Container>::difference_type size,
typename sprout::container_traits<Container>::difference_type n,
typename sprout::container_traits<Container>::difference_type l,
typename sprout::container_traits<Container>::difference_type r
)
{
return r > size
? sprout::deep_copy(cont)
: r == size
? comp(*sprout::next(sprout::internal_begin(cont), offset + n), *sprout::next(sprout::internal_begin(cont), offset + l))
? sprout::fixed::swap_element(
cont,
sprout::next(sprout::internal_begin(cont), offset + n),
sprout::next(sprout::internal_begin(cont), offset + l)
)
: sprout::deep_copy(cont)
: sprout::fixed::detail::make_heap_impl_1<D + 1>(
sprout::fixed::detail::make_heap_impl<D + 1>(
sprout::fixed::detail::make_heap_impl<D + 1>(cont, comp, offset, size, l, l * 2 + 1, l * 2 + 2),
comp,
offset, size,
r, r * 2 + 1, r * 2 + 2
),
comp,
offset, size, n, l, r
)
;
}
template<int D, typename Container, typename Compare, SPROUT_RECURSIVE_FUNCTION_TEMPLATE_BREAK_DECL(D)>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type
make_heap_impl(
Container const& cont, Compare comp,
typename sprout::container_traits<Container>::difference_type offset,
typename sprout::container_traits<Container>::difference_type size,
typename sprout::container_traits<Container>::difference_type n,
typename sprout::container_traits<Container>::difference_type l,
typename sprout::container_traits<Container>::difference_type r
)
{
return sprout::throw_recursive_function_template_instantiation_exeeded();
}
#else
template<typename Container, typename Compare>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Container>::type
make_heap_impl(
@ -91,6 +211,7 @@ namespace sprout {
)
;
}
#endif
} // namespace detail
//
// make_heap