侯捷stl源码剖析注释41 sgi-type-traits.docVIP

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
侯捷stl源码剖析注释41 sgi-type-traits

G++ 2.91.57,cygnus\cygwin-b20\include\g++\type_traits.h 完整列表 /* * * Copyright (c) 1997 * Silicon Graphics Computer Systems, Inc. * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Silicon Graphics makes no * representations about the suitability of this software for any * purpose. It is provided as is without express or implied warranty. */ #ifndef __TYPE_TRAITS_H #define __TYPE_TRAITS_H #ifndef __STL_CONFIG_H #include stl_config.h #endif /* 本檔提供了一個框架(framework),允許針對型別屬性(type attributes),在編譯時期完成函式派送(dispatch)。這對於撰寫 template 很有幫助。例如,當我們準備對一個「元素型別未知」的陣列執行拷貝(copy)動作時,如果我們能事先知道其元素型別是否有一個trivial copy constructor,便能夠幫助我們決定是否可使用快速的 memcpy()。 class template __type_traits 提供許多typedefs,每一個若非 __true_type 就是 __false_type。__type_traits 的引數可以是任何型別。這些typedefs將經由以下管道獲得正確值: 1. 一般具現體(general instantiation),內含對所有型別而言都必定有效的保守值。 2. 經過宣告的特化版本(例如本檔對所有 C++ 內建型別所提供的特化宣告)。 3. 某些編譯器(如Silicon Graphics N32 和 N64 編譯器)會自動為所有型別提供適當的特化版本。 舉例: // 拷貝一個陣列,其元素型別擁有 non-trivial copy constructors。 template class T void copy(T* source,T* destination,int n,__false_type); // 拷貝一個陣列,其元素型別擁有 trivial copy constructors。運用 memcpy() 完成工作。 template class T void copy(T* source,T* destination,int n,__true_type); // 拷貝一個陣列,其元素為任意型別,視情況採用最有效率的拷貝機制。 template class T inline void copy(T* source,T* destination,int n) { copy(source,destination,n, typename __type_traitsT::has_trivial_copy_constructor()); } */ struct __true_type { }; struct __false_type { }; template class type struct __type_traits { typedef __true_type this_dummy_member_must_be_first; /* 不要移除這個成員。它通知「有能力自動將 __type_traits特化」的編譯器說,我們現在所看到的這個 __type_traits template 是特殊的。這是為了確保萬一編譯器也使用一個名為 __type_traits 而其實與此處定義並無任何關聯的template 時

文档评论(0)

sh4125733 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档