Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Break up Alloc<T> in to templated and (mostly) non-templated parts? Without seeing the code its hard to know.


It is a tiny function that is basically equivalent to that macro, but using variadic templates:

    template <typename T, typename... Args>
    T* Alloc(Args&&... args) {
      assert(gHeap.is_initialized_);
      void* place = gHeap.Allocate(sizeof(T));
      assert(place != nullptr);
      // placement new
      return new (place) T(std::forward<Args>(args)...);
    }
https://github.com/oilshell/oil/blob/master/mycpp/gc_heap.h#...

So there is nothing to really break up


Make it forced-inline and it should be more similar to the macro.


It also needs to be marked as hidden or internal visibility (or be made static) otherwise an instantiation will likely still be present in the binary




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: