ICode9

精准搜索请尝试: 精确搜索
  • C++ beginner(2)- variable2022-08-17 00:34:52

    initialization int x{}; // x is filled with zeroes, so x == 0 int x{123}; int x(123); int a, b = 123, c{}, d{456}, e(789); int* x, y, z; == int* x; int y; int z; int *x, y, *z Reference C++ has two kinds of references: “lvalue” and “rvalue.” Just like wi

  • c++: rvalue, prvalue, lvalue, glvalue2021-11-14 09:04:40

    历史习惯问题,叫左值,可以放在等号左边的对象和函数。例如,如果E是一个指针类型的表达式,*E就是一个左值表达式,可以指向E指向的对象或函数。 — An lvalue (so called, historically, because lvalues could appear on the left-hand side of an assignment expression) designat

  • C++中左值与右值2021-09-02 02:01:26

    1.一个简单定义 lvalue代表一个在内存中占有确定位置的对象(换句话说就是有一个地址),可以把左值当成有名字的对象,所有的变量,包括常变量,都是左值。。rvalue通过排他性来定义,每个表达式不是lvalue就是rvalue。因此从上面的lvalue的定义,rvalue是在不在内存中占有确定位置的表达式。 我

  • rvalue reference2021-06-14 18:01:27

    template<class T> void swap(T& a, T& b) // "perfect swap" (almost) { T tmp {static_cast<T&&>(a)}; // the initialization may write to a a = static_cast<T&&>(b); // the assignment may write to b b = static

  • Lvalues and Rvalues2021-06-14 17:34:28

    To complement the notion of an lvalue, we have the notion of an rvalue. Roughly, rvalue means ‘‘a value that is not an lvalue,’’ such as a temporary value (e.g., the value returned by a function). If you need to be more technical (say, because you want

  • C++ 中 lvalue (左值) 和 rvalue (右值) 的区分2021-02-09 03:01:10

    Reference from : <The C++ Programming Language> Chapter 6   Section 4.1   Page  166    "Roughly, rvalue means  "a value that is not an lvalue", such as a temporary value (e.g., the value returned by a function)."       A more

  • Google KickStart 2020 Round G, Combination Lock,二分2020-12-22 13:03:49

    题目链接 题意: 给 N N N个数,每个数的范围为 [ 1 , W

  • 右值和move 与 forward2020-11-15 18:04:50

    一、左值右值的总结   再次来写左值右值相关的东西我的内心是十分惴惴不安的,一来这些相关的概念十分不好理解,二来网上相关的文章实在太多了,多少人一看这类题目便大摇其头,三来也怕说不清反而误导了别人,反复纠缠这些似乎无关大雅的语言细节实在也有成为 language lawyer 之嫌。但

  • js验证日期是否正确2020-03-20 14:04:28

      /** * 验证日期是否正确 * 日期格式:yyyy-mm-dd,yyyy-m-d,yyyy/mm/dd,yyyy/m/d */function checkDate(dateStr) { dateStr = dateStr.replace(/\//g, '-'); var dateReg = /^(\d{4})-(\d{1,2})-(\d{1,2})$/; var rValue = dateStr.match(dateReg); if (rValu

  • c-具有已选择具有非const ref的复制构造函数的参数类型的函数?2019-10-11 06:06:56

    前段时间,当我想编写is_callable< F,Args ...>时,我对某些代码的以下行为感到困惑.特征.重载解析不会调用非const ref接受参数的函数,对吗?为什么在下面它不拒绝,因为构造函数想要一个Test&amp ;?我希望它取f(int)! struct Test { Test() { } // I want Test not be copyable fr

  • c – 与std :: minmax和rvalues的结构化绑定2019-10-05 14:15:48

    当使用std :: minmax和结构化绑定时,我遇到了一个相当微妙的错误.似乎传递的rvalues并不总是像人们期望的那样被复制.最初我在自定义容器上使用了T运算符[]()const,但它似乎与文字整数相同. #include <algorithm> #include <cstdio> #include <tuple> int main() { auto [ami

  • c – 当你使用std :: move返回时,“return-by-rvalue-ref”和“return-by-value”之间的区别?2019-10-01 08:06:08

    考虑以下代码: #include <iostream> using namespace std; struct I { I(I&& rv) { cout << "I::mvcotr" << endl; } }; struct C { I i; I&& foo() { return move(i) }; } }; int main() { C c; I i = c.

  • c – 为什么std :: move采用前向引用?2019-10-01 03:06:22

    std :: move的实现基本上如下所示: template<typename T> typename std::remove_reference<T>::type&& move(T&& t) { return static_cast<typename std::remove_reference<T>::type&&>(t); } 请注意,std :: move的参数是通用引用(也称为转发引用,但

  • c – 隐式生成的赋值运算符是否应该是&ref-qualified?2019-09-27 07:04:41

    以下代码在gcc 4.8.1上编译没有问题: #include <utility> struct foo { }; int main() { foo bar; foo() = bar; foo() = std::move( bar ); } 似乎隐含生成的foo赋值运算符不是& ref-qualified,因此可以在rvalues上调用.根据标准,这是正确的吗?如果是这样,有什么理

  • 在C中,哪些类别(左值,右值,x值等)可以产生类型临时类型的表达式?2019-09-17 11:05:00

    这是一些示例代码: #include <iostream> class Foo { public: explicit Foo(int x) : data(x) {}; Foo& operator++() { data += 1; return *this; } void *get_addr() { return (void*)this; } friend Foo operator + (const Foo& lh

  • c – 为什么std :: shuffle采用右值引用?2019-09-10 19:07:39

    Since C++11,std :: shuffle()对随机位生成器采用右值引用: template<class RandomIt, class URBG> void shuffle(RandomIt first, RandomIt last, URBG&& g); 所以我可以这么称呼它: std::vector<int> v = {...}; std::random_device rd; std::mt19937 g(rd()); std::shuffle

  • c – 通过右值容器迭代2019-08-31 04:06:38

    以下代码是否导致未定义的行为? std::map<int, vector<int>> foo() { return ... } BOOST_FOREACH(const int& i, foo()[42]) { std::cout << i << std::endl; } 如果未定义,修复它的好方法是什么?如果我使用c 11 range-for循环而不是BOOST_FOREACH怎么办?解决方法:不幸的是,这很可

  • c – 通过引用传递复杂的真实和图像2019-08-29 22:04:52

    问题:C 11对复数进行了一些更改,因此不再像成员变量那样使用和滥用real()和imag(). 我有一些代码,我正在转换,通过引用将real()和imag()传递给sincosf().看起来有点像这样: sincosf(/*...*/, &cplx.real(), &cplx.imag()); 这现在给出了一个错误:左值作为一元’&’操作数 在第11节之

  • c – 与r值和l值混淆2019-08-29 21:06:13

    我最近在C 11的白皮书上读过,如果我写的, void foo(X&) 这将被称为l值而不是r值 如果我写, void foo(const X&) 这将被调用r值和l值. 有人能给我一个例子,这意味着什么?解决方法:此函数接受左值引用 void foo(X&) 并试图用右值调用它会产生错误. 此函数需要一个const左值引用 voi

  • c – 获取右值的地址2019-08-26 13:07:16

    class MyClass { public: MyClass(int a) : a(a) { } int a; }; #include <iostream> void print(MyClass* a) { std::cout << a->a << std::endl; } int main() { print(&static_cast<MyClass&&>(MyClass(1337)));

  • c – 按值返回指针不会移动对象2019-08-26 02:05:51

    我用vs2011编译了这段代码.它打印第一个构造函数然后复制构造函数. 但是如果我改变函数返回a而不是ap,它将移动对象.这是一个错误还是为什么它会像这样? * ap不是rvalue吗? struct A { A() { cout << "constructor" << endl;} A(const A&) { cout << "copy constructor " << end

  • c – vector :: push_back和std :: move [复制]2019-08-25 08:07:37

    参见英文答案 > What does auto&& tell us?                                    4个 我尝试了以下代码: #include <iostream> struct test{ test(){} test(test const &){ std::cout<<__LINE__<<"\n"; } test(test&

  • 将r值绑定到l值引用是非标准Microsoft C扩展2019-08-24 19:07:49

    我最近一直在做一个项目,我决定将ReSharper C安装到Visual Studio.当它分析我的代码时,它会吐出一堆新的警告(显然我的编码习惯很糟糕……).其中一个花了我一段时间才弄明白的是绑定r值到l值引用是非标准的Microsoft C扩展.我用以下代码重新创建了警告: Type foo(Type t1, Type t2)

  • c – 现在非临时工作的非常规参考?2019-08-24 14:06:56

    随着移动语义的引入,您是否只能将临时工具绑定到const引用更改?非const似乎也延长了寿命. A getA() { return A();} A & aref = getA(); //OK string & str = string("h") + string("i"); //OK again 这是使用msvc,A的析构函数在主退出之前不会被调用.解决方法:不,规则是相

  • c – 如何使用在函数中本地创建的对象而不将其复制到内存中?2019-08-24 04:05:53

    例如,我有一个类在其consturctor中调用一个返回本地对象的函数.我正在尝试使用rvalue引用来访问此对象,以避免在内存中进行昂贵的移动. class MyClass { BigObject&& C; MyClass() : C(f()) { }; }; BigObject f() { ret

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有