operators

Scala Implicit convertions: 2 way to invoke

@lucastex posted about the Java Elvis operator, and I tried something in Scala to get the same effect. I've just converted everything to a new Structural Type with the ?: operator taking an object of the same type as argument. So Say: implicit def toRockStar[B](v : B) = new { def ?:(opt: => B) = if (v == n...

C# Operators and readability

I was just working on some code and caught myself making this error if (stringName == "firstName" || "lastName") // Do code obviously this is wrong and should be if (stringName == "firstName" || stringName == "lastName") // Do code but it just got me thinking in regards to readability would the first be easier? Maybe havin...

Java: Operations with Colors (add, subtract)? - Colors in a constant class

I'm working with java.awt.Color instances. Is there any way to do arithmetic operations on colors? Something like rgb(20, 20, 20) + rgb(10, 200, 170) = rgb(30, 220, 190)? What I'm trying to do: I have a gui that features a table, where if the user clicks on a cell, the other cells change color based on their relationship to the selected...

How can I pass an arithmetic operator to a template?

I want to somehow merge templates like these into one: template <class Result, class T1, class T2> class StupidAdd { public: T1 _a; T2 _b; StupidAdd(T1 a, T2 b):_a(a),_b(b) {} Result operator()() { return _a+_b; } }; template <class Result, class T1, class T2> class StupidSub { public: T1 _a; T2 _b; StupidSub(T1 a, ...

printing using one '\n'

I am pretty sure all of you are familiar with the concept of the Big4, and I have several stuffs to do print in each of the constructor, assignment, destructor, and copy constructor. The restriction is this: I CAN'T use more than one newline (e.g., ƒn or std::endl) in any method I can have a method called print, so I am guessing print...

What is the >>>= operator in Javascript?

What does the following Javascript statement do to a? a >>>= b; ...

What is the difference between "is" and "==" in python?

Possible Duplicate: Python == vs is comparing strings, is fails sometimes, why? Is a == b the same as a is b ? If not, what is the difference? Edit: Why does a = 1 a is 1 return True, but a = 100.5 a is 100.5 return False? ...

Can I replace the binding operator with the smart match operator in Perl?

How can I write this with the smart match operator (~~)? use 5.010; my $string = '12 23 34 45 5464 46'; while ( $string =~ /(\d\d)\s/g ) { say $1; } ...

Should I Overload == Operator?

How does the == operator really function in C#? If it used to compare objects of class A, will it try to match all of A's properties, or will it look for pointers to the same memory location (or maybe something else)? Let's create a hypothetical example. I'm writing an application that utilizes the Twitter API, and it has a Tweet class,...

What is the name of this operator: "-->"?

After reading this post on comp.lang.c++.moderated, I was completely surprised that it compiled and worked in both VS 2008 and G++ 4.4. The code: #include <stdio.h> int main() { int x = 10; while( x --> 0 ) // x goes to 0 { printf("%d ", x); } } Where in the standard is this defined, and where did it come ...

Vectorising operators in C#

I spend much of my time programming in R or MATLAB. These languages are typically used for manipulating arrays and matrices, and consequently, they have vectorised operators for addition, equality, etc. For example, in MATLAB, adding two arrays [1.2 3.4 5.6] + [9.87 6.54 3.21] returns an array of the same size ans = 11.07 ...

The <<- operator on Ruby, where is it documented?

Hi, I recently used the <<- operator to output a multi-line string, this way... <<-form <h1>Name to say hi!</h1> <form method="post"> <input type="text" name="name"> <input type="submit" value="send"> </form> form But I stole the <<- operator from some Open Source code, but I didn't find any documentation on it. I kinda...

Overriding instance variable array's operators in Ruby

Sorry for the poor title, I don't really know what to call this. I have something like this in Ruby: class Test def initialize @my_array = [] end attr_accessor :my_array end test = Test.new test.my_array << "Hello, World!" For the @my_array instance variable, I want to override the << operator so that I can first process wh...

Does delphi have some "fast" operators ? (+=, -=, ...)

Hello, Very simple question but I couldn't find an answer on google In delphi, is there a way to shorten this kind of code: MyVar := MyVar + X; Like in C++ I would do MyVar += X;. Given how trivial and useful it is there must be way, but I can't find any option for that anywhere ... Thanks for any help ...

C++ operator[] syntax.

Just a quick syntax question. I'm writing a map class (for school). If I define the following operator overload: template<typename Key, typename Val> class Map {... Val* operator[](Key k); What happens when a user writes: Map<int,int> myMap; map[10] = 3; Doing something like that will only overwrite a temporary copy of the [null]...

Comparison of conditional statements.

Are following ways are same.(Considering the evaluation time) if(Condition1) { //code1 } else { //code2 } condition1 ? code1 : code2 Are they just syntactically different? It may seem a stupid question.But I want to clear my doubt. ...

using LIKE with logical operators

i can't seem to figure out how to combine LIKE with an OR or AND: DELETE * FROM persons WHERE FirstName = 'Abe' AND LastName LIKE '%coln'; Looks like it should owrk to me but I get error 1064 (syntax0 Is there a correct way to do this? ...

What does ** operator do in Python?

What does this mean in python: sock.recvfrom(2**16) I know what sock is and I get the jest of recvfrom function, but what the hell is 2**16? ...

Overloading operator>> to a char buffer in C++ - can I tell the stream length?

I'm on a custom C++ crash course. I've known the basics for many years, but I'm currently trying to refresh my memory and learn more. To that end, as my second task (after writing a stack class based on linked lists), I'm writing my own string class. It's gone pretty smoothly until now; I want to overload operator>> that I can do stuff ...

Which are the pdf operators needed to do a search feature in a PDF in iphone sdk?

I have a been trying to do a search feature in a PDF application. I read the Quartz 2d guide in iphone reference library. And so much has been said about the "pdf operators". It's by using them that everything is done, by using call-backs for them. For info about pdf operators, we should read pdf reference of adobe. But it's very vast. ...