How can one incorporate a using
statement into a constructor initialization list?
For example, rather than
foo::foo(int a, int b, int c) : a(a), b(b), c(something_long::tada(c)) {}
I would like to have
// Invoking some 'using something_long::tada;' magic
foo::foo(int a, int b, int c) : a(a), b(b), c(tada(c)) {}
Presumably this looks something like the goofy try/catch syntax required in this code region. Functionally, permiting using statements feels important as something_long::tada(c)
and using something_long::tada; tada(c)
can have different behavior per Koenig lookup.
Would a namespace alias help?
using SVLI = something::very::long::indeed;
foo::foo(int a, int b, int c) : a(a), b(b), c(SVLI::tada(c)) {}
It depends on how many levels of namespaces you need to type. If you need to type quite a few levels of namespaces, you could bridge it in a static function:
class foo
{
//...
static int tada_again(int c)
{
return namespaceA::namespaceB::namespaceC::namespaceD::namespaceE::tada(c);
}
//...
};
foo::foo(int a, int b, int c) : a(a), b(b), c(tada_again(c))
{
}
If there aren't many levels of namespaces need to be typed, from maintain or code readability point of view, keep clear namespace will be better.
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