allocator<"uncopyable">::construct
-
Mahlzeit zusammen...
Folgendes stark vereinfachtes Modell:#include <memory> template<template <typename> class Allocator = std::allocator> class Node { public: typedef Allocator<Node> Alloc; static Node* Create() { Node* n = alloc_.allocate(1); alloc_.construct(n, Node()); return n; } static void Delete(Node* n) { alloc_.destroy(n); alloc_.deallocate(n, 1); } private: friend class Alloc; // access to move ctor Node(){} Node(Node&); Node(Node&& other) { // steal from other... } static Alloc alloc_; }; template<template <typename> class Allocator> typename Node<Allocator>::Alloc Node<Allocator>::alloc_; int main() { Node<>* n = Node<>::Create(); Node<>::Delete(n); return 0; }msvc akzepiert diesen nicht standardkonformen Code. Erst als ich im gcc kompilierte, hab ich dann bemerkt, dass ja Templateparameter nicht als friend deklariert werden können. Hat irgendwer eine andere Idee als den Move ctor public zumachen (der von allocator::construct benötigt wird)?
-
Kommt hier der using Trick zum tragen?
-
theta schrieb:
Kommt hier der using Trick zum tragen?
Hm? Versteh ich nicht. Erklär mal was du meinst.