1

セマンティクスとパフォーマンスに関するいくつかの質問:

x = 0;
While (x < 10) {
  std::cout << "Some text here to send to cout";
  ++x;
}

gcc 4.7 を使用しています。ストリーミングするテキストを std::move 内にラップする必要がありますか?

このような:

   x = 0;
    While (x < 10) {
      std::cout << std::move("Some text here to send to cout");
      ++x;
    }

そして、私が尋ねている間、このような場合、文字列を次のように静的にする方が良いですか:

x = 0;
While (x < 10) {
  static const char* s = "Some text here to send to cout";
  std::cout << s;
  ++x;
}
4

2 に答える 2

3

Moving a string literal won't really do you much good: It will yield a pointer in any case and this pointer will be passed by value. With respect to making the string literal static, I would expect that it make no difference at all.

于 2012-10-02T22:04:46.123 に答える
1

いいえ、いいえ。operator<<引数が右辺値か左辺値かに違いはありませんconst char *。後者の場合、標準の左辺値から右辺値 (純粋概念) への変換が、 に渡される前に自動的に適用されoperator<<ます。

于 2012-10-02T22:06:34.553 に答える