`
febird
  • 浏览: 256637 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

is_trivially_destructible replaced has_trivial_destructor

 
阅读更多

C++11 中的 type_traits, 改变了一些约定成俗的名字:

我们经常使用的 has_trivial_destructor, 变成了is_trivially_destructible, 现在已有不少编译器实现了 has_trivial_destructor, (std, std::tr1). 如此, 要写可移植的代码, 要么使用 tr1, 要么使用 boost, 鉴于 tr1 出现的比 boost 更晚, boost 一般是首选, 而新的编译器往往自带了 tr1, 而 boost 要另外安装.........

We think in general, but we live in details. 一个简单的 type_traits, 也需要这么多折腾.

以下是标准关于 type_traits 更新的详细列表


Summary of renamed traits General form Nothrow form Trivial form Construction Destruction Assignment
is_constructible is_nothrow_constructible
hasis_default_constructibleor hasis_nothrow_default_constructibleor hasis_trivially_default_constructibleor
hasis_copy_constructibleor hasis_nothrow_copy_constructibleor hasis_trivially_copy_constructibleor
hasis_move_constructibleor hasis_nothrow_move_constructibleor hasis_trivially_move_constructibleor
hasis_trivially_destructibleor
hasis_copy_assignable hasis_nothrow_copy_assignable hasis_trivially_copy_assignable
hasis_move_assignable hasis_nothrow_move_assignable hasis_trivially_move_assignable

Furthermore, as noted in GB 92 for the "nothrow" traits, the definitions have become redundant and confusing. This redundancy and confusion actually extends to nearly all of these traits, and in some cases actually leads to incorrect definitions, or at the very least, a lack of self-consistency among the traits. For example, as specified in the current Working Draft:

typedef char Array[3];
is_constructible<Array, const Array&>::value == false
has_copy_constructor<Array, const Array&>::value == true

With our proposed clarifying names, we wish foris_copy_constructible<T>to have the exact same behavior asis_constructible<T, const T&>. So we have adjusted the definitions of theis_*_constructibletraits to be simple synonyms foris_constructibleand similarly for the "nothrow" variants. E.g.:

template <class T> structhas_nothrow_copy_constructoris_nothrow_copy_constructible; has_trivial_copy_constructor<T>::valueistrueoris_nothrow_constructible<U, const U&>::valueistrue, whereUisremove_all_extents<T>::type.
is_nothrow_constructible<T, const T&>::valueistrue.
Tshall be a complete type, (possiblycv-qualified)void, or an array of unknown bound.

This formulation makes it much easier to get the definitions correct. I.e. what it means to be "nothrow constructible" is defined in exactly one place (the definition ofis_nothrow_constructible). The other "nothrow constructible" traits reuse this definition as much as possible, with no repetition.

However we note that we can not currently apply this formula to the "trivially constructible" traits, nor tois_trivially_destructible, nor to any of the assignable traits. The problem is the lack ofis_destructible(FI 18), lack ofis_trivially_constructible, and the lack of generalized assignable traits. We strongly feel that this lack of completeness will inevitably lead to situations where programmers will not be able to query or assert properties of types necessary to the correct operation of their code. For example a container is likely to assert that a contained type have a non-throwing destructor. Lack of this property leads to the container's destructor becoming a source of memory leaks.

Therefore we propose the following 6 new traits to complete the suite of traits:

Summary of traits, new traits shown as insertions General form Nothrow form Trivial form Construction Destruction Assignment
is_constructible is_nothrow_constructible is_trivially_constructible
is_default_constructible is_nothrow_default_constructible is_trivially_default_constructible
is_copy_constructible is_nothrow_copy_constructible is_trivially_copy_constructible
is_move_constructible is_nothrow_move_constructible is_trivially_move_constructible
is_destructible is_nothrow_destructible is_trivially_destructible
is_assignable is_nothrow_assignable is_trivially_assignable
is_copy_assignable is_nothrow_copy_assignable is_trivially_copy_assignable
is_move_assignable is_nothrow_move_assignable is_trivially_move_assignable

We address GB 91 in the definition of the newly introducedis_assignabletrait, usingdeclvalas suggested. All of the rest of the assignable traits reuse this definition without repetition.

In addition we wish to address GB 50 and GB 51 in this paper because the topic is intimately related to the definition of move construction and move assignment and subsequently theis_move_constructibleandis_move_assignabletraits.

The following list shows the current usages of the terms "move-construct" and "move-assign" in the library. While some occurrences are purely descriptive usages of these words, most of them refer to what the type traitsis_move_constructible<T>andis_move_assignable<T>stand for. The list omits to enumerate all usages of these terms within the definition ofpairandtuples, because those will be completely replaced by another paper (N3140).

  1. Table 42, entry:X::propagate_on_container_move_assignment

    true_typeonly if an allocator of typeXshould be moved when the client container is move-assigned.
  2. 20.8.14.2.1/8: "otherwise, move-constructs the target"
  3. 20.9.10.2.1/14: "Thisunique_ptrwill hold a value move constructed fromd."
  4. 20.9.10.2.1/19: "IfDis a reference type, this deleter is copy constructed fromu's deleter; otherwise, this deleter is move constructed fromu's deleter."
  5. 20.9.10.2.1/24: "IfEis a reference type, this deleter is copy constructed fromu's deleter; otherwise, this deleter is move constructed fromu's deleter."
  6. 20.9.11.2.1/24: "Effects:Move-constructs ashared_ptrinstance fromr."
  7. Table 93 — Container requirements, entry "a = rv": "All existing elements of a are either move assigned to or destroyed"
  8. Table 96 — Allocator-aware container requirements (continued), entry "X(rv) X u(rv)": "Requires: move construction ofAshall not exit via an exception."
  9. Table 96 — Allocator-aware container requirements (continued), entry "a = rv":

    All existing elements ofaare either move assigned to or destroyed.
  10. 23.5.2.1/2: "Effects:Initializescompwithxandcwithy(copy constructing or move constructing as appropriate);"
  11. 23.5.2.1/4: "Effects:Initializescompwithxandcwithy(copy constructing or move constructing as appropriate);"
  12. 26.7.4/before p.1: "assigns the result to*(result + (i - first)), and move assigns fromvaltoacc."
  13. 27.7.1.1.1/3: "Effects:Move constructs from the rvaluerhs. This is accomplished by [..]" (Defined)
  14. 27.7.1.5.1/3: "Effects:Move constructs from the rvaluerhsby constructing thebasic_istreambase class withmove(rhs)." (Defined)
  15. 27.7.2.2/5: "Effects:Move constructs from the rvaluerhs. This is accomplished by [..]" (Defined)
  16. 27.8.1.1/4: "Effects:Move constructs from the rvaluerhs. [..]" (Defined)
  17. 27.8.1.2/1: "Effects:After the move assignment [..]" (Descriptive)
  18. 27.8.2.1/3 "Move constructs from the rvaluerhs. This is accomplished by move constructing the base class, and the containedbasic_stringbuf. [..]"
  19. 27.8.3.2/1 "Effects:Move assigns the base and members of*thisfrom the base and corresponding members ofrhs."
  20. 27.8.5/3: "Move constructs from the rvaluerhs. This is accomplished by move constructing the base class, and the containedbasic_stringbuf. [..]"
  21. 27.8.5.1/1: "Effects:Move assigns the base and members of*thisfrom the base and corresponding members ofrhs."
  22. 27.9.1.2/3: "Effects:Move constructs from the rvaluerhs." (Descriptive)
  23. 27.9.1.3/1: "Effects:Callsthis->close()then move assigns fromrhs." (Descriptive)
  24. 27.9.1.7/4: "Effects:Move constructs from the rvaluerhs. This is accomplished by move constructing the base class, and the containedbasic_filebuf. [..]"
  25. 27.9.1.8/1: "Effects:Move assigns the base and members of*thisfrom the base and corresponding members ofrhs." (Descriptive)
  26. 27.9.1.11/4: "Effects:Move constructs from the rvaluerhs. This is accomplished by move constructing the base class, and the containedbasic_filebuf. [..]"
  27. 27.9.1.12/1 "Effects:Move assigns the base and members of*thisfrom the base and corresponding members ofrhs."
  28. 27.9.1.15/4: "Effects:Move constructs from the rvaluerhs. This is accomplished by move constructing the base class, and the containedbasic_filebuf. [..]"
  29. 27.9.1.16/1: "Effects:Move assigns the base and members of*thisfrom the base and corresponding members ofrhs."
  30. 28.8.2/12: "Effects:Move constructs an object of classbasic_regexfrome." (Descriptive)
  31. 28.8.3/9: "Effects:move assigns from that into*thisand returns*this." (Descriptive)
  32. 28.10.1/5: "Effects:Move-constructs an object of classmatch_resultsfrom m satisfying the same postconditions as Table 138." (Descriptive) "Additionally, the storedAllocatorvalue is move constructed fromm.get_allocator()." (Defined meaning)
  33. 28.10.1/8: "Effects:Move-assignsmto*this. The postconditions of this function are indicated in Table 138." (Descriptive)
  34. 30.6.6/7: "Effects:move constructs a future object that refers to the associated asynchronous state that was originally referred to byrhs(if any)." (Descriptive)
  35. 30.6.7/10: "Effects:move constructs ashared_futureobject that refers to the associated asynchronous state that was

分享到:
评论

相关推荐

    Copy Constructors and Assignment Operators终极解释

    在C++编程语言中,复制构造函数(Copy Constructor)和赋值运算符(Assignment Operator)是两个非常关键的概念,特别是在处理对象的拷贝和赋值时。它们默认由编译器提供,但通常需要根据具体需求进行自定义,以确保正确...

    UES.zip_operation

    Until modern times cryptography referred almost exclusively to encryption, which is the process of converting ordinary information (plaintext) into unintelligible gibberish (i.e., ciphertext).[2] ...

    武汉大学计算机学院 陈刚 unix

    NAME tcp —trivially copy a file SYNOPSIS tcp source target DESCRIPTION The tcp utility copies the contents of the source to target. If target is a directory, tcp will copy source into this directory....

    武汉大学unix第一次上机实验作业

    NAME tcp —trivially copy a file SYNOPSIS tcp source target DESCRIPTION The tcp utility copies the contents of the source to target. If target is a directory, tcp will copy source into this directory....

    parallel-hashmap:一系列仅标头,非常快速且对内存友好的hashmap和btree容器

    并行哈希图 概述 该存储库旨在提供一组出色的哈希映射实现,以及std :: map和std :: set的btree替代品,具有以下特征: 仅标头:无需构建,只需将parallel_... 转储/加载功能:当flat哈希映射存储std::trivially_copya

    A library with 2 functions. StripChars() removes any specifi

    A library with 2 functions. StripChars() removes any specified character from any specified string. SplitString() splits a string on one or more individual characters or on an instance of a string ...

    Knockout API 中文版

    Trivially extensible - implement custom behaviors as new declarative bindings for easy reuse in just a few lines of code. 额外的好处: 纯JavaScript类库 – 兼容任何服务器端和客户端技术 Pure ...

    Zmeya是仅标头的C ++ 11二进制序列化库,专为游戏和对性能有严格要求的应用程序而设计-C/C++开发

    Zmeya Zmeya是仅标头的C ++ 11二进制序列化库,...只要使用Zmeya数据结构和其他trivially_copyable,一切都可以正常工作,并且不会产生反序列化费用。 您可以对序列化的文件进行内存映射,然后立即开始使用数据。 那里

    GoogleC++规范

    然而,也有一些例外情况,比如定义在单个文件中的小类(trivially small classes)可以直接放在.cc文件中。头文件主要用于声明,而.cc文件用于实现。这样做的目的是避免循环依赖(circular dependencies)和不必要的...

    一个粒子程序,可以借鉴一下

    effect in an environment, but these effects can trivially be added to any OpenGL program. Compiling the Library for UNIX The sample Makefile compiles both libparticle.a and pspray. If the supplied ...

    TDFS-开源

    _TDFS(Trivially Distributed File System)_ 是一个基于 **FUSE(Filesystem in Userspace)** 的文件系统模块,它的设计目标是实现单写者-多读者模式的数据分发和集群。这种模式允许在分布式环境中高效地管理文件...

Global site tag (gtag.js) - Google Analytics