Skip to content

Commit 24cc0d6

Browse files
author
ecrypa
committed
brute-force attempt to fix min_element example on GCC 4.7
1 parent cc03ecc commit 24cc0d6

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

include/metal/list/min_element.hpp

+33-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "../config.hpp"
55
#include "../detail/sfinae.hpp"
66
#include "../lambda/lambda.hpp"
7-
#include "../number/if.hpp"
87
#include "../number/less.hpp"
98

109
namespace metal {
@@ -53,32 +52,53 @@ namespace metal {
5352
/// \see min, sort
5453
#if !defined(METAL_WORKAROUND)
5554
template<class seq, class lbd = metal::lambda<metal::less>>
56-
using min_element = detail::call<
57-
detail::_min_element<if_<is_lambda<lbd>, lbd>>::template type, seq>;
55+
using min_element =
56+
detail::call<detail::_min_element<lbd>::template type, seq>;
5857
#else
5958
// MSVC 14 has shabby SFINAE support in case of default alias template args
6059
template<class seq, class... lbd>
61-
using min_element = detail::call<
62-
detail::_min_element<if_<is_lambda<lbd>, lbd>...>::template type, seq>;
60+
using min_element =
61+
detail::call<detail::_min_element<lbd...>::template type, seq>;
6362
#endif
6463
}
6564

66-
#include "../lambda/apply.hpp"
67-
#include "../lambda/invoke.hpp"
68-
#include "../lambda/partial.hpp"
65+
#include "../list/list.hpp"
66+
#include "../number/if.hpp"
6967
#include "../value/fold_left.hpp"
7068

7169
namespace metal {
7270
/// \cond
7371
namespace detail {
74-
template<class lbd>
75-
struct _min_element {
72+
template<class x, class y>
73+
struct _min_element_min_impl {
74+
template<template<class...> class expr>
75+
using type = if_<expr<y, x>, y, x>;
76+
};
77+
78+
template<template<class...> class expr>
79+
struct _min_element_min {
7680
template<class x, class y>
77-
using custom_min = if_<invoke<lbd, y, x>, y, x>;
81+
using type =
82+
forward<_min_element_min_impl<x, y>::template type, expr>;
83+
};
7884

85+
template<class seq>
86+
struct _min_element_impl {};
87+
88+
template<class... vals>
89+
struct _min_element_impl<list<vals...>> {
90+
template<template<class...> class expr>
91+
using type = fold_left<
92+
lambda<_min_element_min<expr>::template type>, vals...>;
93+
};
94+
95+
template<class lbd>
96+
struct _min_element {};
97+
98+
template<template<class...> class expr>
99+
struct _min_element<lambda<expr>> {
79100
template<class seq>
80-
using type =
81-
apply<partial<lambda<fold_left>, lambda<custom_min>>, seq>;
101+
using type = forward<_min_element_impl<seq>::template type, expr>;
82102
};
83103
}
84104
/// \endcond

0 commit comments

Comments
 (0)