As part of writing a new variant template to replace my usage of boost::variant in the Quxlang compiler (it’s missing some functionality I needed to work on non-clang C++ compilers), I wanted to write variant_detail::make_variant_info<type>(), but I had to write variant_detail::template make_variant_info<type>() instead. The use of typename and template in seemingly random places helps C++ to parse the input code. Supposing you have foo<bar>(baz) is this (foo < bar) > (baz) or a template? I think it was pretty obvious in this case that I wanted the template, but unfortunately the C++ compiler isn’t always so smart and so when it doesn’t know if foo is a template (perhaps because foo here is produced from a template).
Qux solves this problem entirely by… using a different symbol for template instantiation and the less-than operation. Wow, what an amazing and complicated solution. Or rather, I’m surprised nobody in C++ land thought using < was a bad idea. Oh well, lesson learned I suppose? In Quxlang, the symbol used is the humble @ operator! There are two ways to instantiate a temploid* in Quxlang, the first is the a@b syntax, where the template a is instantiated with a single argument, and the second, formal version is a@(b, c, d, ...) which supports any number of arguments.
You’ll never need to write foo.template < a > ever again! (assuming you write your code in Quxlang and not C++)
*In Quxlang, a temploid is anything that can be instantiated such as a template or a function**. Basically anything that can use template parameters or have multiple overloads.
** Actually these are both temploidic declarations and not temploids per se, but I don’t want to cover that topic in this post. For now accept this simplification.
Leave a comment