相关疑难解决方法(0)

根据经验确定C++ 11表达式的值类别?

C++ 11中的每个表达式都有一个值类别.lvalue,xvalue或prvalue之一.

有没有办法编写一个宏,给定任何表达式作为参数,将产生一个字符串"lvalue","xvalue"或"prvalue"酌情?

例如:

int main()
{
    int x;

    cout << VALUE_CAT(x) << endl; // prints lvalue
    cout << VALUE_CAT(move(x)) << endl; // prints xvalue
    cout << VALUE_CAT(42) << endl; // prints prvalue
}
Run Code Online (Sandbox Code Playgroud)

怎么可以VALUE_CAT实现?

c++ c++11

25
推荐指数
1
解决办法
1007
查看次数

什么是ref-qualifier`const &&`的用法?

在上一个问题之后,我一直在研究ref-qualifiers.

给出下面的代码示例;

#include <iostream>
#include <string>
#include <utility>

struct A {
  std::string abc = "abc";
  std::string& get() & {
    std::cout << "get() &" << std::endl;
    return abc;
  }
  std::string get() && {
    std::cout << "get() &&" << std::endl;
    return std::move(abc);
  }
  std::string const& get() const & {
    std::cout << "get() const &" << std::endl;
    return abc;
  }
  std::string get() const && {
    std::cout << "get() const &&" << std::endl;
    return abc;
  }
};

int main()
{
  A a1;
  a1.get();
  const …
Run Code Online (Sandbox Code Playgroud)

c++ rvalue-reference language-lawyer move-semantics c++11

22
推荐指数
3
解决办法
4824
查看次数