Skip to content

Instantly share code, notes, and snippets.

@lucasmeijer
Last active December 23, 2015 00:29
Show Gist options
  • Save lucasmeijer/6554039 to your computer and use it in GitHub Desktop.
Save lucasmeijer/6554039 to your computer and use it in GitHub Desktop.
//PUZZLE: This code compiles, but requires an ugly double argumetn on line 27. How to change the code so
//this is not required, yet the TMagic type is still automatically deduced?
//
//- Dont want to make DoSomething virtual
//- compile with gcc -c test.cpp
template<class T> struct Converter {};
struct TheMagicTypeToFind {};
struct MyConverter : Converter<TheMagicTypeToFind> //I want to store the magic type here
{
void DoSomething();
};
template<class TMagic, class TConverter>
static void MyFunc(TConverter converter, Converter<TMagic>& onlyUsedForArgumentDeduction)
{
TMagic magic;
converter.DoSomething();
}
static void Main()
{
MyConverter converter;
MyFunc(converter,converter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment