c++ loop data structure [duplicate] - c++

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

Related

Sorting list of ints. TMP [duplicate]

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.

Where is an example of a monad? [duplicate]

This question already has answers here:
What is a monad?
(47 answers)
Closed 8 years ago.
I recently have tried to understand what monad is.
Although I watched lots of posts and videos which explains what monad is and what category theory is, because it is too abstract I cant fully understand it. So
Can I have a useful example of monad??
I wrote this post as an example of using the monad abstraction purely as a practical way to avoid code duplication.
(Many things are Monads; what makes Monad useful is writing a function once (in terms of Monad) and then being able to reuse that same function with Future, Option, Either, Writer, State and so on).

What is an equivalent to instanceof in C++? [duplicate]

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.

C++ invalid assignment [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Undefined Behavior and Sequence Points
Is there any one know that whether this is valid or not in C++
int a = 0;
a = a++;
Someone told me that it will generate unknown behavior under C++ standard, did anyone know why, and where in the C++ standard states that? Thanks!
I've posted it before, and I will post it again:
http://www.slideshare.net/olvemaudal/deep-c
highly recommended for anybody with such questions in mind
The techincal reason why is that you should not modify the same variable twice (either directly or due to side effects) between sequence points.
Here is an SO question with good answers that clarifies this further and describes sequence points in general.
I don't know about the standard per se (its probably referenced from the C standard anyway), but here you can read about it:
http://www.research.att.com/~bs/bs_faq2.html#evaluation-order

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.