将成员模板 typedef 与 using 别名会使编译器认为它不是 class 模板

Aliasing the member template typedef with using makes compiler think it is not a class template

最终我需要过滤一个类型列表(brigand::list - 在 brigand 元编程库中定义)。但要开始:

我有一个包含类型列表的设置 class:

   template<typename TComponentList>
  class Settings {

    // this is an integral_constant holding bool
    template<typename TList, typename T>
    using ContainsFilter = brigand::found<TList, std::is_same<T, brigand::_1>>;

    // is the type present in component list?
       template<typename T>
    using IsComponentFilter = ContainsFilter<TComponentList, T>;
}

brigand 库提供了 filter "function",但要通过我的过滤器,我需要使用 brigand::bind 包装它。这是一个例子:

using ls = brigand::list<TagA, SignatureA, ComponentB>;

// binds the template parameter - passes it to my filter
using wrapped = brigand::bind<TestSettings::IsComponentFilter, brigand::_1>;

// a list holding only ComponentB
using filtered = brigand::filter<ls, wrapped>;

我无法克服的最后一步是根据模板参数将过滤放在 class 中:

   template <class TSettings>
    struct FilteringClass
    {
        // problem line
        using wrapped = brigand::bind<TSettings::IsComponentFilter, brigand::_1>;

        // template<typename TSignature>
        // using SignatureComponents = brigand::filter<TSignature, wrapped>;
    };

编译问题行时,我首先得到一个错误,我需要在 TSettings:

之前使用 typename 关键字
to refer to a type member of a template parameter, use 'typename TSettings:: 

这听起来正是我想要的! 我想是否需要明确告诉编译器将 TSettings 视为一种类型?但是,当我添加它时,我从 brigand's 绑定函数内部收到此错误:

error: type/value mismatch at argument 1 in template parameter list for 'template<template<class ...> class<template-parameter-1-1>, class ...> struct brigand::bind'
     using wrapped = brigand::bind<TSettings, brigand::_1>;
 note:   expected a class template, got '(TSettings:: IsComponentFilter < <expression error>)'

所以,我找到了我丢失的东西,尽管几乎是随机的 要正确添加另一个别名,我需要添加 ::template,例如:

template<typename T>
using wrapped = brigand::bind<typename TSettings::template IsComponentFilter, brigand::_1>;

我想如果没有它,原始别名被模板化的事实不知何故被编译器丢失了。

关键字的含义在this answer中有很好的解释。