For my problem, I can use the using
directive in two ways. They basically boil down to these options:
template<typename U>
struct A {
private:
// Define our types
using WrapperType = Wrapper<U>;
public:
U *operator()(U *g) const {
// TODO: use WrapperType
}
};
OR:
struct B {
template <typename U>
U *operator()(U *g) const {
// Define the types here instead.
using WrapperType = Wrapper<U>;
// TODO: use WrapperType
}
};
In both cases, there will be other class template parameters. So B
will still have template parameters, even though it doesn't look like it in this simplified example.
My question is:
Is there any overhead of defining a type locally like in B
? (when compared to A
)?
It isn't clear to me how the type declaration affects the generated code. The code must run in real time, and this will be the core of the codebase. So if there is any overhead whatsoever, I cannot use B
.
That being said, B
IS preferable in our case, because I would ideally like to call this code with a variety of types. And yes, this really does need to be in a class. I have just simplified the example extremely.
What Is Overhead? Overhead refers to the ongoing business expenses not directly attributed to creating a product or service. It is important for budgeting purposes but also for determining how much a company must charge for its products or services to make a profit.
Is there any overhead [on the generated code] of defining a type locally like in B?
No there isn't any.
Defining a type alias (what you do with using WrapperType = Wrapper<U>;
) only affects compilation and is completely removed once run-time begins.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With