FAQ Database Discussion Community


C# ternary operator List operator

c#,list,operator-keyword,ternary-operator
Any knows a quickest Ternary operation for this. label1.Text = Cclass.TestMe() .Where(t => t.GFName == (textBox1.Text == "" ? "GName" : textBox1.Text)) .First() .GFName == null ? "Nothing" : "Super"; I was trying to check if the List is empty return something. So the compiler will not throw a Exception...

Swift, Optional wrappers. “?” “!” I understand how it works. But why is it better than != nil checking

swift,syntax,casting,operator-keyword
I understand how "!" or "?" works. But i'm not quite sure what the added benefit is compared to != nil checking. What is the added benefit of moving to "!?"? I feel like it's just something Apple has added but can't really see the extra benefit compared to status...

What's the difference between “&” in this program

c++,operator-keyword
Below is part of a C++ program: Circle circle1, &circle2 = circle1, *p = &circle2; I'm wondering what is the difference in between the two &s there? Thanks so much....

The operator < is undefined for the argument type

java,types,arguments,undefined,operator-keyword
No hate on my Java programming teacher, but I've had some experience with programming, and for the first project I'd like to wow the teacher. Anyways, I'm new to Java, but have some strong knowledge of C. Just to test out the array system in Java I have designed this...

std vector no match for operator ==

c++,vector,const,operator-keyword
I'm stuck at this error: gcc.compile.c++ Physics/HelicityAmplitude/bin/gcc-4.8.3/debug/HelicityDecayTree.o In file included from /cvmfs/cluster/gcc/gcc-4.8.3/include/c++/4.8.3/algorithm:62:0, from /cluster/compwa_externals/boost_1_55_0/include/boost/move/algorithm.hpp:23, from /cluster/compwa_externals/boost_1_55_0/include/boost/move/move.hpp:24, from /cluster/compwa_externals/boost_1_55_0/include/boost/unordered/detail/util.hpp:19, from...

specialize friend operator in template class previously defined error

