www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is this possible?

Hi all,

Is it possible in D to use templates or mixins for something like this 
(in python)?


def A(par1,par2):
     return NO_ERROR
def B(par1):
     return ERROR

def wrap(func):
     def wrapped(*args):
         result = func(*args)
         if result == ERROR:
             raise Exception('some description')
     return wrapped

wrappedA = wrap(A)
wrappedB = wrap(B)

wrappedA( 1,2 )
wrappedB( 3 )
-->> exception raised!

Thanks in advance!

---
Paolo Invernizzi
Feb 20 2006