Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualBitMaster

Posted 10 January 2013 - 03:17 AM

Shouldn't this work more intuitively?
template  template 
   typename List::Node* List::AllocateNode (TArgs&&... args) 
   {
      struct Deleter
      {
         void operator () (Node* n) { Deallocate(n); }
      };

      uint64_t m;
      std::unique_ptr<Node, Deleter> n(Allocate(1,m));
      new (n.get()) Node(std::forward(args)...);
      return n.release();
   }
Edit: initially forgot I need the deleter as part of the std::unique_ptr type...
Edit2: not what I planned initially, but this should be the same performance as doing it by hand, just with automatic RAII. I'm pretty sure the local type in the template should be legal in C++11 but I don't have a relevant standard at hand right now.

#3BitMaster

Posted 10 January 2013 - 03:12 AM

Shouldn't this work more intuitively?
template <typename T, typename Alloc> template <typename... TArgs>
   typename List<T,Alloc>::Node* List<T,Alloc>::AllocateNode (TArgs&&... args) 
   {
      uint64_t m;
      std::unique_ptr<Node, std::function<void (Node*)>> n(Allocate<Node>(1,m), [] (Node* n) { Deallocate(n); });
      new (n.get()) Node(std::forward<TArgs>(args)...);
      return n.release();
   }

Edit: initially forgot I need the deleter as part of the std::unique_ptr type...

#2BitMaster

Posted 10 January 2013 - 03:10 AM

Shouldn't this work more intuitively?
template <typename T, typename Alloc> template <typename... TArgs>
   typename List<T,Alloc>::Node* List<T,Alloc>::AllocateNode (TArgs&&... args) 
   {
      uint64_t m;
      std::unique_ptr<Node> n(Allocate<Node>(1,m), [] (Node* n) { Deallocate(n); });
      new (n.get()) Node(std::forward<TArgs>(args)...);
      return n.release();
   }

#1BitMaster

Posted 10 January 2013 - 03:09 AM

Shouldn't this work more intuitively?


template <typename T, typename Alloc> template <typename... TArgs>
   typename List<T,Alloc>::Node* List<T,Alloc>::AllocateNode (TArgs&&... args) 
   {
      uint64_t m;
      std::unique_ptr<Node[]> n(Allocate<Node>(1,m), [] (Node* n) { Deallocate(n); });
      new (n.get()) Node(std::forward<TArgs>(args)...);
      return n.release();
   }

PARTNERS