I don't see the difference between these two, could someone tell me if there are differences?
template <typename Arg1>
void templatedFuncAlsoTakingAutoArg(Arg1 arg1, auto arg2)
{
// Both types are known at compile time for constexpr
static constexpr decltype(arg1) variable1 = decltype(arg1)();
static constexpr decltype(arg2) variable2 = decltype(arg2)();
// And both types work with constexpr if so that invalid code
// can appear within constexpr statements
// If I pass in a double for arg1 or arg2 this still compiles
if constexpr (std::is_integral_v<decltype(arg1)>)
{
arg1.non_existent_member = 7;
}
if constexpr (std::is_integral_v<decltype(arg1)>)
{
arg2.non_existent_member = 7;
}
}
What I'm wondering is basically if it came down to writing a function what would be the difference if I wrote it like this:
template <typename Arg>
void likeThis(Arg arg){}
or:
void orLikeThis(auto arg) {}
In the template version you have the advantage of being able to refer to the type directly, but in the 'auto' version you can always get the type with decltype anyway, right? So what are the differences? Under the hood is the version that takes auto actually a template anyway, and is instantiated in the same way the compiler does templates?