For libraries with many large and complex template instantiations, it seems to me that one of the major considerations in deciding whether to use concepts would be whether or not the build output is smaller in size.
With SFINAE, my understanding is that the following code will cause the template instantiations std::is_function<bar>
and std::enable_if<true, bool>
to be included in the build output, increasing its size (albeit marginally for this example):
#include <type_traits>
template<typename F,
typename = std::enable_if_t<
std::is_function<F>::value,
bool> = true>
void foo(F& f)
{
// do some stuff with f
}
void g();
int main()
{
foo(g);
return 0;
}
If a C++20 concept based on std::is_function
is used instead, obviously the template will have to be instantiated to check it. But is that instantiation then written to the final build output? And does this differ depending on compiler implementation?
#include <type_traits>
template<typename F>
concept Function = std::is_function<F>::value;
template<Function F>
void foo(F& f)
{
// do some stuff with f
}
//...