0

Eventually I need to filter a typelist (brigand::list - defined in brigand meta-programming library). But to start:

I have a settings class that holds a type list:

   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>;
}

The brigand library offers a filter "function", but to pass my filter there i need to wrap it using brigand::bind. Here's an example of that:

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>;

The last step - which i cannot overcome, is to put the filtering inside a class, depending on a template param:

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

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

When compiling the problem line i first get an error that i need to use typename keyword before TSettings:

to refer to a type member of a template parameter, use 'typename TSettings:: 

That sounds exactly like what i want! I guess it is needed to explicitly tell compiler to treat TSettings as a type? However when i add it, i get this error from inside brigand's bind function:

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>)'
TheSmokingGnu
  • 302
  • 2
  • 6
  • 15
  • You probably want: `template – Jarod42 Jul 25 '18 at 22:49
  • I'm guessing Jarod has the answer. But we would have a better hint if you could show an example usage of `FilteringClass` (with whatever you provide as a template argument also declared). – aschepler Jul 25 '18 at 23:07

1 Answers1

1

So, i found what i was missing, albeit almost randomly To add that another alias correctly i needed to add ::template, like that:

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

I guess without it the fact that original alias was templated was somehow lost to the compiler.

The meaning of the keyword is nicely explained in this answer.

TheSmokingGnu
  • 302
  • 2
  • 6
  • 15