0

c++ code

template <typename F, typename V, typename R, typename T, typename... Types>
struct dispatcher<F, V, R, T, Types...>
{
    VARIANT_INLINE static R apply_const(V const& v, F&& f)
    {
        if (v.template is<T>())
        {
            return f(unwrapper<T>::apply_const(v.template get_unchecked<T>()));
        }
        else
        {
            return dispatcher<F, V, R, Types...>::apply_const(v, std::forward<F>(f));
        }
    }

    VARIANT_INLINE static R apply(V& v, F&& f)
    {
        if (v.template is<T>())
        {
            return f(unwrapper<T>::apply(v.template get_unchecked<T>()));
        }
        else
        {
            return dispatcher<F, V, R, Types...>::apply(v, std::forward<F>(f));
        }
    }
};

what is mean v.template is<T>() in this c++ prog? i cannot find any "is" function, this v.template is<T>() is system inner function or keyword with v.template get_unchecked<T>().

S1mple
  • 11
  • 2
  • 1
    Apparently, whichever type `dispatcher` is going to be instantiated with, is expected to provide a member function template named `is`. – Igor Tandetnik Feb 28 '19 at 05:21
  • The code seems to come [from here](https://github.com/mapbox/variant/blob/master/include/mapbox/variant.hpp). Class `variant` in that file does have a member function template named `is`, as well as one named `get_unchecked`. Where were you looking for it, that you failed to find it? – Igor Tandetnik Feb 28 '19 at 05:25
  • If the question is about the syntax `.template`, see [Where and why do I have to put the “template” and “typename” keywords?](https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – Jarod42 Feb 28 '19 at 09:23

0 Answers0