This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
C++ struct sorting
Is it possible to sort a vector in C++ according to a specified sorting method, like used in Java's Collections.sort that takes a Comparator?
Yes. See the answers to this question from this morning: C++ struct sorting
Yes, it is. Take a look here for an example.
Related
This question already has answers here:
How to choose between map and unordered_map?
(5 answers)
Closed 5 years ago.
According to: This Tutorial
I can't understand the difference between std::map and std::unorderedmap. When and Why we should use Map and Unorderedmap?
As I've read in tutorial you provided, search speed in std::unorderedmap is O(1). While in std::map it's O(log2(n)), where n is size of the map.
So if you have to call std::find often, you can consider this option. While choosing hash function isn't an easy task.
This question already has answers here:
Quick sort at compilation time using C++11 variadic templates
(2 answers)
Closed 7 years ago.
I wonder it it is possible to sort numbers during compilation? I mean something like that:
template<int...>
void sort(){
...
}
And:
sort<2,4,5,13,453>();
And I don't ask of solution or something like that. Please give me a hint or reference me.
Since C++ template system is known to be turing-complete, you can in principle compute everything that is computable at compile time. That includes sorting algorithms.
This question already has answers here:
C++ equivalent of java's instanceof
(5 answers)
Closed 9 years ago.
How can I check the class type in c++?
In Java I used instanceof.
I prefer not to use dynamic cast, but only classic c++.
Is there any way?
Clarification:
It isn't a duplicate of another question in StackOverflow, since I asked how can I find it without using of dynamic_cast. In the other question, the answer was to use it. Please don't mark it as a duplicated.
There is no way to check class type without RTTI or it's home brew substitution. If application compiled without RTTI information about type is not stored anywhere.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What algorithm gives suggestions in a spell checker?
What algorithm should be used in a C++ program whose aim is to read from a text file and give suggestions for the wrong spelled words ?
Use the Levenshtein distance:
http://thetechnofreak.com/technofreak/levenshtein-distance-implementation-c/
http://murilo.wordpress.com/2011/02/01/fast-and-easy-levenshtein-distance-using-a-trie-in-c/
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Dump facility in C++ like var_dump() in PHP?
I'm not sure does C++ even allow this kind of thing, but I was wondering, could it be possible to write a generic function that could output any type array (std::vector) as plain text, as long as I write myself each of the types output function, for example std::string, float, int, etc.
So, how could I go through the structs types and output them one by one by different output functions made by me?
You should have a look at cxx-prettyprint. http://louisdx.github.com/cxx-prettyprint/
I think it does all your asking for.