c++ version of library. I use class. next step is using template to improve this