Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

Thread.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/basic.h>
35 #include <ogdf/basic/memory.h>
36 #include <thread>
37 
38 
39 namespace ogdf {
40 
42 
53 class Thread : public std::thread
54 {
55 public:
56  Thread() : thread() { }
57  Thread(Thread &&other) : thread(std::move((thread&&)other)) { }
58 
59  // Visual C++ 2013 Preview cannot compile that combination of variadic templates and lambda function (though it should).
60  // Therefore we use the version without function arguments for MSVC untils this works.
61 #ifdef _MSC_VER
62  template<class Function>
63  explicit Thread(Function && f) : thread([&]{
64  f();
65  OGDF_ALLOCATOR::flushPool();
66  }) { }
67 
68 #else
69  template<class Function, class ... Args>
70  explicit Thread(Function && f, Args && ... args) : thread([&](Args && ... tArgs){
71  f(std::forward<Args>(tArgs)...);
72  OGDF_ALLOCATOR::flushPool();
73  }, std::forward<Args>(args)...) { }
74 #endif
75 
76  Thread &operator=(Thread &&other) {
77  thread::operator=(std::move((thread&&)other));
78  return *this;
79  }
80 };
81 
82 } // end namespace ogdf
Declaration of memory manager for allocating small pieces of memory.
Thread(Thread &&other)
Definition: Thread.h:57
const T & move(const T &v)
Definition: backward.hpp:243
Basic declarations, included by all source files.
Threads supporting OGDF&#39;s memory management.
Definition: Thread.h:53
Thread(Function &&f, Args &&... args)
Definition: Thread.h:70
The namespace for all OGDF objects.
Thread & operator=(Thread &&other)
Definition: Thread.h:76