Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. struct FactoryAST {
  2.  
  3.     FactoryAST() = default;
  4.  
  5.       //in general I am not a super fan of hardcore or complex templates
  6.       //but I decided to experiment a little with it.
  7.       //This is the inner function, a generic function getting an arbitrary
  8.       //number of arguments and forwarding them to the constructor
  9.     template <typename T, typename... Args> T *allocASTNode(Args... args) {
  10.  
  11.         return new(allocator.alloc(sizeof(T))) T(args...);
  12.     }
  13.  
  14.     template <typename... Args>
  15.     codegen::VariableExprAST *allocVariableAST(Args &&... args) {
  16.       return allocASTNode<codegen::VariableExprAST>(
  17.           std::forward<Args...>(args));
  18.     }
  19.  
  20.     SlabAllocator allocator;
  21.   };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement