Skip to content

Commit

Permalink
Some ICC and MSVC version have some issues. MSVC 2013 is really cripp…
Browse files Browse the repository at this point in the history
…led but most o brigand works with it so we support it as best effort.

This fixes the glaring issues of said compilers.

@jfalcou
  • Loading branch information
edouarda committed Nov 13, 2016
1 parent 746659e commit c312a9c
Show file tree
Hide file tree
Showing 30 changed files with 671 additions and 569 deletions.
13 changes: 9 additions & 4 deletions brigand/algorithms/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ namespace brigand
#if defined(BRIGAND_COMP_MSVC_2013) || defined(BRIGAND_COMP_CUDA) || defined(BRIGAND_COMP_INTEL)
namespace detail
{
template <class P, class T>
struct all_helper : ::brigand::apply<P, T>
{
};

template <bool...>
struct bools_
{
Expand All @@ -26,8 +31,8 @@ namespace detail

template <template <class...> class Sequence, typename Predicate, typename... Ts>
struct all_impl<Sequence<Ts...>, Predicate>
: std::is_same<bools_<true, ::brigand::apply<Predicate, Ts>::value...>,
bools_<::brigand::apply<Predicate, Ts>::value..., true>>
: std::is_same<bools_<true, all_helper<Predicate, Ts>::value...>,
bools_<all_helper<Predicate, Ts>::value..., true>>
{
};
}
Expand All @@ -53,8 +58,8 @@ namespace detail
struct all_impl<Sequence<T, Ts...>, Predicate>
{
static constexpr all_same tester{
static_cast<::brigand::apply<Predicate, T> *>(nullptr),
static_cast<::brigand::apply<Predicate, Ts> *>(nullptr)...};
static_cast< ::brigand::apply<Predicate, T> *>(nullptr),
static_cast< ::brigand::apply<Predicate, Ts> *>(nullptr)...};
using type = bool_<(::brigand::apply<Predicate, T>::value != 0 && tester.value)>;
};

Expand Down
21 changes: 16 additions & 5 deletions brigand/algorithms/count.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ namespace brigand
{
namespace detail
{
#if defined(BRIGAND_COMP_GCC) || defined(BRIGAND_COMP_CLANG) // not MSVC
constexpr std::size_t count_bools(bool const * const begin, bool const * const end,
std::size_t n)
{
return begin == end ? n : detail::count_bools(begin + 1, end, n + *begin);
}
#endif

template <bool... Bs>
struct template_count_bools
Expand Down Expand Up @@ -71,29 +73,38 @@ namespace lazy
struct count_if<S<Ts...>, Pred>
{
static constexpr bool s_v[] = {::brigand::apply<Pred, Ts>::type::value...};
using type = brigand::size_t<::brigand::detail::count_bools(s_v, s_v + sizeof...(Ts), 0u)>;
using type = brigand::size_t< ::brigand::detail::count_bools(s_v, s_v + sizeof...(Ts), 0u)>;
};

template <template <typename...> class S, typename... Ts, template <typename...> class F>
struct count_if<S<Ts...>, bind<F, _1>>
{
static constexpr bool s_v[] = {F<Ts>::value...};
using type = brigand::size_t<::brigand::detail::count_bools(s_v, s_v + sizeof...(Ts), 0u)>;
using type = brigand::size_t< ::brigand::detail::count_bools(s_v, s_v + sizeof...(Ts), 0u)>;
};

template <template <typename...> class S, typename... Ts, template <typename...> class F>
struct count_if<S<Ts...>, F<_1>>
{
static constexpr bool s_v[] = {F<Ts>::type::value...};
using type = brigand::size_t<::brigand::detail::count_bools(s_v, s_v + sizeof...(Ts), 0u)>;
using type = brigand::size_t< ::brigand::detail::count_bools(s_v, s_v + sizeof...(Ts), 0u)>;
};
#else
#if defined(BRIGAND_COMP_MSVC_2015)
template <template <typename...> class S, typename... Ts, typename Pred>
struct count_if<S<Ts...>, Pred>
: ::brigand::detail::template_count_bools<::brigand::apply<Pred, Ts>::value...>
: ::brigand::detail::template_count_bools< ::brigand::apply<Pred, Ts>::value...>
{
};

#else
template <template <typename...> class S, typename... Ts, typename Pred>
struct count_if<S<Ts...>, Pred>
{
template <typename T>
using val_t = brigand::apply<Pred, T>;
using type = typename ::brigand::detail::template_count_bools<val_t<Ts>::value...>::type;
};
#endif
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion brigand/algorithms/detail/non_null.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace detail
// Default find-like predicate

template <typename Args>
struct non_null_impl : bool_<Args::value != 0>{};
struct non_null_impl : bool_<Args::value != 0>{};
using non_null = non_null_impl<_1>;
}
}
2 changes: 1 addition & 1 deletion brigand/algorithms/find.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace lazy
// reverse_find uses reverse and find :o
template <typename Sequence, typename Predicate = detail::non_null>
using reverse_find =
::brigand::lazy::reverse<::brigand::find<brigand::reverse<Sequence>, Predicate>>;
::brigand::lazy::reverse< ::brigand::find<brigand::reverse<Sequence>, Predicate>>;
}

