summaryrefslogtreecommitdiff
path: root/include/mbgl
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-07-21 12:32:13 +0300
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-07-24 19:30:02 +0300
commit5ee05a7781396004cb617002b6cbe8b7402616a6 (patch)
tree42ebf5c06b1cb71a05f4386ee557fcf922eb65f5 /include/mbgl
parent81e9ed7fdd65ca4816ac6a76139d6c18d5182a21 (diff)
downloadqtlocation-mapboxgl-5ee05a7781396004cb617002b6cbe8b7402616a6.tar.gz
[core] make actor self reference optional
Diffstat (limited to 'include/mbgl')
-rw-r--r--include/mbgl/actor/actor.hpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/include/mbgl/actor/actor.hpp b/include/mbgl/actor/actor.hpp
index 00e1bb82f8..74d5a66285 100644
--- a/include/mbgl/actor/actor.hpp
+++ b/include/mbgl/actor/actor.hpp
@@ -7,6 +7,7 @@
#include <memory>
#include <future>
+#include <type_traits>
namespace mbgl {
@@ -47,10 +48,21 @@ namespace mbgl {
template <class Object>
class Actor : public util::noncopyable {
public:
- template <class... Args>
+
+ // Enabled for Objects with a constructor taking ActorRef<Object> as the first parameter
+ template <typename U = Object, class... Args,
+ typename std::enable_if<std::is_constructible<U, ActorRef<Object>, Args...>::value>::type...>
+ Actor(Scheduler& scheduler, Args&&... args_)
+ : mailbox(std::make_shared<Mailbox>(scheduler)),
+ object(self(), std::forward<Args>(args_)...) {
+ }
+
+ // Enabled for plain Objects
+ template <typename U = Object, class... Args,
+ typename std::enable_if<!std::is_constructible<U, ActorRef<Object>, Args...>::value>::type...>
Actor(Scheduler& scheduler, Args&&... args_)
- : mailbox(std::make_shared<Mailbox>(scheduler)),
- object(self(), std::forward<Args>(args_)...) {
+ : mailbox(std::make_shared<Mailbox>(scheduler)),
+ object(std::forward<Args>(args_)...) {
}
~Actor() {