If I have a class Foo in namespace bar:
namespace bar
{
class Foo { ... }
};
I can then:
using Baz = bar::Foo;
and now it is just like I defined the class in my namespace with the name Baz.
Is it possible to do the same for functions?
namespace bar
{
void f();
}
And then:
using g = bar::f; // error: ‘f’ in namespace ‘bar’ does not name a type
What is the cleanest way to do this?
The solution should also hold for template functions.
Definition: If some entity B is an alias of A, than if any or all usages (not declarations or definitions of course) of A are replaced by B in the source code than the (stripped) generated code remains the same. For example typedef A B
is an alias. #define B A
is an alias (at least). T& B = A
is not an alias, B can effectively implemented as an indirect pointer, wheres an "unaliased" A can use "immediate semantics".
inline
does not force inlining, only suggests. Even if you force inlining through compiler specifics, the compiler might generate a non-inline version of the wrapper (gcc does, even when not used --i.e. the address is not taken-- in code) – Willardwillcoxusing g = bar::f;
.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0945r0.html (wg21.link/p0945r0) – Elmerelmina