Bazı kaynak kodlarını okuyarak, bir sonraki özellik tanımını buldum:Özellikleri tanımla. Özellikler blobs ve Metafunctions
namespace dds {
template <typename Topic> struct topic_type_support { };
template <typename Topic> struct topic_data_writer { };
template <typename Topic> struct topic_data_reader { };
template <typename Topic> struct topic_data_seq { };
}
#define REGISTER_TOPIC_TRAITS(TOPIC) \
namespace dds { \
template<> struct topic_type_support<TOPIC> { \
typedef TOPIC##TypeSupport type; }; \
template<> struct topic_data_writer<TOPIC> { \
typedef TOPIC##DataWriter type; }; \
template<> struct topic_data_reader<TOPIC> { \
typedef TOPIC##DataReader type; }; \
template<> struct topic_data_seq<TOPIC> { \
typedef TOPIC##Seq type; }; \
}
Bu bana tuhaf geliyor. Tüm özellikleri benzersiz bir sınıfta şöyle gruplandırırdım:
namespace dds {
template <typename Topic> struct topic_traits { };
}
#define REGISTER_TOPIC_TRAITS(TOPIC) \
namespace dds { \
template<> struct topic_traits<TOPIC> { \
typedef TOPIC##TypeSupport type_support; \
typedef TOPIC##DataWriter data_writter; \
typedef TOPIC##DataReader data_reader; \
typedef TOPIC##Seq seq_type; \
}; \
}
Herhangi biriniz, ikinci yaklaşımın neden ilkinden daha kırılgan olabileceğini ya da yeni özellikler eklemek ne kadar zor olabileceğini anlayabiliyor musunuz?
Meta programlama hakkında daha fazla bilgi için Boost MPL – KitsuneYMG
@Samuel: Traits blob. Aradığım isim bu! Teşekkürler. Abrahams kitabını çoktan sipariş ettim. –