Function Templates - Explicit specialisation vs Global Functions (C++) -
i know function templates used make functions portable , used data types.
also explicit specialization of templates done if have more efficient implementation specific data type.
but instead of explicit specialization code nontemplate function called main
. save processing time compiler locate nontemplate functions faster explicitly specialized templated functions in turn better in terms of efficiency.
so why use explicit specialization when have alternative of calling nontemplate functions?
please correct me if i'm wrong!
edit 1: told professor whenever make function templates , call function main
,the compiler first looks templated function , if not able locate that,then searches function template in turn makes templated function , calls it.
it sounds you're confusing compile-time efficiency run-time efficiency. choice of function call made @ compile time, not run time, make no difference run time of program.
explicit specialization used when have special case can benefit special treatment. backfires, in case of std::vector<bool>
, while other times it's quite handy. means user of function doesn't need aware there's special case; it's transparent.
Comments
Post a Comment