I am currently implementing some utility functions for implementing some libraries I am working on. I was forced to choose between segmenting the functions as static members as part of a class definition within a more general namespace, or enter more specific namespace and then define the functions. I choose the former feeling as it was more flexible in the way those utility classes may be drawn into scope (using or inheritance) though I was unsure whether there was any overhead associated with this design choice or not:
Is
namespace Utilities {
struct CharUtil {
static void foo();
}
}
Utilities::CharUtil::foo();
slower than
namespace Utilities {
namespace CharUtil {
void foo();
}
}
Utilities::CharUtil::foo();
?
Is the former faster using inheritance?
There is no difference at all between the two cases, except for functions’ mangled names. Static functions do not have
thispointer as hidden argument. The compiler generated code for both functions will be the same.