lundi 29 avril 2019

Template function overload resolution of T vs. SomeClass

I want to understand why the void handleParam(const Str& name, Table<T> value) template overload never gets instantiated (note that the code below is illustrative). I'm sure there is a perfectly good reason why it doesn't work, I just want to understand that reason. I'm aware of (and using) the workaround using an intermediate templated struct. But if something like the below was possible it would simplify my code a lot.

class TypeHandler
{
public:
    TypeHandler(OtherClass& bi) : _bi(bi) { }

    template <typename T> void handleParam(const Str& name, Table<T> value)
    {
        // Never gets instantiated.
    }

    template <typename T> void handleParam(const Str& name, T value)
    {

    }
}

template<typename HandlerType>
void HandleParamValue::handleTab(DataBlock& data, HandlerType& handler) {

    ...

    // Table of floats.
    Table<float> tab;
    handler.handleParam<Table<float>>(param_name, tab);

    // etc.
    ...
}

template<typename HandlerType>
void ParamStore::Iterate(HandlerType& handler) {
    for (...) {

        ...

        if (is_table(type)) {
            HandleParamValue::handleTab<HandlerType>(_datablock, handler);
        }
        else {
            HandleParamValue::handle<HandlerType>(_datablock, handler);
        }
    }
}

// Kick the whole thing off.
TypeHandler handler(_some_instance);
_param_store->Iterate(handler);

Aucun commentaire:

Enregistrer un commentaire