operator-keyword

Meaning of %o% in R

谁说我不能喝 提交于 2019-11-30 17:41:49
问题 I encountered the following in R: x=x+y%o%c(1.5,1.5) I am wondering what is the meaning of %o% here. I tried googling but didn't have much luck 回答1: There are a number of shortcuts in R that use the %...% notation. %o% is the outer product of arrays > 1:3 %o% 1:3 [,1] [,2] [,3] [1,] 1 2 3 [2,] 2 4 6 [3,] 3 6 9 There are a number of others, my most used is %in% : 3 %in% c(1,2,3,4) #TRUE 5 %in% c(1,2,3,4) #FALSE 3.4 %in% c(1,2,3,4) #FALSE There are a few others, I don't know them all off the

What's “<?=” operator in C++? [duplicate]

Deadly 提交于 2019-11-30 17:05:33
This question already has an answer here: C extension: <? and >? operators 2 answers I came across the following code here , which is from the C++ implementation of Dijkstra algorithm using an adjacency matrix. //read in edges keeping only the minimum for(int i=0; i<E; i++) { int v1,v2,tmp; fin >> v1; fin >> v2; fin >> tmp; adjmat[v1][v2]<?=tmp; // <?= sets left to min(left,right) adjmat[v2][v1]<?=tmp; } Pay attention to the last two lines, which apply operator <?= . As being commented, the following line adjmat[v1][v2]<?=tmp; // <?= sets left to min(left,right) will set left to min(left,right

How to define a static operator<<?

南笙酒味 提交于 2019-11-30 15:26:37
Is it possible to define a static insertion operator which operates on the static members of a class only? Something like: class MyClass { public: static std::string msg; static MyClass& operator<< (const std::string& token) { msg.append(token); return *this; // error, static } }; alternatively: static MyClass& operator<< (MyClass&, const std::string &token) { MyClass::msg.append(token); return ?; } This is how I would like to use it: MyClass << "message1" << "message2"; Thank you! If all the members of MyClass are static, it's possible to return a fresh instance. However, returning a

How to use like in XPath?

人走茶凉 提交于 2019-11-30 14:51:33
问题 I have a page that searches with filters. I have this code for example, xmlTempResultSearch = xmlResidentListDisplay.selectNodes("//PeopleList/Row[@LastName != '"+txtSearch.value+"']"); xmlTempResultSearch.removeAll(); This selects the data that is not equal to the LastName inputted on the txtSearch textbox and then removes them from the result set so that its filtered to equal the last name on the txtSearch textbox. My problem with this code is that it should be equal (=) to the txtSearch

Is it not possible to call C++ operators manually?

廉价感情. 提交于 2019-11-30 11:35:50
I'm trying to understand operators in C++ more carefully. I know that operators in C++ are basically just functions. What I don't get is, what does the function look like? Take for example: int x = 1; int y = 2; int z = x + y; How does the last line translate? Is it: 1. int z = operator+(x,y); or 2. int z = x.operator+(y); ? When I tried both of them, the compiler errors. Am I calling them wrong or are operators in C++ not allowed to be called directly? Using C++ standardese, the function call syntax ( operator+(x, y) or x.operator+(y) ) works only for operator functions : 13.5 Overloaded

How is that x=20;x= ++x + ++x + x++ ;final value of x in java is 65 [duplicate]

半城伤御伤魂 提交于 2019-11-30 09:55:32
问题 This question already has answers here : How do the post increment (i++) and pre increment (++i) operators work in Java? (14 answers) Closed 2 years ago . How is this possible as post increment operator should increase x to 66? When I did the same for y= ++x + ++x + x++; it gave a value 65 for y and 23 for x. So let me know how is java compilers solving these expression. 回答1: Let Java show you. javap -c MyClass shows you bytecode: public static void main(java.lang.String[]); Code: 0: bipush

Speed of Comparison operators

ε祈祈猫儿з 提交于 2019-11-30 09:02:24
问题 In languages such as... well anything, both operators for < and <= (and their opposites) exist. Which would be faster, and how are they interpreted? if (x <= y) { blah; } or if (x < y + 1) { blah; } 回答1: Assuming no compiler optimizations (big assumption), the first will be faster, as <= is implemented by a single jle instruction, where as the latter requires an addition followed by a jl instruction. http://en.wikibooks.org/wiki/X86_Assembly/Control_Flow#Jump_if_Less 回答2: I wouldn't worry

Overloading operator ->

你。 提交于 2019-11-30 08:15:17
Here is my code example: class X { public: void f() {} }; class Y : public X { public: X& operator->() { return *this; } void f() {} }; int main() { Y t; t.operator->().f(); // OK t->f(); // error C2819: type 'X' does not have an overloaded member 'operator ->' // error C2232: '->Y::f' : left operand has 'class' type, use '.' } Why the compiler is trying to "move the responsibility" for operator-> from Y to X? When I implement X::op-> then I cannot return X there - compile error says "infinite recursion" while returning some Z from X::op-> again says that Z doesn't have operator->, thus going

C++ overloading conversion operator for custom type to std::string

怎甘沉沦 提交于 2019-11-30 07:03:10
I hope someone might be able to answer why the following doesn't work. Bear with me though, I am still very much a noob... I just cannot get to the bottom of why the following using namespace std; #include <string> #include <iostream> class testClass { public: operator char* () {return (char*)"hi";}; operator int () {return 77;}; operator std::string () {return "hello";}; }; int main() { char* c; int i; std::string s = "goodday"; testClass t; c = t; i = t; s = t; cout<< "char: " << c << " int: " << i << " string: "<<s<<endl; return 0; } gives me a compile time error: myMain.cpp: In function

Angular 6 pipe RxJs operator to chain 3 dependant observables

不羁的心 提交于 2019-11-30 06:59:15
I have 3 dependent Rest API resources (lets say observables) like this: 1st observable produces one item as array of users, like this: getUsers(): Observable<User[]> [ { "id": 1, "name": "Peter", "surname": "Smith" }, { "id": 2, "name": "John", "surname": "Wayne" }, ... ] 2nd observable can be used to fetch addresses assigned to user, so the input parameter is User ID, and returns a one item as array of addresses: getUserAddresses(user_id: string): Observable<Address[]> [ { "id": 1, "city": "London", "street": "Wicombe 34" }, { "id": 2, "city": "Paris", "street": "La fever 20" }, ... ] 3rd