operators

Bitwise OR of constants

While reading some documentation here, I came across this: unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; NSDateComponents *comps = [gregorian components:unitFlags fromDate:date]; I have no idea how this works. I read up on the bitwise operators in C, but I do not understand how you can fit three (...

What is the difference between += and =+?

What is the difference between += and =+? Specifically, in java, but in general also. ...

How do boost operators work?

boost::operators automatically defines operators like + based on manual implementations like += which is very useful. To generate those operators for T, one inherits from boost::operators<T> as shown by the boost example: class MyInt : boost::operators<MyInt> I am familiar with the CRTP pattern, but I fail to see how it works here. Spe...

PHP compare doubt

if(0 == ('Pictures')) { echo 'true'; } why it's giving me 'true' ? ...

Rails: can't convert ActiveRecord::Associations::BelongsToAssociation into String

This rails project is very bare-bones, just begun, so I haven't done any weird loopholes or patching. The model, to_s replaces school with bar if nil: class Department < ActiveRecord::Base belongs_to :school def to_s "foo" + (school || "bar") end end Says the view: can't convert ActiveRecord::Associations::BelongsToAssocia...

assign operator to variable in python?

Usual method of applying mathematics to variables is a * b Is it able to calculate and manipulate two operands like this? a = input('enter a value') b = input('enter a value') op = raw_input('enter a operand') then how do i connect op and two variables a and b?? i know i can compare op to +, -, %, $ and then assign and compute......

Should my if statement work, is it structured properly?

if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile)) && $_SERVER['REQUEST_URI'] != "login" || "thankyou" || "confirm") Should this code work, operators wise and syntax wise? ...

Other ternary operators besides ternary conditional (?:)

The "ternary operator" expression is now almost equivalent to the ternary conditional operator: condition ? trueExpression : falseExpression; However, "ternary operator" only means that it takes three arguments. I'm just curious, are there any languages with any other built-in ternary operators besides conditional operator and which o...

Simple question about operator ||

HEllo, i try to do that in FlashBuilder (FlexProject) protected function btn_detail_view_clickHandler(event:MouseEvent):void { CurrentState="Statistiques" || "PartMarche"; } But it's not working, i guess this is not the right syntax but what's the right syntax ? Thanks PS: i want to when the state is equ...

Implementing operator< in C++

I have a class with a few numeric fields such as: class Class1 { int a; int b; int c; public: // constructor and so on... bool operator<(const Class1& other) const; }; I need to use objects of this class as a key in an std::map. I therefore implement operator<. What is the simplest implementation of operator< to us...

What is Ruby's double-colon (::) all about?

I'd probably be able to answer this for myself if "::" wasn't so hard to Google. Didn't see anything on SO so thought I'd try my luck. What is this double-colon :: all about? I see it everywhere in Rails: class User < ActiveRecord::Base or… ActionController::Routing::Routes.draw do |map| I found a definition from this guy: Th...

What is operator<< <> in C++?

I have seen this in a few places, and to confirm I wasn't crazy, I looked for other examples. Apparently this can come in other flavors as well, eg operator+ <>. However, nothing I have seen anywhere mentions what it is, so I thought I'd ask. It's not the easiest thing to google operator<< <>( :-) ...

How can I implicitly convert my class to another type ?

For example implicitly MyClass myClass = new MyClass(); int i = myClass; ...

difference between -> and . for member selection operator.

Possible Duplicate: what is the difference between (.) dot operator and (->) arrow in c++ in this book i have I'm learning pointers, and i just got done with the chapter about OOP (spits on ground) anyways its telling me i can use a member selection operator like this ( -> ). it sayd that is is like the "." except points to ob...

while(0=0) evaluates to false

b=10; while(a=b) { b--; if(b==-10)break; } B goes from 10 to -10. In my world, the while-statement, a=b, should always be true (since the assigment always "goes well"). That is not the case. When the loop stops, b will have a value of 0. In my world, it should pass 0 and go all the way to -10, when the if-statement kicks in. Have...

What is the "=~" operator in Ruby?

I saw this on a screencast and couldn't figure out what it was. Reference sheets just pile it in with other operators as a general pattern match operator. ...

Is there an exponent operator in C#?

For example, does an operator exist to handle this? float Result, Number1, Number2; Number1 = 2; Number2 = 2; Result = Number1 (operator) Number2; In the past the ^ operator has served as an exponential operator in other languages, but in C# it is a bit-wise operator. Do I have to write a loop or include another namespace to handle...

Consistency in placing operator functions

I have a class like this: class A { ...private functions, variables, etc... public: ...some public functions and variables... A operator * (double); A operator / (double); A operator * (A); ...and lots of other operators } However, I want to also be able to do stuff like 2 * A instead of only being allowed to ...

Type casting Collections using Conversion Operators

The below code gives me User-defined conversion must convert to or from enclosing type, while snippet #2 doesn't... It seems that a user-defined conversion routine must convert to or from the class that contains the routine. What are my alternatives? Explicit operator as extension method? Anything else? public static explicit oper...

== and === operators in php

Lets say I have a variable that will always be a string. Now take the code below: if($myVar === "teststring") Note $myVar will always be a string, so my questions is Which is quicker/best, using === (Indentity) or the == (Equality)? ...