Is there any difference in a use between defining the tag type as an anonymous empty struct or as an empty struct?
using A = struct {};
struct B {};
At my mind the only difference is the "effective" type name, when one utilize a kind of reflection (i.e. __PRETTY_FUNCTION__
, <cxxabi.h>:abi::__cxa_demangle(typeid().name())
etc).
ADL work for both ways:
namespace ns
{
using A = struct {};
struct B {};
constexpr
bool
adl(A)
{
return true;
}
constexpr
bool
adl(B)
{
return true;
}
}
template< typename type >
constexpr
bool
adl(type)
{
return false;
}
static_assert(adl(ns::A{}));
static_assert(adl(ns::B{}));
Apart from the different strings you've already noted, the only significant difference is that you can refer to B
using an elaborated-type-specifier, so you can say struct B b;
instead of B b;
but you cannot use struct A a;
because A
is a typedef-name not a class-name.
However there is almost never a good reason to say struct B
instead of just B
so in practice the difference is not important, especially not for tag types.
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