C ++ limits semantics

I am updating critical libraries to use restrictions, as implemented in C ++ 11 g ++ and MSVC with the keyword __restrict. This is apparently the most standard extension, so I will use restrictit __restrictinterchangeably.

restrict is the C99 keyword, but nonetheless, compilers have identified important uses for it in C ++.

This post intends to be a “question” asking about what C ++ is a specific use and what it means, and then the CW answer, answering it. Feel free to add / check / edit. So: "Help! What do these C ++ mean for the keyword restrict?"

  • Qualification this(method limitation):

    void Foo::method(int*__restrict a) __restrict { /*...*/ }
    
  • Limit the link:

    int&__restrict x = /*...*/;
    
  • Limit inside the template:

    std::vector<float*__restrict> x;
    
  • /. C struct, ++ , C:

    class Foo final { public: int*__restrict field; };
    
+3
1
  • this ( ):

    , this . :

    • , :

      void Foo::method(Foo*__restrict other) __restrict { /*...*/ }
      

      this other. restrict , .

    • : . , :

      void Foo::method1(void) __restrict { field=6; }
      void Foo::method2(void) __restrict { this->field=6; }
      

      this .

  • :

    , , . , , , . - , , . , , " " .

  • . , f , a.field b.field :

    class Foo final {
        int*__restrict field;
    };
    int f(Foo a, Foo b) { /*...*/ }
    

    , a!=b - , / Foo. : , , restrict ( ).

+2

Source: https://habr.com/ru/post/1659180/


All Articles