Sorting list of ints. TMP [duplicate] - c++

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.

Related

How can I Tell if a Type is a Functor? [duplicate]

This question already has answers here:
Find out whether a C++ object is callable
(8 answers)
Can std::is_invocable be emulated within C++11?
(1 answer)
Closed 3 years ago.
In c++17 I have is_invocable to match function pointers, lambdas, and functors.
But what if I'm trapped on c++14? Do I have a type trait, or can I write one, which will match all of these?
I've tried is_function but that only works on function pointers.
Yes you can, std::is_invocable is a library function which requires no compiler support. You can just rip the implementation from an STL of your choice.
For example, you can find LLVM implementation of __invokable (to which std::is_invocable forwards all the logic in LLVM's STL) here: https://android.googlesource.com/platform/ndk/+/5b3a49bdbd08775d0e6f9727221fe98946f6db44/sources/cxx-stl/llvm-libc++/libcxx/include/type_traits
(I was thinking of extracting it and posting here, but it seems to be too big for a post. On a lighter note, I find difference in spelling - invocable vs invokable - amusing.)

Why function argument evaluation cannot be ordered? [duplicate]

This question already has answers here:
Order of evaluation in C++ function parameters
(6 answers)
Closed 4 years ago.
As far as we know, the function argument evaluation order is not defined by c++ standard.
For example:
f(g(), h());
So we know it is undefined.
My question is, why cant c++ standard define the order of evaluation from left to right??
Because there is no good reason to do so.
The c++ standard generally only defines what is necessary and leaves the rest up to implementers.
This is why it produces fast code and can be compiled for many platforms.

c++ loop data structure [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Does a standard implementation of a Circular List exist for C++?
Is there ready a template class in some c++ library that is some kind of a loop: A liked list where the last node references the first one.
Admittedly this wouldn't always be a practical class to use since there couldn't exist a end() iterator nor a well defined begin() iterator. But I could really have use for one and I was hoping that I wouldn't have to code it myself.
Edit:
Thank you both (Vivek Goel and madmik3) and for your answers, but unfortunately they have nothing to do with my question (I suggest http://en.wikipedia.org/wiki/Linked_list to you both). I also found the same question here, didn't find it yesterday. I apologise for posting the same question.
What about Circular Buffer from boost
http://www.boost.org/doc/libs/1_51_0/libs/circular_buffer/doc/circular_buffer.html
Boost has a circular buffer.
http://www.boost.org/doc/libs/1_51_0/libs/circular_buffer/doc/circular_buffer.html
You can also see sample code here:
http://en.wikipedia.org/wiki/Ring_buffer

C++ equivalent for print_r() from PHP? [duplicate]

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.

C++ change sort method [duplicate]

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.