From 46021777714cd08c4fb2a7064f48f292b5e812f3 Mon Sep 17 00:00:00 2001 From: "Victor \"multun\" Collod" Date: Tue, 10 Jul 2018 17:26:16 +0200 Subject: [PATCH] auto: private constructor, maker method --- auto.hh | 8 +++++--- test.cc | 12 +----------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/auto.hh b/auto.hh index 1993f87..e0c1284 100644 --- a/auto.hh +++ b/auto.hh @@ -61,22 +61,24 @@ class Auto { return data_[!data_pos_]; } + Auto() : data_pos_(0) {} public: auto &get_state() { return *cur_data().template get_data(); } - Auto() : data_pos_(0) {} ~Auto() { cur_data().leave(); } template class InitialState, class ...Args> - void initialize(Args&& ...args) { - cur_data().template enter( + static Auto init(Args&& ...args) { + Auto res; + res.cur_data().template enter( std::forward(args)...); + return res; } template class NewState, class ...Args> diff --git a/test.cc b/test.cc index af43b26..24eb3cd 100644 --- a/test.cc +++ b/test.cc @@ -1,15 +1,6 @@ #include "auto.hh" #include -// template -// struct ExInterface; -// template -// struct StateA; -// template -// struct StateB; - - - template struct ExInterface { virtual void callback(Auto &a) = 0; @@ -57,8 +48,7 @@ using trans = TList>; using MyAuto = Auto; int main() { - MyAuto a; - a.template initialize(1); + auto a = MyAuto::template init(1); a.get_state().callback(a); a.get_state().callback(a); }