c++ - practice and discovery of Boost Type Erasure -


i reading boost type erasure , trying figure out potential usage. practice bit while reading tons of documentations topic (it looks big one). quoted area of application networking / exchanging data between client , server. can suggest other example or exercise can play bit library?

type erasure useful in extraordinary amount of situations, point may thought of fundamentally missing language feature bridges generic , object oriented programming styles.

when define class in c++, defining both specific type , specific interface, , these 2 things not need related. type deals data, interface deals transformations on data. generic code, such in stl, doesn't care type, cares interface: can sort container or container-like sequence using std::sort, long provides comparison , iterator interface.

unfortunately, generic code in c++ requires compile time polymorphism: templates. doesn't things cannot known until runtime, or things require uniform interface.

a simple example this: how store number of different types in single container? simplest mechanism store of types in void*, perhaps type information distinguish them. way recognize of these types have same interface: retrieval. if make single interface retrieval, specialize each type, if part of type had been erased.

any_iterator useful reason this: if need iterate on number of different containers same interface, need erase type of container out of type of iterator. boost::any_range subtle enhancement of this, extending iterators ranges, basic idea same.

in short, time need go multiple types similar interface single type single interface, need form of type erasure. runtime technique equates compile time templates.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -