comparison-operators

Find substring in the string in TWIG

泪湿孤枕 提交于 2019-11-28 07:06:46
I want to find substring of the string or check if there is no such substring using Twig. On the words, I need analogue of 'strstr' or 'strpos' in php. I googled and searched this issue in stackoverflow but nothing found. Does someone know how to solve this problem? Just searched for the docs , and found this : Containment Operator: The in operator performs containment test. It returns true if the left operand is contained in the right: {# returns true #} {{ 1 in [1, 2, 3] }} {{ 'cd' in 'abcde' }} 来源: https://stackoverflow.com/questions/13007288/find-substring-in-the-string-in-twig

No == operator found while comparing structs in C++

房东的猫 提交于 2019-11-28 03:52:55
Comparing two instances of the following struct, I receive an error: struct MyStruct1 { Position(const MyStruct2 &_my_struct_2, const int _an_int = -1) : my_struct_2(_my_struct_2), an_int(_an_int) {} std::string toString() const; MyStruct2 my_struct_2; int an_int; }; The error is: error C2678: binary '==' : no operator found which takes a left-hand operand of type 'myproj::MyStruct1' (or there is no acceptable conversion) Why? In C++, struct s do not have a comparison operator generated by default. You need to write your own: bool operator==(const MyStruct1& lhs, const MyStruct1& rhs) { return

MySQL comparison operator, spaces

≯℡__Kan透↙ 提交于 2019-11-28 03:16:56
问题 If the database row is like this: country = 'usa' and i query "select * from data where country = 'usa '" it also returns this row. So its not an exact match. Why MySQL does this? And in what other cases it will also return TRUE when its not really true? 回答1: The trailing spaces are omitted if the column is of type char or varchar ; using like 'usa ' resolves the issue 回答2: As mentioned in the manual: All MySQL collations are of type PADSPACE . This means that all CHAR and VARCHAR values in

How to overload operator==() for a pointer to the class?

随声附和 提交于 2019-11-28 01:11:30
I have a class called AString . It is pretty basic: class AString { public: AString(const char *pSetString = NULL); ~AString(); bool operator==(const AString &pSetString); ... protected: char *pData; int iDataSize; } Now I want to write code like this: AString *myString = new AString("foo"); if (myString == "bar") { /* and so on... */ } However, the existing comparison operator only supports if (*myString == "bar") If I omit that asterisk, the compiler is unhappy. Is there a way to allow the comparison operator to compare *AString with const char* ? No, there is not. To overload operator== ,

Is comparison of const_iterator with iterator well-defined?

纵饮孤独 提交于 2019-11-27 21:31:55
问题 Consider the following code: #include <vector> #include <iostream> int main() { std::vector<int> vec{1,2,3,5}; for(auto it=vec.cbegin();it!=vec.cend();++it) { std::cout << *it; // A typo: end instead of cend if(next(it)!=vec.end()) std::cout << ","; } std::cout << "\n"; } Here I've introduced a typo: in the comparison I called vec.end() instead of vec.cend() . This appears to work as intended with gcc 5.2. But is it actually well-defined according to the Standard? Can iterator and const

C# Type Comparison: Type.Equals vs operator ==

青春壹個敷衍的年華 提交于 2019-11-27 21:01:31
Resharper suggests that the following be changed from: Type foo = typeof( Foo ); Type bar = typeof( Bar ); if( foo.Equals( bar ) ) { ... } To: if( foo == bar ) { ... } operator == // Summary: // Indicates whether two System.Type objects are equal. // // Parameters: // left: // The first object to compare. // // right: // The second object to compare. // // Returns: // true if left is equal to right; otherwise, false. public static bool operator ==( Type left, Type right ); Equals( Type o ) // Summary: // Determines if the underlying system type of the current System.Type is the // same as the

C# Nullable Equality Operations, Why does null <= null resolve as false? [duplicate]

徘徊边缘 提交于 2019-11-27 19:37:16
This question already has an answer here: Why does >= return false when == returns true for null values? 8 answers Why is it that in .NET null >= null resolves as false, but null == null resolves as true? In other words, why isn't null >= null equivalent to null > null || null == null ? Does anyone have the official answer? This behaviour is defined in the C# specification ( ECMA-334 ) in section 14.2.7 (I have highlighted the relevant part): For the relational operators < > <= >= a lifted form of an operator exists if the operand types are both non-nullable value types and if the result type

JavaScript - === vs == operators performance

你。 提交于 2019-11-27 12:25:56
A few weeks ago, I have read this thread Is < faster than <=? about comparison operators in C . It was said that there is no difference in the performance between < and <= as they are interpreted as same/similar machine commands. At the same time, in our company's "best practices", it was said that we should always use "===" to compare things instead of "==". So, I started to wonder if this is always appropriate as I am used to using the "==" and "typeof ... == " and do not want to change my way of writing :-] Note that this is in the context of JavaScript. So, I have a little research and

Understanding set comparison

旧巷老猫 提交于 2019-11-27 08:51:08
问题 So, my problem is to understand comparison between lists. I had a homework to compare if some string has all the letters from the alphabet, so i did this: import string def ispangram(str): letters = ''.join(str.split()).lower() unique_letters = set(letters) sorted_list = list(sorted(unique_letters)) str_alphabet = ''.join(sorted_list) alphabet = string.ascii_lowercase if str_alphabet == alphabet: print(True) else: print(False) ispangram("The quick brown fox jumps over the lazy dog") Ok, i got

JavaScript equality transitivity is weird

梦想的初衷 提交于 2019-11-27 07:24:37
I've been reading Douglas Crockford's JavaScript: The Good Parts , and I came across this weird example that doesn't make sense to me: '' == '0' // false 0 == '' // true 0 == '0' // true false == undefined // false false == null // false null == undefined // true The author also goes on to mention "to never use == and != . Instead, always use === and !== ". However, he doesn't explain why the above behavior is exhibited? So my question is, why are the above results as they are? Isn't transitivity considered in JavaScript? alex '' == '0' // false The left hand side is an empty string, and the