Search Results

Search found 2508 results on 101 pages for 'ternary operator'.

Page 80/101 | < Previous Page | 76 77 78 79 80 81 82 83 84 85 86 87  | Next Page >

  • Using Linq to filter parents by their children

    - by Nick L
    Having some problems with my Silverlight app (with RIA services) filtering my results. The idea is on the client I set up the EntityQuery and its filters and call load. However this isn't working for me. Heres my code. public void FireQuery(string filterValue) { EntityQuery<Parent> query = m_ParentDomainContext.GetParentQuery(); query = query.Where(p => p.Children.Any(c => c.Name.Contains(filterValue))); m_ParentDomainContext.Load(query, Query_Completed, null); } Compiles just fine, however, runtime I get "Query operator 'Any' is not supported." Exception. Does anyone know of a good way to filter like this? Again, I'm looking for a way to set this up on the client.

    Read the article

  • C++ Iterators and inheritance

    - by jomnis
    Have a quick question about what would be the best way to implement iterators in the following: Say I have a templated base class 'List' and two subclasses "ListImpl1" and "ListImpl2". The basic requirement of the base class is to be iterable i.e. I can do: for(List<T>::iterator it = list->begin(); it != list->end(); it++){ ... } I also want to allow iterator addition e.g.: for(List<T>::iterator it = list->begin()+5; it != list->end(); it++){ ... } So the problem is that the implementation of the iterator for ListImpl1 will be different to that for ListImpl2. I got around this by using a wrapper ListIterator containing a pointer to a ListIteratorImpl with subclasses ListIteratorImpl2 and ListIteratorImpl2, but it's all getting pretty messy, especially when you need to implement operator+ in the ListIterator. Any thoughts on a better design to get around these issues?

    Read the article

  • C++ How do you set an array of pointers to null in an initialiser list like way?

    - by boredjoe
    I am aware you cannot use an initialiser list for an array. However I have heard of ways that you can set an array of pointers to NULL in a way that is similar to an initialiser list. I am not certain how this is done. I have heard that a pointer is set to NULL by default, though I do not know if this is guaranteed/ in the C++ standard. I am also not sure if initialising through the new operator compared to normal allocation can make a difference too.

    Read the article

  • Testing what a String token holds

    - by Yiwei Gao
    I am making a calculator and part of this program takes in user String input and tokenizes it (using my own implementation of a Tokenizer class). So now I have a bunch of Token objects and I would like to test each one of them to see if they hold numbers or operators. Is there a way to test to see if they hold operators (ie. +, -, *, /, =, (, ), etc.) without using if (token.equals("+") || token.equals("-") || ... and so on, for each operator? These Token objects are all of type String.

    Read the article

  • What does it mean when a Perl method returns a "hashref"?

    - by Uri
    I'm trying to decrypt a Perl code which I'm not familiar with, somehow related to HashRef. I'm using Amazon::S3, but my question is a general Perl question. See the code below: use Amazon::S3; my $s3 = Amazon::S3->new( ... ); my $response = $s3->buckets; Documentation (here) sais, about s3-buckets: Returns undef on error, else HASHREF of results The following line is working for me, but I don't understand why: for $b in ( @ { $response->{buckets} } ) { print "bucket: " . $b->bucket . "\n"; } I'm Puzzled by each operator on the first line. What type exactly are $response, $respone->{bucket}. Looks like the expression within the for is an array, but I don't understand this syntax: @{ ... }?

    Read the article

  • The Cash or Credit problem

    - by Josh K
    If you go to a store and ask "Cash or Credit?" they might simply say "Yes." This doesn't tell you anything as you posed an OR statement. if(cash || credit) With humans it's possible that they might respond "Both" to that question, or "Only {cash | credit}." Is there a way (or operator) to force the a statement to return the TRUE portions of a statement? For example: boolean cash = true; boolean credit = true; boolean cheque = false; if(cash || credit || cheque ) { // In here you would have an array with cash and credit in it because both of those are true }

    Read the article

  • How to know if the argument that is passed to the function is a class, union or enum in c++?

    - by Narek
    I want to define an operator<< for all enums, to cout the value and print that it is an enum like this: code: enum AnyEnum{A,B,C}; AnyEnum enm = A; cout << enm <<endl; output: This is an enum which has a value equal to 0 I know a way of doing this with Boost library by using is_enum struct. But I don’t understand how it works. So that's why, in general, I am interested how to identify if the veriable is a class type, union type or an enum (in compile time).

    Read the article

  • fastest method for minimum of two numbers

    - by user85030
    I was going through mit's opencourseware related to performance engineering. The quickest method (requiring least number of clock cycles) for finding the minimum of two numbers(say x and y) is stated as: min= y^((x^y) & -(x<y)) The output of the expression x < y can be 0 or 1 (assuming C is being used) which then changes to -0 or -1. I understand that xor can be used to swap two numbers. Questions: 1. How is -0 different from 0 and -1 in terms of binary? 2. How is that result used with the and operator to get the minimum? Thanks in advance.

    Read the article

  • What types of conditions can be used for conditional compilation in C++?

    - by user1002288
    This is an exam question for C++: Which of the following statements accurately describe the condition that can be used for conditional compilation in C++? A. The condition can depend on the value of environment variables. B. The condition can depend on the value of any const variables. C. The condition can depend on the value of program variables. D. The condition can use the sizeof() operator to make decision about compiler-dependent operations based on the size of standard data type. E. The condition must evaluate to either a 0 or 1 during preprocessing. I think the answer is E. Is this correct?

    Read the article

  • How does the stream manipulators work?

    - by Narek
    It is well known that the user can define stream manipulators like this: ostream& tab(ostream & output) { return output<< '\t'; } And this can be used in main() like this: cout<<'a'<<tab<<'b'<<'c'<<endl; Please explain me how does this all work? If operator<< assumes as a second parameter a pointer to the function that takes and returns ostream &, then please explain my why it is necessary? What would be wrong if the function does not take and return ostream & but it was void instead of ostream &? Also it is interesting why “dec”, “hex” manipulators take effect until I don’t change between them, but user defined manipulators should be always used in order to take effect for each streaming?

    Read the article

  • How to stable_sort without copying?

    - by Mehrdad
    Why does stable_sort need a copy constructor? (swap should suffice, right?) Or rather, how do I stable_sort a range without copying any elements? #include <algorithm> class Person { Person(Person const &); // Disable copying public: Person() : age(0) { } int age; void swap(Person &other) { using std::swap; swap(this->age, other.age); } friend void swap(Person &a, Person &b) { a.swap(b); } bool operator <(Person const &other) const { return this->age < other.age; } }; int main() { static size_t const n = 10; Person people[n]; std::stable_sort(people, people + n); }

    Read the article

  • typedef to store pointers in C

    - by seriouslion
    The Size of pointer depends on the arch of the machine. So sizeof(int*)=sizeof(int) or sizeof(int*)=sizeof(long int) I want to have a custom data type which is either int or long int depending on the size of pointer. I tried to use macro #if, but the condition for macros does not allow sizeof operator. Also when using if-else, typedef is limited to the scope of if. if((sizeof(int)==sizeof(int *)){ typedef int ptrtype; } else{ typedef long int ptrtype; } //ptrtype not avialble here Is there any way to define ptrtype globally?

    Read the article

  • Using template specialization in C++

    - by user550413
    How can I write a function using template specialization that has 2 different input types and an output type: template <class input1, class input2, class output> and return the sum of the 2 numbers (integers/doubles). However, if I get 2 integers I want to return an integer type but for any other combinations of integer and double I'll always return double. I am trying to do that without using directly the '+' operator but having the next functions instead: double add_double_double(double a, double b) {return (a+b);} double add_int_double(int a, double b) {return ((double)(a)+b);} int add_int_int(int a, int b) {return (a+b);}

    Read the article

  • Mobile web apps - Is this the right approach?

    - by Pasta
    I need to build a cross platform mobile app (iphone, android, etc). The app is for a company like a cellular operator (Tmobile, ATT). The app needs to do the following: Show previous bills (cached so that it does not have to download everytime) Need an internet connection to download newer bills, view recent data, etc. Can I build a mobile web app to handle this? I understand that there is offline storage and iPhone has good support for web apps (full screen, good icons, offline, etc). Will a web app be the best approach to take as the app requires to be online? The app will not be used by lots of people, just customers of the website who don't want to use an existing website. We are all web developers and a mobile web app looks like the best way to approach this.

    Read the article

  • What's the simplest way of defining lexicographic comparison for elements of a class?

    - by the_mandrill
    If I have a class that I want to be able to sort (ie support a less-than concept), and it has several data items such that I need to do lexicographic ordering then I need something like this: struct MyData { string surname; string forename; bool operator<(const MyData& other) const { return surname < other.surname || (surname==other.surname && forename < other.forename); } }; This becomes pretty unmanageable for anything with more than 2 data members. Are there any simpler ways of achieving it? The data members may be any Comparable class.

    Read the article

  • Finding the specific type held in an ArrayList<Object> (ie. Object = String, etc.)

    - by Christopher Griffith
    Say I have an ArrayList that I have cast to an ArrayList of objects. I know that all the objects that were in the ArrayList I cast were of the same type, but not what the type was. Now, if the ArrayList is not empty, I could take one of the objects in it and use the instanceof operator to learn what the actual type is. But what of the case where the ArrayList is empty? How do I determine what type Object actually is then? Is it possible?

    Read the article

  • Casting an object which could be null

    - by DeeMac
    DateTime? testDate = (DateTime?)arrayOfObjects[dateObject]; Does that code look ok? I attempted to use the as operator but I got the 'non-nullable' error. What I'm trying to say is that the object I'm choosing from the array is either DateTime or a null DateTime but either can be assigned to testDate. Doesn't feel right doing it this way, I think I'm missing something obvious. EDIT: I suppose it's the same as the way I could've adapted the as in the following way: DateTime? testDate = arrayOfObjects[dateObject] as DateTime?; Is either line of code the best way of handling potential nulls?

    Read the article

  • C++ template specialization

    - by user231536
    I have a class template <typename T> class C { static const int K=1; static ostream& print(ostream& os, const T& t) { return os << t;} }; I would like to specialize C for int. //specialization for int template <> C<int>{ static const int K=2; } I want the default print method that works for int to remain and just change the constant. For some specializations, I want to keep K=1 and change the print method because there is no << operator. How do I do this?

    Read the article

  • What is the difference between "a is b" and "id(a) == id(b)" in Python?

    - by bp
    The id() inbuilt function gives... an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime. The is operator, instead, gives... object identity So why is it possible to have two objects that have the same id but return False to an is check? Here is an example: >>> class Test(): ... def test(): ... pass >>> a = Test() >>> b = Test() >>> id(a.test) == id(b.test) True >>> a.test is b.test False A more troubling example: (continuing the above) >>> b = a >>> b is a True >>> b.test is a.test False >>> a.test is a.test False

    Read the article

  • Postfix evaluation in C

    - by Andrewziac
    I’m taking a course in C and we have to make a program for the classic Postfix evaluation problem. Now, I’ve already completed this problem in java, so I know that we have to use a stack to push the numbers into, then pop them when we get an operator, I think I’m fine with all of that stuff. The problem I have been having is scanning the postfix expression in C. In java it was easier because you could use charAt and you could use the parseInt command. However, I’m not aware of any similar commands in C. So could anyone explain a method to read each value from a string in the form: 4 9 * 0 - = Where the equals is the signal of the end of the input. Any help would be greatly appreciated and thank you in advance :)

    Read the article

  • binary number comparison

    - by EquinoX
    If I have a 32 bit two's complement number and I want to know what is the easiest way to know of two numbers are equal... what would be the fastest bitwise operator to know this? I know xor'ing both numbers and check if the results are zero works well... any other one's? how about if a number is greater than 0?? I can check the 31'st bit to see if it's greater or equal to 0..but how about bgtz?

    Read the article

  • Switching from php to python

    - by ts
    Hello I am trying to make a list of things which can be difficult/surprising to someone who is changing language from PHP to Python. so far i have rather short list: forget require / include, learn import (this was most difficult to me - to understand package - module - class - object hierarchy and its mapping to filesystem) you can't just upload file on server to have webpage (-mod_python, wsgi etc) learn the python way for use variable class names (new $class() vs import + getattr) / operator in python 2.x and all float-related horrors those were difficult to me, it takes few days before mind adapts a new paradigm after i found that there is few other areas which could be challenging for someone with (too) many years of php: everything is an object you have to live with exceptions array vs list, set, dictionary, tuple ... learn (effective) list comprehensions learn generators any other ideas / personal experiences ?

    Read the article

  • Quickest way to compute the number of shared elements between two vectors

    - by shn
    Suppose I have two vectors of the same size vector< pair<float, NodeDataID> > v1, v2; I want to compute how many elements from both v1 and v2 have the same NodeDataID. For example if v1 = {<3.7, 22>, <2.22, 64>, <1.9, 29>, <0.8, 7>}, and v2 = {<1.66, 7>, <0.03, 9>, <5.65, 64>, <4.9, 11>}, then I want to return 2 because there are two elements from v1 and v2 that share the same NodeDataIDs: 7 and 64. What is the quickest way to do that in C++ ? Just for information, note that the type NodeDataIDs is defined as I use boost as: typedef adjacency_list<setS, setS, undirectedS, NodeData, EdgeData> myGraph; typedef myGraph::vertex_descriptor NodeDataID; But it is not important since we can compare two NodeDataID using the operator == (that is, possible to do v1[i].second == v2[j].second)

    Read the article

  • C++ Reference of vector

    - by void
    Hello, class Refvect { public: vector<int> &refv; Refvect(int t, vector<int> &refv = vector<int>()) : refv(refv) { }; void operator()() { refv.clear(); } }; int main () { Refvect r(0); r(); } With Visual Studio 2010, this gives me an error : "vector iterators incompatible" at the execution, but I don't understand why (but I can insert elements in refv without any problem). The temporary object vector() lives as long as the reference, no?

    Read the article

  • Can't compile std::map sorting, why?

    - by Vincenzo
    This is my code: map<string, int> errs; struct Compare { bool operator() (map<string, int>::const_iterator l, map<string, int>::const_iterator r) { return ((*l).second < (*r).second); } } comp; sort(errs.begin(), errs.end(), comp); Can't compile. This is what I'm getting: no matching function for call to ‘sort(..’ Why so? Can anyone help? Thanks!

    Read the article

< Previous Page | 76 77 78 79 80 81 82 83 84 85 86 87  | Next Page >