Skip to content

Commit

Permalink
try GCC 4.7 workaround from brunocodutra#100 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrypa committed Oct 27, 2019
1 parent b049b98 commit a715b23
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions include/metal/list/min_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
#define METAL_LIST_MIN_ELEMENT_HPP

#include "../config.hpp"
#include "../lambda/apply.hpp"
#include "../detail/sfinae.hpp"
#include "../lambda/lambda.hpp"
#include "../number/if.hpp"
#include "../number/less.hpp"

namespace metal {
/// \cond
namespace detail {
template<class lbd = metal::lambda<metal::less>>
struct _min_folder;
template<class seq>
struct _min_element;
}
/// \endcond

Expand Down Expand Up @@ -53,26 +52,25 @@ namespace metal {
/// \see min, sort
#if !defined(METAL_WORKAROUND)
template<class seq, class lbd = metal::lambda<metal::less>>
using min_element = apply<
lambda<detail::_min_folder<if_<is_lambda<lbd>, lbd>>::template type>,
seq>;
using min_element =
detail::call<detail::_min_element<seq>::template type, lbd>;
#else
// MSVC 14 has shabby SFINAE support in case of default alias template args
template<class seq, class... lbd>
using min_element = apply<
lambda<detail::_min_folder<if_<is_lambda<lbd>, lbd>...>::template type>,
seq>;
using min_element =
detail::call<detail::_min_element<seq>::template type, lbd...>;
#endif
}

#include "../lambda/invoke.hpp"
#include "../number/if.hpp"
#include "../value/fold_left.hpp"

namespace metal {
/// \cond
namespace detail {
template<class lbd>
struct _min_folder {
template<class lbd = metal::lambda<metal::less>>
struct _min_element_impl {
template<class x, class y>
using custom_min = if_<invoke<lbd, y, x>, y, x>;
// Must use `invoke` in order to support SFINAE. It is tempting to
Expand All @@ -82,6 +80,16 @@ namespace metal {
template<class... vals>
using type = fold_left<lambda<custom_min>, vals...>;
};

template<class seq>
struct _min_element {};

template<class... vals>
struct _min_element<list<vals...>> {
template<typename... lbd>
using type =
call<_min_element_impl<lbd...>::template type, vals...>;
};
}
/// \endcond
}
Expand Down

0 comments on commit a715b23

Please sign in to comment.