Skip to content

Commit

Permalink
auto: private constructor, maker method
Browse files Browse the repository at this point in the history
  • Loading branch information
multun committed Jul 10, 2018
1 parent 7629405 commit 4602177
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
8 changes: 5 additions & 3 deletions auto.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,24 @@ class Auto {
return data_[!data_pos_];
}

Auto() : data_pos_(0) {}

public:
auto &get_state() {
return *cur_data().template get_data<intf_t>();
}

Auto() : data_pos_(0) {}

~Auto() {
cur_data().leave();
}

template<template<class> class InitialState, class ...Args>
void initialize(Args&& ...args) {
cur_data().template enter<InitialState, Args...>(
static Auto init(Args&& ...args) {
Auto res;
res.cur_data().template enter<InitialState, Args...>(
std::forward<Args>(args)...);
return res;
}

template<template<class> class NewState, class ...Args>
Expand Down
12 changes: 1 addition & 11 deletions test.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#include "auto.hh"
#include <iostream>

// template<class ...States>
// struct ExInterface;
// template<class ...States>
// struct StateA;
// template<class ...States>
// struct StateB;



template<class Auto>
struct ExInterface {
virtual void callback(Auto &a) = 0;
Expand Down Expand Up @@ -57,8 +48,7 @@ using trans = TList<TPair<StateB, StateA>>;
using MyAuto = Auto<ExInterface, trans, StateA, StateB>;

int main() {
MyAuto a;
a.template initialize<StateB>(1);
auto a = MyAuto::template init<StateB>(1);
a.get_state().callback(a);
a.get_state().callback(a);
}

0 comments on commit 4602177

Please sign in to comment.