c++,templates,operator-keyword,friend
I tried to specialize << operator for char in my template class hpp template<class T> class tablicowy{ public: T * tablica; int rozmiar; public: tablicowy(T arr[], int n){ { tablica = arr; rozmiar = n; } }; friend std::ostream& operator<<(std::ostream& out, tablicowy<char>& that ); friend std::ostream& operator<<(std::ostream& out, tablicowy<T>& that...

Invalid Int “+” happens with any numerical operator

android,string,exception,numbers,operator-keyword
I am taking a crack at Android development and for my first app.. pun intended, I decided to go with a calculator. So my problem is that any arithmetic operator is evaluated as a numeric datatype and crashes the app. I've seen this discussed on other forums but most of...

What does the |= operator do?

php,operator-keyword
I saw this operator |= in another question and I wondered what it does. It looks like this: $result |= (ord($safe[$i % $safeLen]) ^ ord($user[$i])); ...

is it safe to use comparison operators on BigDecimal in groovy/grails?

groovy,comparison,operator-keyword
The Java way to compare two BigDecimals is to use the compareTo() method, and check if the result is -1, 0 or 1. BigDecimal a = new BigDecimal("1.23") BigDecimal b = new BigDecimal("3.45") if (a.compareTo(b) > 0)) { } I have seen that some people are using this format in...

“|=” operator in JS (never seen before)

javascript,operator-keyword
I just encountered the code below. var loadComplete = 0; window.onload = function(){ loadComplete |= 1; }; I've never seen "|=" like operator. Also I have googled about it, but there seems to be no example of it....

Sort using function on attribute found using attrgetter

python,operator-keyword
I'd like to sort a list foo_list using a function foo_function on an attribute foo_attr on each object in the list (same attribute for all objects). I've tried using the code below: sorted(foo_list, key=foo_function(attrgetter('foo_attr'))) However, I get the following error: AttributeError: 'operator.attrgetter' object has no attribute foo_attr Edit: Updated to...

Breakpoint on delete[] when destroying char *

c++,memory,delete,breakpoints,operator-keyword
I'm doing an assignment for class in which i can't use the string class. I need to use char* as arrays and doing arithmetic with them. My code being executed in main is the following: I create 2 myString objects and I add them. Then this is done correctly. Both...

What is the difference when concatenating a String as a variable with a Character vs concatenating with an other String?

java,string,performance,operator-keyword
When i see something (pseudo 1-liner) like this: str1 + "a" + str2 Is it much worse (or better/equal) than the following (pseudo 1-liner)? str1 + 'a' + str2 Update: Better example (by @QPaysTaxes) to reduce confusion regarding my original example. What i tried: Various stuff for the past 10...

implementing addition operator for std::vector with type checking

c++,overloading,operator-keyword,stdvector
This is my implementation of + operator for std::vector<T>. //+ operator overloading template <typename T> std::vector<T> operator+(std::vector<T> v1, const std::vector<T>& v2) { if(v1.size() != v2.size()) { throw std::exception("Two vector size must be same"); } for(unsigned int i = 0; i<v1.size(); i++) { v1[i] += v2[i]; } return v1; } it...

Advanced logical operations in MongoDB with Java Driver

java,mongodb,operator-keyword
I have a little problem with MongoDB, I'm trying to create a query with multiple operators with the Java driver. I'm looking for something like this : x1 : y1 OR (x2 : y2 AND x3 : y3) At the moment I have this : BasicDBObject andQuery = new BasicDBObject();...

c++ operator overloading library class

c++,overloading,operator-keyword
I have a class from Gtk Library that represents a color(GdkColor)....i have written my own interval tree around it... Basically, it associates different colors to different intervals... Now,in my test case, once i do a query for interval, i want to compare the output with the expected value. typedef struct...

C++, Use [] notation on pointer?

c++,arrays,pointers,operator-keyword
I just noticed I can use [] on a pointer and it works, but I was wondering, if this is good to use it. int a[]={1,2,3,4}; int *p=&a[1]; std::cout << p[0]; // returns 2; std::cout << p[-1]; // returns 1; std::cout << p[1]; // returns 3; I always learned, you...

How to use an operation which is defined in another namespace in c++

c++,namespaces,operator-keyword
I have a definition for an operation in a namespace and I want to use it in another name space, how I can do this: for example, assume that I have this: operation defined: namespace op { inline cv::Matx21f operator/(const cv::Matx21f &v, float a) { return cv::Matx21f(v(0) / a, v(1)...

XSLT remove data if attribute value is higher than threshold

xml,xslt,math,operator-keyword,relational
I am newbie to XSLT. My am is to remove elements from XML based on a field if it is higher than some threshold value which I will be getting as parameter to it. My XML is as shown below: <tns:PM objectClass="MyNode" objectName="" className="com.project.converter.PMFamilyConverter" interfaceName="ComponentPM" xmlns:tns="http://www.myproject/SS/PMSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.myProject.com/SS/PM.xsd"> <tns:family desc="family0"...

Comparison != doesnt work like I expect

python,comparison,control,operator-keyword,flow
I have this: salir = "" while salir != "s" or salir != "S": print("no has salido") salir = input("Digit s to exit or enter to continue) print("saliste") but the operator != doesnt work, but if I put this: salir = "" while not (salir == "s" or salir ==...

Unix - Count line inside two files and sum the value

bash,function,shell,unix,operator-keyword
I want to count how much line within 2 files. I create function to get the value for each file, and sum it. Here is the code : count_sus_pop() { wc -l < ${SCRIPTDIR}/output/${OUTPUTFILE1}_${DATE}.csv } count_waive_pop() { wc -l < ${SCRIPTDIR}/output/${OUTPUTFILE2}_${DATE}.csv } if [$(count_sus_pop)+$(count_waive_pop) -gt 2]; then pop="[POPULATION]" else pop=""...

How properly overload size() method/operator in Matlab

matlab,size,overloading,operator-keyword
I have some class with the property val classdef SomeClass < handle properties val; end methods function sz = size(this,varargin) sz = builtin('size',this.val,varargin{:}); end; end end supposedly it should be the proper way to overload this method to get the proper sizes of object of class SomeClass if it is...

Reading a matrix created using an operator

c++,class,matrix,operator-keyword
Hello stackoverflow community. I need some help with a bit of code (I am a new to C++ so be gentle). I am trying to use operator() to create a matrix, store data from an input file, then write to an output file. The below code has been simplified a...

Why “++” operator over bool is defined?? however “--” is not in C++ [duplicate]

c++,operator-keyword
This question already has an answer here: bool operator ++ and -- 4 answers I was wondering why the ++ operator is defined over bool... however when I tried the --operator, it was not defined for bool.. Can someone please explain me the reason behind that?...

Discarding const qualifier

c++,class,operator-keyword
Why isn't discarding const qualifier allowed? Suppose we wrote: #include <iostream> struct A { void operator=(const A&){ std::cout << "A&" << std::endl; } void operator=(const A&&){ std::cout << "A&&" << std::endl; } }; const A a; A b; int main() { a = b; //Error: discarding qualifier } Couldn't someone...

C++ invalid operator< when using sorting

c++,string,sorting,operator-keyword
bool sortingGame(Player Player1, Player Player2) { if (Player1.gamePercent() > Player2.gamePercent())// first compare precetage (float) { return true; } else if (Player2.gamePercent() > Player1.gamePercent()) { return false; } else if (Player1.getLastName() > Player2.getLastName())//then names (std::string) { return true; } else if (Player2.getLastName() > Player1.getLastName()) { return false; } else if (Player1.getFirstName()...

Why doesn't or operator work in if statement when using “not equals”?

c#,equals,operator-keyword
I am a bit confused by this. I want to hide a button if the current username of the system is != Administrator OR Administrator2, but the only way to get my desired goal is by using the && instead of ||. string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name; if (userName != @"PC\Administrator"...

C++ overload resolution, conversion operators and const

c++,const,overloading,operator-keyword
In this case void f(int *); void f(const int *); ... int i; f(&i); the situation is pretty clear - f(int *) gets called which seems right. However, if I have this (it was done like that by mistake(*) ): class aa { public: operator bool() const; operator char *();...

Can I filter an Android app by the mobile network operator?

android,networking,filter,operator-keyword,carrier
For example, I want to make a specific app so that it only shows up and can be downloaded by users on the Vodafone network.

Meaning of %o% in R

r,operator-keyword
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...

Ternary Operators For Initialisation In Swift

swift,operator-keyword,ternary
From How to customize ternary operators in Swift I know that it's possible to create custom ternary operators using two binary operators, my question is: Is there a way I could use it for initialisation of classes or structs? Say I have a LinearEquation. Everything works fine but initialising an...

Error C2679: binary '<<' : no operator found (vector iterators used)

c++,operator-overloading,operator-keyword,cout,ostream
The full error message reads: Error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::_Vector_iterator< std ::_Vector_val < std::_ Simple _ types < projects > > >' (or there is no acceptable conversion) Not the prettiest but here's my code up to the error,...

Can not define operator on list

c#,list,entity,operator-keyword
I have an error in this section : i need + operator for sum two List... public partial class Question { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public Question() { this.Answers = new HashSet<Answer>(); } public long Question_Code { get; set; } public Nullable<byte> Question_ExamCode { get; set; } public Nullable<byte> Question_LessonCode { get;...

Java && operators

java,string,if-statement,operator-keyword
I'm trying to make simple if statement , I need to see if my two String's values are not empty (does not equal ""). I use && operator , but sadly , it only checks one string properly if it's not empty , and if the second string is empty,...

Pre-increment and post-increment behavior in Java [duplicate]

java,operator-keyword
This question already has an answer here: Is there a difference between x++ and ++x in java? 13 answers Pre & post increment operator behavior in C, C++, Java, & C# 6 answers Can someone explain the implementation of the following code: int j = 1; System.out.println(j-- + (++j...

Operator |= in C++ and its usage

c++,operator-keyword
While i was checking some C++ code i found a rather interesting operator and was wondering what it does? I tried finding it on the Internet but no luck. index |= (image(y - 1, x) != 0) << 3; The right-hand side is clear, it does a left shift by...

C# operator issues [closed]

c#,operator-keyword
Hey guys I've been getting this on some code I've been working on for school. Been googling it for hours but can't find anything, any help would be appreciated. Code: if (dogName = "" || lstDogBreeds.SelectedIndex = -1) Error: Operator '||' cannot be applied to operands of type 'string' and...

Javascript: meaning of || operator while initializing var [duplicate]

javascript,keypress,operator-keyword
This question already has an answer here: What does the construct `x = x || y;` mean? 6 answers to get information about what key was pressed, I now use following code: function AddEventListeners() { document.getElementById('txtHangman').addEventListener('keypress', TextHangman.bind(this), false); } And then the eventhandler function: function TextHangman(_key) { var _keypressed...

Defining an inline operator in a different file than the declaration

c++,operator-keyword,inline-functions
I want to define operators for a class I created, I want the operators to be inline I also want the definition be in the .cpp file while the declaration is in the .h file I tried to do this: Vector3D.h class Vector3D { ... }; inline Vector3D operator+(Vector3D lv,...

Not using operator '?' properly?

c++,return,operator-keyword
So I've got function returning an integer along with some max and min value for it. I wanted to do it with nice and clean one-liner at the end: (freq>max_freq) ? return max_freq : ((freq<min_freq) ? return min_freq : return freq); but what I get is posplot.hh:238:21: error: expected primary-expression...

C++ stream extraction operator overloading

c++,overloading,operator-keyword
This is a question as to the philosophy (canonical design) of user-written C++ input stream extraction operators (>>). Assume that on entry to the >> operator implementation (for a user-written class), the eof flag is already set for the input stream. Should a user-written extraction operator (>>) set the failure...

Java: Unexpected behaviour with concatenating a String and an expression using the plus + operator

java,string,operator-keyword,behavior
Consider the following piece of code public class Test { public static void main(String... strings) { System.out.println("String, " + false); System.out.println("String, " + getFalse()); System.out.println("String, " + new TestClass()); System.out.println("String, " + (new TestClass() == null)); System.out.println("String, " + new TestClass() == null); } private static class TestClass { public...

C++: Associativity of * (multiply) operator is not left-to-right

c++,operator-overloading,operator-keyword,associativity
While working on a school assignment, we had to do something with operator overloading and templates. All cool. I wrote: template<class T> class Multiplication : public Expression<T> { private: typename std::shared_ptr<Expression<T> > l, r; public: Multiplication(typename std::shared_ptr<Expression<T> > l, typename std::shared_ptr<Expression<T> > r) : l(l), r(r) {}; virtual ~Multiplication() {};...

How can I override the member of (->) operator of a base class

c++,qt,inheritance,overloading,operator-keyword
Background: I have Qt generated UI classes with no common ancestor. I am subclassing a class (say, "Door") that uses one of these UI classes, and the derived class ("OakDoor") will use a different UI class, although much of the UI elements will have the same name. Until now I...

Overload c++ operator >> so i can read a vector (vector vector;)

c++,vector,overloading,operator-keyword
i want to know how i can overload the >> operator so i can read a vector or a matrix just doing cin >> vector vector(). Thanks!...

Custom Class - Change attribute in array

python,arrays,class,numpy,operator-keyword
I belivie I am looking for an operator for changes in an array for Python. I have created a custom class for a numpy array matrix. I would like to change a single element in an array, which also changes the numbers of zeros, which is what the class below...

C++/CLI: “ Button^ button1; ” what is ^ meaning here? [duplicate]

class,visual-studio-2012,c++-cli,operator-keyword
This question already has an answer here: What does the caret (‘^’) mean in C++/CLI? 7 answers I created a WindowsForm class in C++/CLI with one button and onClick event. I looked into the source code and saw this: public ref class MyForm : public System::Windows::Forms::Form { public: MyForm(void)...

Proper way to split declaration and definition of inlined non member operator (linker issue)

c++,visual-studio-2013,linker,inline,operator-keyword
I have a visual studio solution with 2 projects, one of which is a static library. In this library I have the following class with some overloaded operators (both members and not): namespace Vec { class Vec2 { ... inline Vec2& operator +=(const Vec2& b); }; inline Vec2 operator+(const Vec2&a,...

& operator string error with string of arguments to processStartInfo

vb.net,operator-keyword,string-concatenation,processstartinfo
I need to pass a string into the ProcessStartInfo for ffmpeg so that I can call the dim.Argument and have it append the strings and variables from code as I parse through the files. I have the current filename.mp3 that the code sees in movedFileInfo but it won't allow me...

C# ?? operator in property, how it works?

c#,operator-keyword
I can't understand how it works. private Person _user; private Person User { get { return _user ?? ( _user = GetUser() ); } } The first time I refer to User property, _user is null so it returns ( _user = GetUser() )???? What am I missing?...

C comma in ternary statement

c,operator-keyword,ternary-operator,comma
int m = 5, d = 12, y = 1975, val; // May 12, 1975 Can someone please explain the function/purpose of the comma operator in the line of code below: val = (d+=m<3?y--:y-2,23*m/9+d+4+y/4-y/100+y/400)%7; The above line was written by Mike Keith to calculate the day of the week given...