Christopher Smith on 12 Jun 2003 21:48:01 -0000 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
[ALACPP] Latest CUJ doing sorting with typelists. |
So, I didn't get much sleep last night, and for the first part of it I decided to read my latest CUJ. It has a number of interesting articles in it which various members of this group would like (like an article on Boost.Python, and another on custom memory allocators). The one that really caught my eye though was an article about using typelists to do sorting. C++ sorting is typically done with functors, so what this article talks about is using a typelist to chain together a variety of sort functors. So, you could do something like TYPELIST_2(less_last, less_first) to instantiate a sorter which sorts on last name, then first name, essentially using the Chain-of-Command pattern. This struck me as a specific instantiation of what I was talking about yesterday: namely static functors, using template parameters instead of instance variables. This allows you to define a templated "map" class that allows you to chain together a series of functors using a typelist. The nice thing is that it's all evaluated at compile time, so you get the benefits of polymorphism without the overhead of a virtual function table (indeed, in a lot of cases function calls will get inlined). --Chris _______________________________________________ alacpp mailing list alacpp@xxxxxxxxxxx http://lists.ellipsis.cx/mailman/listinfo/alacpp