Skip to content

Commit

Permalink
compatibility with msvc 19.28
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpoelen committed Jan 17, 2021
1 parent a72c070 commit bf401c5
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 39 deletions.
28 changes: 27 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,34 @@ jobs:
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86
IF ERRORLEVEL 1 EXIT
set PATH=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Tools\Llvm\bin;%PATH%
set CC=clang-cl
:after_vc
set CC=%CXX%
python -m pip install ninja meson
meson setup build -Dwarning_level=3 -Dmp_debug=${{ matrix.debug }} -Db_colorout=always
type D:\a\jln.mp\jln.mp\build\meson-logs\meson-log.txt
ninja -C build -k10
windows-cl:
name: Windows ${{ matrix.env }} dbg=${{ matrix.debug }}
runs-on: windows-latest
timeout-minutes: 4
strategy:
fail-fast: false
matrix:
env: [cl]
debug: ['false']

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
- shell: cmd
env:
CXX: ${{ matrix.env }}
run: |
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86
IF ERRORLEVEL 1 EXIT
set PATH=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Tools\Llvm\bin;%PATH%
set CC=%CXX%
python -m pip install ninja meson
meson setup build -Dwarning_level=3 -Dmp_debug=${{ matrix.debug }} -Db_colorout=always
type D:\a\jln.mp\jln.mp\build\meson-logs\meson-log.txt
Expand Down
12 changes: 11 additions & 1 deletion include/jln/mp/algorithm/adjacent_difference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,21 @@ namespace jln::mp
/// \cond
namespace jln::mp::detail
{
#ifdef _MSC_VER
template<class C, class x, int_... xs>
using _adjacent_difference_msvc = JLN_MP_DCALL_XS(xs, C, x, number<xs>...);
#endif

template<class y, class... ys>
struct _adjacent_difference<list<y, ys...>>
{
#ifdef _MSC_VER
template<class C, class x, class... xs>
using f = _adjacent_difference_msvc<C, x, (xs::value - ys::value)...>;
#else
template<class C, class x, class... xs>
using f = typename C::template f<x, number<xs::value - ys::value>...>;
using f = JLN_MP_DCALL_XS(xs, C, x, number<xs::value - ys::value>...);
#endif
};

template<>
Expand Down
12 changes: 12 additions & 0 deletions include/jln/mp/functional/call.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
#include "../list/list.hpp"
#include "../number/number.hpp"

/// \cond
#ifdef _MSC_VER
# ifdef JLN_MP_ENABLE_DEBUG
# ifndef JLN_MP_ENABLE_DEBUG_FORCE
# undef JLN_MP_ENABLE_DEBUG
# define JLN_MP_ENABLE_DEBUG 1
# endif
# else
# define JLN_MP_ENABLE_DEBUG 1
# endif
#endif
/// \endcond

namespace jln::mp
{
Expand Down
12 changes: 6 additions & 6 deletions include/jln/mp/functional/try.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace jln::mp
namespace detail
{
template<class, class, class = void>
struct _try;
struct _try_impl;

template<class x>
struct _try_dispatch;
Expand All @@ -42,7 +42,7 @@ namespace jln::mp
{
template<class... xs>
using f = typename detail::_try_dispatch<
typename detail::_try<F, list<xs...>>::type
typename detail::_try_impl<F, list<xs...>>::type
>::template f<TC, FC, xs...>;
};

Expand All @@ -65,15 +65,15 @@ namespace jln::mp
{
template<class... xs>
using f = number<!std::is_same<na,
typename detail::_try<F, list<xs...>>::type
typename detail::_try_impl<F, list<xs...>>::type
>::value>;
};

template<class F>
struct try_<F, identity, violation>
{
template<class... xs>
using f = typename detail::_try<F, list<xs...>>::type;
using f = typename detail::_try_impl<F, list<xs...>>::type;
};
/// \endcond
}
Expand All @@ -82,13 +82,13 @@ namespace jln::mp
namespace jln::mp::detail
{
template<class, class, class>
struct _try
struct _try_impl
{
using type = na;
};

template<class F, class... xs>
struct _try<F, list<xs...>, std::void_t<typename F::template f<xs...>>>
struct _try_impl<F, list<xs...>, std::void_t<typename F::template f<xs...>>>
{
using type = typename F::template f<xs...>;
};
Expand Down
38 changes: 29 additions & 9 deletions include/jln/mp/list/slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "list.hpp"
#include "../number/number.hpp"
#include "../utility/unpack.hpp"
#include "../utility/conditional.hpp"

namespace jln::mp
{
Expand Down Expand Up @@ -33,20 +34,24 @@ namespace jln::mp
::template f<
start::value, size::value,
// verify that stride is strictly greater than 0
#ifdef _MSC_VER
emp::conditional_c<(stride::value > 0), stride, void>::value,
#else
unsigned{int_(stride::value)-1}+1u,
#endif
C, sizeof...(xs)>
::template f<xs...>;
};

template<unsigned start, unsigned size, unsigned stride = 1, class C = listify>
template<int_ start, int_ size, int_ stride = 1, class C = listify>
using slice_c = slice<number<start>, number<size>, number<stride>, C>;

namespace emp
{
template<class L, class start, class size, class stride = number<1>, class C = mp::listify>
using slice = unpack<L, slice<start, size, stride, C>>;

template<class L, unsigned start, unsigned size, unsigned stride = 1, class C = mp::listify>
template<class L, int_ start, int_ size, int_ stride = 1, class C = mp::listify>
using slice_c = slice<L, number<start>, number<size>, number<stride>, C>;
}
}
Expand Down Expand Up @@ -75,31 +80,46 @@ namespace jln::mp::detail
template<>
struct _slice<2>
{
template<unsigned start, unsigned size, unsigned /*stride*/, class C, unsigned len>
template<int_ start, int_ size, unsigned /*stride*/, class C, std::size_t len>
using f = drop_c<start, take_c<
detail::validate_index<size - 1u,
unsigned{int_(len) - start}>::value + 1u,
detail::validate_index<size - 1,
#ifdef _MSC_VER
(start < int_(len) ? int_(len) - start : 0)
#else
unsigned{len - start}
#endif
>::value + 1,
C>>;
};

template<unsigned size, unsigned stride, class C>
template<int_ size, int_ stride, class C>
struct _slice_impl
{
#ifdef _MSC_VER
template<int_ i, class x>
using g = typename wrap_in_list_c<(i <= size && i % stride == 0)>::template f<x>;
#endif

template<int_... ints>
struct impl
{
#ifdef _MSC_VER
template<class... xs>
using f = call<join<C>, g<ints, xs>...>;
#else
template<class... xs>
using f = typename join<C>::template f<
typename wrap_in_list_c<(ints <= size && ints % stride == 0)>
::template f<xs>
...>;
#endif
};
};

template<>
struct _slice<1>
{
template<unsigned start, unsigned size, unsigned stride, class C, unsigned len>
template<int_ start, int_ size, unsigned stride, class C, std::size_t len>
using f = drop_c<
start,
typename emp::make_int_sequence_v_c<
Expand All @@ -115,7 +135,7 @@ namespace jln::mp::detail
template<>
struct _slice<0>
{
template<unsigned start, unsigned size, unsigned /*stride*/, class C, unsigned len>
template<int_ start, int_ size, unsigned /*stride*/, class C, std::size_t len>
using f = typename conditional_c<
bool(detail::validate_index<start, len>::value)
>::template f<C, C>;
Expand All @@ -124,7 +144,7 @@ namespace jln::mp::detail
template<>
struct _slice<3>
{
template<unsigned start, unsigned size, unsigned /*stride*/, class C, unsigned len>
template<int_ start, int_ size, unsigned /*stride*/, class C, std::size_t len>
using f = drop_c<start, front<C>>;
};
}
Expand Down
10 changes: 7 additions & 3 deletions include/jln/mp/list/sliding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace jln::mp
{
constexpr int_ sliding_stride(int_ size, int_ stride);

template<int_ size, int_ stride, int_ = sliding_stride(size, stride)>
template<int_ size, int_ stride, int_>
struct mk_sliding;
}
/// \endcond
Expand All @@ -30,13 +30,17 @@ namespace jln::mp
/// If `stride > 1`, the last window may be smaller than \c size
template<class size, class stride, class C = listify>
using sliding_with_stride = typename detail::mk_sliding<
size::value, stride::value>::template f<C>;
size::value, stride::value,
detail::sliding_stride(size::value, stride::value)
>::template f<C>;

template<class size, class C = listify>
using sliding = sliding_with_stride<size, number<1>, C>;

template<int_ size, int_ stride = 1, class C = listify>
using sliding_with_stride_c = typename detail::mk_sliding<size, stride>::template f<C>;
using sliding_with_stride_c = typename detail::mk_sliding<size, stride,
detail::sliding_stride(size, stride)
>::template f<C>;

template<int_ size, class C = listify>
using sliding_c = sliding_with_stride_c<size, 1, C>;
Expand Down
53 changes: 46 additions & 7 deletions include/jln/mp/smp/number/operators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../functional/if.hpp"
#include "../list/size.hpp"
#include "../list/push_back.hpp"
#include "../list/pop_front.hpp"

/// \cond
namespace jln::mp::detail
Expand All @@ -15,7 +16,42 @@ namespace jln::mp::detail
if_<
size<>,
try_<Tpl<assume_number<C>>>,
always<number<i>, assume_number<C>>>>;
always<number<i>, assume_number<C>>
>
>;

#ifdef _MSC_VER
template<template<class...> class Tpl, class C, int_ i = 0>
using smp_op_without_zero = contract<
if_<
size<>,
if_<
pop_front<and_<>>,
try_<Tpl<assume_number<C>>>,
violation
>,
always<number<i>, assume_number<C>>
>
>;

template<class C>
using smp_op_without_zero_and_with_value = contract<
if_<
size<>,
if_<
pop_front<and_<>>,
try_<C>,
violation
>,
violation
>
>;
# define JLN_smp_op_without_zero detail::smp_op_without_zero
# define JLN_smp_op_without_zero_and_with_value detail::smp_op_without_zero_and_with_value
#else
# define JLN_smp_op_without_zero detail::smp_op_default
# define JLN_smp_op_without_zero_and_with_value try_contract
#endif
}
/// \endcond

Expand Down Expand Up @@ -61,22 +97,22 @@ namespace jln::mp::smp
using mul1 = detail::smp_op_default<mp::mul, C, 1>;

template<class C = identity>
using div = try_contract<mp::div<assume_number<C>>>;
using div = JLN_smp_op_without_zero_and_with_value<mp::div<assume_number<C>>>;

template<class C = identity>
using div0 = detail::smp_op_default<mp::div, C>;
using div0 = JLN_smp_op_without_zero<mp::div, C>;

template<class C = identity>
using div1 = detail::smp_op_default<mp::div, C, 1>;
using div1 = JLN_smp_op_without_zero<mp::div, C, 1>;

template<class C = identity>
using mod = try_contract<mp::mod<assume_number<C>>>;
using mod = JLN_smp_op_without_zero_and_with_value<mp::mod<assume_number<C>>>;

template<class C = identity>
using mod0 = detail::smp_op_default<mp::mod, C>;
using mod0 = JLN_smp_op_without_zero<mp::mod, C>;

template<class C = identity>
using mod1 = detail::smp_op_default<mp::mod, C, 1>;
using mod1 = JLN_smp_op_without_zero<mp::mod, C, 1>;

template<class C = identity>
using xor_ = try_contract<mp::xor_<assume_number<C>>>;
Expand Down Expand Up @@ -344,4 +380,7 @@ namespace jln::mp::detail
// JLN_MP_MAKE_EXPECTED_ARGUMENT1(argument_category::binary_number, greater);
// JLN_MP_MAKE_EXPECTED_ARGUMENT1(argument_category::binary_number, greater_equal);
}

#undef JLN_smp_op_without_zero
#undef JLN_smp_op_without_zero_and_with_value
/// \endcond
Loading

0 comments on commit bf401c5

Please sign in to comment.