Skip to main content

Going up step by step

Have you ever wanted to be able to iterate through your own class as if it was a cool STL container?
Do something like this:

Then it there is a way to integrate your class into STL and get powerful support. In order to be able to provide interface to for each loop you need to support in your custom classes set of operations such as:

After giving it a good time to fix all the bugs and understand them all as single piece you will notice what really for each loop needs to be able to iterate through a custom object.

Here a code example. Simple one.

If you have a big class on your hands that stores all the data and you want to implement a more secure and encapsulated class you can implement a set of Wrappers and Iterators to iterate all of those edges of your class.

This code sample is a bit crazy. But it shows how you can separate iteration routine and the rest of class logic. Controlling complexity is a goal of software architecture. Patterns, SOLID and other instruments are there only cause of some bright minds wanted to show their jobs on that topic for other people to use it.

Iterators are neat concept separating STL algorithms and containers. Watching on Iterator pattern from another angle reveals different way to look at it's place in STL. Since Iterators usually implemented inside of containers they as glue connects two islands of the STL archipelago.

It's better to think about this relations as if there is a strictly established policy of data translation. Such high level of abstraction model let us see what the idea behind design of STL, as well as start to see other libraries on such level.

Iterate and prosper.

Popular posts from this blog

Какой язык изучать и почему не схх?

Многие товарищи, что хотят начать изучать программирование, долго выбирают язык, технологию, платформу. Долго думают, а правильно ли они поступают выбрав cxx/Java/C$/something else. Затем долго расспрашивают знакомых программистов, читают форумы, собираются с духом, поступают в университет на специальность включающую программирование, идут на работу связанную с изученной технологией... И начинают сомневаться в правильности сделанного выбора.

В этой статье jsonmez очень хорошо описал почему не стоит выбирать схх(ещё один вариант написания C++).

"Ну и что? Очередная статья ни о чём..." - подумаете вы.

Статья очередная, но не бесполезная. В ней написаны 36 вопросов, которые, по моему мнению, очень даже помогают оценить ваши знания в сфере схх. Либо хотя бы понять к чему стремиться, если вы всё же решились изучать "самый сложный язык с ООП".

Можно мысленно разбить схх на уровни по сложности задач.

1ый уровень: высокоуровневые задачи, такие как ввод, вывод данных и соо…

Maturing, relocation, getting to the point

So it's been a long time I've wrote something for the blog.
Since the last post few things have changed. For example - I've moved in a foreign country. I went into Ukraine which is not a big deal you would say, but for me it's a pretty significant change in my life.

I've worked a two years in solo on a video related projects, one of which was related to trans-coding video on fly using a gstreamer and the other one was about storing and providing access to a video content by special tags, this one was a nightmare.

The gstreamer is a neat open source solution in video processing libraries. The people designed it are crazy ones - such a over-complicated implementation to achieve flexibility and effectiveness in processing video on various platforms and hardware. The most important about this library for me was it's non-existing support. Or should I say community driven support? I don't know even for now. At the time I've had a couple questions, so basical…