0

With mapbox::variant (https://github.com/mapbox/variant/blob/master/include/mapbox/variant.hpp), I can do the following:

using variant = mapbox::util::variant<Args...>;
variant<std::string> v;
// do something with v
...
// Get string from v:
std::string s = v.get<std::string>();

But when I try to implement this by a template function, I got compile error:

template <typename T>
T getValue()
{
    variant<T> value{};
    // Get value
    ...
    return value.get<T>();
}

GCC complains:

../utils.hpp:52:23: error: expected primary-expression before '>' token return value.get(); ^ ../utils.hpp:52:25: error: expected primary-expression before ')' token return value.get();

What is wrong with the template function?

Mine
  • 4,123
  • 1
  • 25
  • 46

1 Answers1

1

I think you want:

return value.template get<T>();

this answer gives a good/comprehensive description as to why...

Community
  • 1
  • 1
Biggy Smith
  • 910
  • 7
  • 14