Why is the restrict keyword not part of C++?

前端 未结 2 1623
小蘑菇
小蘑菇 2021-01-01 10:35

The title says it all. I am curious why is the restrict keyword not part of C++ ? I don\'t know much about C++, and I\'m still not able to find anything online that would gi

相关标签:
2条回答
  • 2021-01-01 11:12

    There are several issues in defining "restrict" in C++, some of them are listed in WG paper N3635: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3635.pdf "Towards restrict-like semantics for C++"

    Some possible issues with restrict in C++ are:

    • Restrict Class members and indirection with “this pointer”
    • Passing of restrict qualifiers into functions, functors, lambdas, and templates
    • Escaping of restrict pointer values inside functions
    • Overlapping array members, strides

    Document also list several C++ compilers with limited "restrict" support for C++.

    There is also interesting history note in N3635 about non-inclusion of restrict to C++:

    At the time of reviewing C99 feature inclusion in C++ during the Mont Tremblant meeting, restrict was considered but was waiting a paper proposal although none came forward....

    Restrict is a C99 feature and was never designed to work in class abstractions and it may have to do with that pointers are not common in C++. ... it was designed for fine-grain aliasing for C, but not well-designed for type-based aliasing in C++

    0 讨论(0)
  • 2021-01-01 11:13

    Not to detract from osgx's answer, but - there is a somewhat more up-to-date paper, N3998 by Finkel, Tong, Carrouth, Nelson Vandevoode and Wong, from May 2014:

    Towards restrict-like aliasing semantics for C++

    And an ever newer one from 2018:

    [[assert: std::disjoint(A,nA, B,nB)]]: Contract assertions as an alternate spelling of ‘restrict’

    (Thanks @MCCCS for pointing the last one out.)

    0 讨论(0)
提交回复
热议问题