Emacs Lisp: difference between (function (lambda …)) and (lambda …)?

What is the difference between (function (lambda …)) and (lambda …) and ‘(lambda …) ? It seems three are interchangeable in a lot of cases. Answer They are pretty interchangeable. The answer is that function enables the lambda to be byte compiled, whereas the other two do not (and are equivalent). Note: this does not … Read more

How do I get characters common to two vectors in C++?

I am trying to compare two vector objects, and return a single vector containing all the chars which appear in both vectors. How would I go about this without writing some horribly complex manual method which compares every char in the first vector to every char in the second vector and using an if to … Read more

Shortcut for creating a comparator based on a member field or function

I often find myself wanting to create a comparator objects for a struct or class which simply extracts one member of the class and does the usual < comparison on that. For example: struct student { int id; std::string name; }; // sort by ID std::sort(students.begin(), students.end(), [](const student& l, const student& r){ return l.id … Read more

Why isn’t this DirectoryInfo comparison working? [duplicate]

This question already has answers here: Closed 9 years ago. Possible Duplicate: How to check whether 2 DirectoryInfo objects are pointing to the same directory? var dirUserSelected = new DirectoryInfo(Path.GetDirectoryName(“SOME PATH”)); var dirWorkingFolder = new DirectoryInfo(Path.GetDirectoryName(“SAME PATH AS ABOVE”)); if (dirUserSelected == dirWorkingFolder) { //this is skipped } if (dirUserSelected.Equals(dirWorkingFolder)) { //this is skipped } … Read more

Need to Compare Two Generic Objects Using Greater Than or Less Than [duplicate]

This question already has answers here: How to compare values of generic types? (8 answers) Closed 8 years ago. Synopsis: I have a need to take two generic C# objects, and if they are numerical, compare them using either less than or greater than comparisons. Problem: I can’t figure out how to have my class … Read more

How to most efficiently test if two arrays contain equivalent items in C#

I have two arrays and I want to know if they contain the same items. Equals(object obj) doesn’t work because an array is a reference type. I have posted my attempt below, but since I’m sure this is a common task I’d like to know if there is a better test. public bool ContainsEquivalentSequence<T>(T[] array1, … Read more

What’s the recommended best practice for using IEqualityComparer?

I’m looking for real world best practices, how other people might have implemented solutions with complex domains. Answer Any time you consider using an IEqualityComparer<T>, pause to think if the class could be made to implement IEquatable<T> instead. If a Product should always be compared by ID, just define it to be equated as such … Read more