![](/img/trans.png)
[英]Strong typedef for primitive types (BOOST_STRONG_TYPEDEF is not cutting it)
[英]Print boost strong typedef'ed type in gdb
我在代碼中使用了BOOST_STRONG_TYPEDEF
來基於std::string
分隔不同類型的標識符(例如,這樣我就可以擁有SERVER_ID
和FILE_ID
,並且當函數需要一個ID時不要意外地傳遞服務器的ID。文件)。
我現在正在調試我的代碼,並在遍歷一組此類型定義的對象時,打印當前元素將很有用。 不幸的是,boost的模板化性質使輸出非常難以閱讀:
(gdb)p服務器
$ 11 =(const mpn :: SER_ID&)@ 0x756660:{,std :: allocator>,boost :: detail :: empty_base> >> = {,std :: allocator>,boost :: detail :: empty_base>>> > = {,std :: allocator>,boost :: detail :: empty_base> >> = {,std :: allocator>,boost :: detail :: empty_base >> = {,std :: allocator>,boost :: equal_comparable2,std :: allocator>,boost :: detail :: empty_base> >> = {,std :: allocator>,boost :: detail :: empty_base >> = {> = {},},},},} ,},},t =“ B” ...}
是否可以通過某種方式將對象轉換為字符串(C ++允許使用static_cast
)並將其正常打印?
事實證明, BOOST_STRONG_TYPEDEF
包含基礎對象作為typedef的屬性t
:
(gdb) p server.t
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.