background preloader

Cpp

Facebook Twitter

C

STL. Debugger. Terra Informatica » Generators in C++ May 26, 2008 As we know iterators in C++ is a good but not perfect abstraction. Concept of foreach() (D, Python, Ruby, etc.) appears as more generic solution. At least foreach() does not require artificial iterator::end() to be defined for the collection.

Abstraction foreach() can be imagined as some function/object that is returning next value of collection/sequence each time it is getting invoked. Such functions are known as generators. Here is my version of generator() for the C++. First of all sample, here is a declaration of our generator function in C++: #include "generator.h" generator(descent) { int i; emit(int) // will emit int values. Having declared such generator we can use it as: int main(int argc, char* argv[]) { descent gen; do printf("next number is %d\n", gen()); while (gen); return 0; } That is pretty simple and should be intuitively clear, no?

Here is full source of the generator.h file: Enjoy! C++ FQA Lite: Defective C++ Part of C++ FQA Lite This page summarizes the major defects of the C++ programming language (listing all minor quirks would take eternity). To be fair, some of the items by themselves could be design choices, not bugs. For example, a programming language doesn't have to provide garbage collection. It's the combination of the things that makes them all problematic. For example, the lack of garbage collection makes C++ exceptions and operator overloading inherently defective. Therefore, the problems are not listed in the order of "importance" (which is subjective anyway - different people are hit the hardest by different problems). No compile time encapsulation In naturally written C++ code, changing the private members of a class requires recompilation of the code using the class.

Well, at least when all relevant code is controlled by the same team of people, the only problem is the frequent rebuilds of large parts of it. Outstandingly complicated grammar No way to locate definitions. Raw Material Software - Juce. Dzone.com - fresh links for developers. The Artima Developer Community. ACCU. The C++ Source. In this article, Scott Meyers describes a technique that enables the specification of arbitrary combinations of user-defined code features on a per-function basis and that detects violations of feature constraints during compilation. by Howard E. Hinnant, Bjarne Stroustrup, and Bronek Kozicki, March 10, 2008, 62 comments Rvalue references is a small technical extension to the C++ language.

Rvalue references allow programmers to avoid logically unnecessary copying and to provide perfect forwarding functions. They are primarily meant to aid in the design of higher performance and more robust libraries. Computers make life easier because they're so fast, right? The author discusses how the use of generic programming in C++ can lead to conflicts with object-oriented design principles. C++ is a language for writing efficient high-performance programs, and bit manipulations are bread and butter of many such programs. Have your cake and eat it, too, with STL extensions. 11 comments.