0

I'm trying to implement lazy in C++ like in this Python example using decorators:

@lazy
@factory(Category)
def func(self):
    return self.__raw_data  # for building object include object type and **params

I found Getting Lazy with C++ and Lazy evaluation in C++ post but they haven't helped me. I don't understand how implement the lazy.

Community
  • 1
  • 1
  • Do you mean this [`lazy` package](https://pypi.python.org/pypi/lazy) and this [`lazy` decorator](http://pythonhosted.org/lazy/#lazy.lazy) ? – Bakuriu Sep 30 '15 at 19:02
  • Hi Bakuriu, yep decorator. Example: class lazy(object): def __init__(self, function): self._function = function def __get__(self, instance, owner = None): if instance == None: return self val = self._function(instance) setattr(instance, self._function.func_name, val) return val – Alexander Steshenko Sep 30 '15 at 19:06
  • It isn't clear what your specific problem is. – n. m. could be an AI Sep 30 '15 at 19:51
  • @n.m. hi. Ok, sorry for bad explanation. I want don`t create object while it not need. I stored raw data which transfer into constructor but not immediately. While object not need it just storaged (lazy) for create object in future and data for transfer in constructor. I want create objects to demand. How implement this on Python I know but C++ porting difficult for me. – Alexander Steshenko Sep 30 '15 at 20:05
  • @Bakuriu yep how decorator. – Alexander Steshenko Sep 30 '15 at 20:09
  • you mean something like this ??:http://stackoverflow.com/questions/21252296/lazy-initialization-with-singleton-pattern – basav Oct 01 '15 at 04:49
  • @basav thanks for answer maybe this is solution of my problem. – Alexander Steshenko Oct 01 '15 at 10:57

0 Answers0