assignment-operator

What's the difference between `=` and `<-` in R? [duplicate]

▼魔方 西西 提交于 2019-11-27 10:25:11
Possible Duplicate: Assignment operators in R: '=' and '<-' I'm using R 2.8.1 and it is possible to use both = and <- as variable assignment operators. What's the difference between them? Which one should I use? From here : The operators <- and = assign into the environment in which they are evaluated. The operator <- can be used anywhere, whereas the operator = is only allowed at the top level (e.g., in the complete expression typed at the command prompt) or as one of the subexpressions in a braced list of expressions. Reading from "Introducing Monte Carlo Methods with R", by Robert and

Why doesn't Java have compound assignment versions of the conditional-and and conditional-or operators? (&&=, ||=)

孤街浪徒 提交于 2019-11-27 08:08:46
问题 So for binary operators on booleans, Java has & , | , ^ , && and || . Let's summarize what they do briefly here: JLS 15.22.2 Boolean Logical Operators &, ^, and | JLS 15.23 Conditional-And Operator && JLS 15.24 Conditional-Or Operator || For & , the result value is true if both operand values are true ; otherwise, the result is false . For | , the result value is false if both operand values are false ; otherwise, the result is true . For ^ , the result value is true if the operand values are

Does it improve safety to mark assignment operators as lvalue-only?

佐手、 提交于 2019-11-27 06:44:14
问题 If T is a class type with the default signature for assignment operator, then we can write: T const &ref = ( T{} = something ); which creates a dangling reference. However, with the signature: T &operator=(T t) & the above code with dangling reference will fail to compile. This would prevent some situations where we return an lvalue that designates a temporary object -- undesirable situations because they can lead to dangling references. Is there any reason not to do this; would we be

PHP's =& operator

谁说胖子不能爱 提交于 2019-11-27 05:33:38
问题 Are both these PHP statements doing the same thing?: $o =& $thing; $o = &$thing; 回答1: Yes, they are both the exact same thing. They just take the reference of the object and reference it within the variable $o . Please note, thing should be variables. 回答2: They're not the same thing, syntactically speaking. The operator is the atomic =& and this actually matters. For instance you can't use the =& operator in a ternary expression. Neither of the following are valid syntax: $f = isset($field[0]

Explicit copy constructor

痞子三分冷 提交于 2019-11-27 05:16:35
I have extended std::string to fulfil my needs of having to write custom function build into string class called CustomString I have defined constructors: class CustomString : public std::string { public: explicit CustomString(void); explicit CustomString(const std::string& str); explicit CustomString(const CustomString& customString); //assignment operator CustomString& operator=(const CustomString& customString); ... }; In the third constructor (copy constructor) and assignment operator, whose definition is: CustomString::CustomString(const CustomString& customString): std::string(static

Placement new and assignment of class with const member

Deadly 提交于 2019-11-27 04:33:32
Why is that undefined behaviour? struct s { const int id; // <-- const member s(int id): id(id) {} s& operator =(const s& m) { return *new(this) s(m); // <-- undefined behavior? } }; (Quote from the standard would be nice). This question arose from this answer . There is nothing that makes the shown code snippet inherently UB. However, it is almost certain UB will follow immediately under any normal usage. From [basic.life]/8 (emphasis mine) If, after the lifetime of an object has ended and before the storage which the object occupied is reused or released, a new object is created at the

Overloading assignment operator in C++

。_饼干妹妹 提交于 2019-11-27 04:25:25
As I've understand, when overloading operator=, the return value should should be a non-const reference. A& A::operator=( const A& ) { // check for self-assignment, do assignment return *this; } It is non-const to allow non-const member functions to be called in cases like: ( a = b ).f(); But why should it return a reference? In what instance will it give a problem if the return value is not declared a reference, let's say return by value? It's assumed that copy constructor is implemented correctly. Not returning a reference is a waste of resources and a yields a weird design. Why do you want

What does `let 5 = 10` do? Is it not an assignment operation?

被刻印的时光 ゝ 提交于 2019-11-27 04:23:09
问题 If I say let 5 = 10 , why does 5 + 1 return 6 instead of 11 ? 回答1: When you say let 5 = 10 it's not a redefinition of 5, it's a pattern matching, the same which occurs when you say foo 5 = undefined ... foo 10 ... The pattern simply fails if it's ever matched. In let-expressions the match is lazy. This means the match is only being done when a variable bound by it is evaluated. This allows us to write things like let foo = undefined in 10 In your expression, no variable is bound, so the

Value returned by the assignment

筅森魡賤 提交于 2019-11-27 03:55:47
Why does the regular assignment statement (say, x = 5 ) return the value assigned ( 5 in this case), while the assignment combined with a variable declaration ( var x = 5 ) returns undefined ? I got the return values by executing these statements in the Chrome browser's Javascript console: > var x = 5; undefined > y = 5; 5 That's the way the language was designed. It is consistent with most languages. Having a variable declaration return anything other than undefined is meaningless, because you can't ever use the var keyword in an expression context. Having assignment be an expression not a

What's the use of the private copy constructor in c++

北战南征 提交于 2019-11-27 03:30:42
Why do people define a private copy constructor? When is making the copy constructor and the assignment operator private a good design? If there are no members in the class which are pointers or handles to a unique object (like file name), then wat other cases are there where private copy constructor is a good idea? Same question apply for assignment operator. Given that majority of C++ revolves around copying of objects and passing by reference, are there any good designs which involve private copy constructor? Some objects represent particular entities that can't or shouldn't be copied. For