1
// partial_apply.hpp
template <template <class...> class Op, class ...Ts>
struct partial_apply {
    template <class ...Args> using type = Op<Ts..., Args...>;
};
# define PARTIAL_APPLY_T(OP, ...) typename partial_apply<OP, ##__VA_ARGS__>::template type

// test_partial_apply.cc
#include "partial_apply.hpp"

template <class ...Ts> struct A {};
template <template <class...> class Op> using apply_int = Op<int>;

int main() {
    using type = apply_int<PARTIAL_APPLY_T(A)>;
}

I compiled test_partial_apply.cc using command clang++-5.0 -std=c++17 test_partial_apply.cc which issued the following errors:

test_partial_apply.cc:8:28: error: expected an identifier or template-id after '::'
    using type = apply_int<PARTIAL_APPLY_T(A)>;
                           ^~~~~~~~~~~~~~~~~~
./../include/partial_apply.hpp:9:78: note: expanded from macro 'PARTIAL_APPLY_T'
# define PARTIAL_APPLY_T(OP, ...) typename partial_apply<OP, ##__VA_ARGS__>::template type
                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
test_partial_apply.cc:8:28: error: expected a type
./../include/partial_apply.hpp:9:78: note: expanded from macro 'PARTIAL_APPLY_T'
# define PARTIAL_APPLY_T(OP, ...) typename partial_apply<OP, ##__VA_ARGS__>::template type
                                                                             ^
2 errors generated.
JiaHao Xu
  • 2,452
  • 16
  • 31

1 Answers1

2

Use typename disambiguator only when it is indeed a type. Without specifying template arguments template <class ...Args> using type = Op<Ts..., Args...>; is not a type.

Remove typename, it should work:

# define PARTIAL_APPLY_T(OP, ...) partial_apply<OP, ##__VA_ARGS__>::template type

Live Demo

llllllllll
  • 16,169
  • 4
  • 31
  • 54