template <typename Sequence, typename Predicate = detail::non_null>
Expand Down
4 changes: 2 additions & 2 deletions brigand/algorithms/index_of.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace detail
struct index_if_impl
{
using type = ::brigand::size_t<size<Sequence>::value -
size<::brigand::find<Sequence, Predicate>>::value>;
size< ::brigand::find<Sequence, Predicate>>::value>;
};

template <class Sequence, typename Predicate, typename NotFoundType>
Expand All @@ -31,7 +31,7 @@ namespace detail
} // namespace detail

template <class Sequence, class Predicate, class NotFoundType = no_such_type_>
using index_if = typename detail::index_if_impl<::brigand::found<Sequence, Predicate>::value,
using index_if = typename detail::index_if_impl< ::brigand::found<Sequence, Predicate>::value,
Sequence, Predicate, NotFoundType>::type;

template <class Sequence, typename T>
Expand Down
13 changes: 9 additions & 4 deletions brigand/algorithms/merge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ namespace brigand
{
namespace detail
{
template <class Comp, class T1, class U>
struct merge_helper : ::brigand::apply<Comp, T1, U>
{
};

template <class L, class Seq1, class Seq2, class Comp>
struct merge_impl;

Expand All @@ -25,7 +30,7 @@ namespace detail

template <class... R, class T0, class T1, class... Ts, class U, class... Us, class Comp>
struct merge_insert<true, list<R...>, list<T0, T1, Ts...>, list<U, Us...>, Comp>
: merge_insert<::brigand::apply<Comp, T1, U>::value, list<R..., T0>, list<T1, Ts...>,
: merge_insert<merge_helper<Comp, T1, U>::value, list<R..., T0>, list<T1, Ts...>,
list<U, Us...>, Comp>
{
};
Expand All @@ -40,7 +45,7 @@ namespace detail

template <class... R, class T, class... Ts, class U0, class U1, class... Us, class Comp>
struct merge_insert<false, list<R...>, list<T, Ts...>, list<U0, U1, Us...>, Comp>
: merge_insert<::brigand::apply<Comp, T, U1>::value, list<R..., U0>, list<T, Ts...>,
: merge_insert<merge_helper<Comp, T, U1>::value, list<R..., U0>, list<T, Ts...>,
list<U1, Us...>, Comp>
{
};
Expand All @@ -59,7 +64,7 @@ namespace detail
struct merge_impl<list<R...>, list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, Ts...>,
list<U0, U1, U2, U3, U4, U5, U6, U7, U8, U9, Us...>, Comp>
{
using sub = merge_insert<::brigand::apply<Comp, T0, U0>::value, list<>,
using sub = merge_insert<merge_helper<Comp, T0, U0>::value, list<>,
list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>,
list<U0, U1, U2, U3, U4, U5, U6, U7, U8, U9>, Comp>;
using type = typename merge_impl<append<list<R...>, typename sub::list>,
Expand All @@ -69,7 +74,7 @@ namespace detail

template <class... R, class T, class... Ts, class U, class... Us, class Comp>
struct merge_impl<list<R...>, list<T, Ts...>, list<U, Us...>, Comp>
: std::conditional<::brigand::apply<Comp, T, U>::value,
: std::conditional<merge_helper<Comp, T, U>::value,
merge_impl<list<R..., T>, list<Ts...>, list<U, Us...>, Comp>,
merge_impl<list<R..., U>, list<T, Ts...>, list<Us...>, Comp>>::type
{
Expand Down
6 changes: 2 additions & 4 deletions brigand/algorithms/none.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace brigand
{

#if defined(BRIGAND_COMP_MSVC_2013) || defined(BRIGAND_COMP_CUDA) || defined(BRIGAND_COMP_INTEL)
namespace detail
{
Expand All @@ -26,7 +25,6 @@ namespace detail
using that = brigand::apply<Pred, T>;
using type = bool_<!that::value>;
};

using type = all<Sequence, nope<_1>>;
};
}
Expand All @@ -43,8 +41,8 @@ namespace detail
struct none_impl<Sequence<T, Ts...>, Predicate>
{
static constexpr all_same tester{
static_cast<::brigand::apply<Predicate, T> *>(nullptr),
static_cast<::brigand::apply<Predicate, Ts> *>(nullptr)...};
static_cast< ::brigand::apply<Predicate, T> *>(nullptr),
static_cast< ::brigand::apply<Predicate, Ts> *>(nullptr)...};
using type = bool_<(::brigand::apply<Predicate, T>::value == 0 && tester.value)>;
};

Expand Down
11 changes: 8 additions & 3 deletions brigand/algorithms/remove.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace lazy
template <template <class...> class L, typename... Ts, typename Pred>
struct remove_if<L<Ts...>, Pred>
: ::brigand::detail::append_impl<
L<>, typename std::conditional<::brigand::apply<Pred, Ts>::value, list<>,
L<>, typename std::conditional< ::brigand::apply<Pred, Ts>::value, list<>,
list<Ts>>::type...>
{
};
Expand Down Expand Up @@ -66,7 +66,7 @@ namespace lazy
template <template <class...> class L, typename... Ts, typename Pred>
struct filter<L<Ts...>, Pred>
: ::brigand::detail::append_impl<
L<>, typename std::conditional<::brigand::apply<Pred, Ts>::value, list<Ts>,
L<>, typename std::conditional< ::brigand::apply<Pred, Ts>::value, list<Ts>,
list<>>::type...>
{
};
Expand All @@ -88,9 +88,14 @@ namespace lazy
#else
namespace detail
{
template <class Pred, class T>
struct empty_helper : ::brigand::apply<Pred, T>
{
};

// this is essentially just a work around because MSVC can't expand variadic packs properly
template <typename Pred, typename T, bool B>
struct empty_if_true : std::conditional<::brigand::apply<Pred, T>::value == B, list<>, list<T>>
struct empty_if_true : std::conditional<empty_helper<Pred, T>::value == B, list<>, list<T>>
{
};
template <template <typename...> class F, typename T, bool B>
Expand Down
10 changes: 8 additions & 2 deletions brigand/algorithms/replace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ namespace brigand
//#ifdef BRIGAND_COMP_MSVC
namespace detail
{
template <typename Pred, typename T>
struct rep_helper
{
using type = brigand::apply<Pred, T>;
};

template <typename T, typename Pred, typename NewType>
struct replacer : std::conditional<::brigand::apply<Pred, T>::value, NewType, T>
struct replacer : std::conditional<rep_helper<Pred, T>::type::value, NewType, T>
{
};
template <typename T, template <typename...> class F, typename NewType>
Expand All @@ -35,7 +41,7 @@ namespace lazy

template <typename Sequence, typename Predicate, typename NewType>
struct replace_if;
//#ifdef BRIGAND_COMP_MSVC

template <template <typename...> class S, typename... Ts, typename Predicate, typename NewType>
struct replace_if<S<Ts...>, Predicate, NewType>
{
Expand Down
4 changes: 2 additions & 2 deletions brigand/algorithms/sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ namespace detail
template <class T0, class T1, class Comp>
struct mini_sort<list<T0, T1>, Comp>
{
using type = typename std::conditional<::brigand::apply<Comp, T0, T1>::value, list<T0, T1>,
list<T1, T0>>::type;
using base = ::brigand::apply<Comp, T0, T1>;
using type = typename std::conditional<base::value, list<T0, T1>, list<T1, T0>>::type;
};

template <class T0, class Comp>
Expand Down
12 changes: 11 additions & 1 deletion brigand/algorithms/split_at.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ namespace detail
{
template <bool b, typename O, typename L, std::size_t I>
struct split_at_impl; // if you get an error here your index is out of bounds

#if defined(BRIGAND_COMP_INTEL)
template <template <typename...> class S, typename... Os>
struct split_at_impl<false, S<Os...>, S<>, 0>
{
using type = S<S<Os...>, S<> >;
};
#else
template <template <typename...> class S, typename... Os, typename... Ts>
struct split_at_impl<false, S<Os...>, S<Ts...>, 0>
{
using type = S<S<Os...>, S<Ts...>>;
};
#endif

template <template <typename...> class S, typename... Os, typename T, typename... Ts>
struct split_at_impl<false, S<Os...>, S<T, Ts...>, 0>
{
Expand Down Expand Up @@ -55,4 +65,4 @@ namespace lazy
}
template <typename L, typename I>
using split_at = typename ::brigand::lazy::split_at<L, I>::type;
}
}
30 changes: 15 additions & 15 deletions brigand/algorithms/transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,20 @@ namespace brigand
using type = Seq<brigand::apply<Func, T>...>;
};

//fast track for eager
template<template<class...> class Seq, class... T, template<typename...> class Func>
struct transform<0, Seq<T...>, bind<Func, _1>>
{
using type = Seq<Func<T>...>;
};

//fast track for lazy
template<template<class...> class Seq, class... T, template<typename...> class Func>
struct transform<0, Seq<T...>, Func<_1>>
{
using type = Seq<typename Func<T>::type...>;
};
//fast track for eager
template<template<class...> class Seq, class... T, template<typename...> class Func>
struct transform<0, Seq<T...>, bind<Func, _1>>
{
using type = Seq<Func<T>...>;
};

//fast track for lazy
template<template<class...> class Seq, class... T, template<typename...> class Func>
struct transform<0, Seq<T...>, Func<_1>>
{
using type = Seq<typename Func<T>::type...>;
};

template<template<class...> class Seq1, class... T1, template<class...> class Seq2, class... T2, class Func>
struct transform<1, Seq1<T1...>, Seq2<T2...>, Func>
{
Expand All @@ -106,7 +106,7 @@ namespace brigand
namespace lazy
{
template<typename Sequence1, typename OpSeq1, typename... OpSeq2>
struct transform : detail::transform<sizeof...(OpSeq2), Sequence1, OpSeq1, OpSeq2...> {};
struct transform : detail::transform<sizeof...(OpSeq2), Sequence1, OpSeq1, OpSeq2...> {};
}

// Main transform entry point
Expand Down
Loading

0 comments on commit c312a9c

Please sign in to comment.