开发者

Modelling Typeclasses in C++

Is it possible to implement Haskell typecla开发者_如何转开发sses in C++? If yes, then how?


There's a few papers on this, which might be useful as background reading:

  • C++ templates/traits versus Haskell type classes, Sunil Kothari , Martin Sulzmann
  • A Comparative Study of Language Support for Generic Programming, Ronald Garcia , Jaakko Järvi , Andrew Lumsdaine , Jeremy Siek , Jeremiah Willcock


The similar mechanism in C++ is called "concepts". The idea is to define a typeclass by defining the requirements of any type belonging to that class. C++ iterators make extensive use of concepts, and C++0x had intended to support direct syntax for them (rather than the indirect template tricks to perform concept checks C++ currently employs), but it appears this support has been dropped from the standard.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