0

I wanted to go deeper in template code, but I got an error that I reproduce in the simplified code here :

namespace impl {
    template<class T>
    struct DefaultPolicy {
        static T unwrap(T value) { return value; };
    };
}

struct DefaultPolicy {
    template <class T> using type = typename impl::DefaultPolicy<T>;
};

template <class T, class Policy>
auto unwrap(T value, Policy) {
    using policy_t = typename Policy::type<T>;
    return policy_t::unwrap(value);
};

int main() {
    unwrap(42, DefaultPolicy{});
}

I have no idea how to correct what looks like a basic syntax error :

error: expected ';' before '<' token
     using policy_t = typename Policy::type<T>;
                                           ^

However, if I replace the 'Policy' type by 'DefaultPolicy' (what should be done by the compiler ... more or less ?), I got no error.

So, is there a simple syntax solution, or am I trying to do something not possible ?

S. Congard
  • 1
  • 1
  • 2
  • 3
    Add the `template` disambiguator. (Why it's needed, look it up, there's duplicates.) `using policy_t = typename Policy::template type;` – DeiDei Sep 28 '17 at 21:49
  • 1
    [Clang has a much better error message here](http://coliru.stacked-crooked.com/a/58025b3a86589dba). – nwp Sep 28 '17 at 21:50
  • Thanks, it works ! I'm sorry for the duplicate, seems I made bad researchs – S. Congard Sep 28 '17 at 21:55

0 Answers0