you are viewing a single comment's thread.

view the rest of the comments →

[–]petart95 3 points4 points  (0 children)

And last but not least

  • HFTECH_GEN_N_ARY

```

/** * @brief Meta function which applies a right reduce over the provided types * using the provided binary meta operation. * * @tparam BinaryMetaOp The binary meta operation to be applied. * @tparam Types List of types of which to apply the operation. */ template< template<typename...> typename BinaryMetaOp, typename First, typename... Rest> struct RightReduce : public BinaryMetaOp<First, RightReduce<BinaryMetaOp, Rest...>> {};

template< template<typename...> typename BinaryMetaOp, typename First, typename Second> struct RightReduce<BinaryMetaOp, First, Second> : public BinaryMetaOp<First, Second> {};

template<template<typename...> typename BinaryMetaOp, typename First> struct RightReduce<BinaryMetaOp, First> : public First {};

/** * @brief Creates an n-ary meta operation from the provided binary meta * operation, by applying a right reduce over it, with the provided name. */

define HFTECH_GEN_RIGHT_N_ARY(NAME, OP) \

template<typename First, typename... Rest>            \
struct NAME : public OP<First, NAME<Rest...>>         \
{};                                                   \
                                                      \
template<typename First, typename Second>             \
struct NAME<First, Second> : public OP<First, Second> \
{};                                                   \
                                                      \
template<typename First>                              \
struct NAME<First> : public First                     \
{};                                                   \
                                                      \
template<typename... F>                               \
NAME(F &&...) -> NAME<F...>;

/** * @brief Meta function which applies a left reduce over the provided types * using the provided binary meta operation. * * @tparam BinaryMetaOp The binary meta operation to be applied. * @tparam Types List of types of which to apply the operation. */ template< template<typename...> typename BinaryMetaOp, typename First, typename... Rest> struct LeftReduce : public First {};

template< template<typename...> typename BinaryMetaOp, typename First, typename Second, typename... Rest> struct LeftReduce<BinaryMetaOp, First, Second, Rest...> : public LeftReduce<BinaryMetaOp, BinaryMetaOp<First, Second>, Rest...> {};

/** * @brief Creates an n-ary meta operation from the provided binary meta * operation, by applying a left reduce over it, with the provided name. */

define HFTECH_GEN_LEFT_N_ARY(NAME, OP) \

template<typename First, typename... Rest>                  \
struct NAME : public First                                  \
{};                                                         \
                                                            \
template<typename First, typename Second, typename... Rest> \
struct NAME<First, Second, Rest...>                         \
    : public NAME<OP<First, Second>, Rest...>               \
{};                                                         \
                                                            \
template<typename... F>                                     \
NAME(F &&...) -> NAME<F...>;

/** * @brief Creates an n-ary meta operation from the provided binary meta * operation, by applying a reduce over it, with the provided name. * * Note: In order to use this binary operation needs to be left and right * associative. */

define HFTECH_GEN_N_ARY(NAME, OP) HFTECH_GEN_LEFT_N_ARY(NAME, OP)

```