c++ - Empty struct or anonymous struct as tag -
is there difference in use between defining tag type anonymous empty struct or empty struct?
using = struct {}; struct b {};
at mind difference "effective" type name, when 1 utilize kind of reflection (i.e. __pretty_function__
, <cxxabi.h>:abi::__cxa_demangle(typeid().name())
etc).
adl work both ways:
namespace ns { using = 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 different strings you've noted, significant difference can refer b
using elaborated-type-specifier, can struct b b;
instead of b b;
cannot use struct a;
because a
typedef-name not class-name.
however there never reason struct b
instead of b
in practice difference not important, not tag types.
Comments
Post a Comment