开发者

Call/Return feature of classic C++(C with Classes), what modern languages have it?

On page 57 of The Design and Evolution of C++, Dr. Stroustrup talks about a feature that was initially part of C with Classes, but it isn't part of modern C++(standard C++). The feature is called call/return. This is an example:

class myclass
{
  call() { /* do something before each call to a function. */ }
  return() { /* d开发者_如何学Pythono something else after each call to a function. */ }
  ...
};

I find this feature very interesting. Does any modern language have this particular feature?


The modern C++ equivalent would be a sentry object: construct it at the beginning of a function, with its constructor implementing call(), and upon return (or abnormal exit), its destructor implements return().


Aspect Oriented Programming has this. http://en.wikipedia.org/wiki/Aspect-oriented_programming

Aspect Oriented Programming (also known as AOP) has the ability to create interceptors before, after and around code.


The D2 programming language has this and more with it's ScopeGuards. It's designed so you can use multiple ones, they work like a FILO stack.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