Commit 1e3fb346 authored by Dominik Charousset's avatar Dominik Charousset

be less restrictive on either's template parameters and added two inspection functions

parent 53a2fca5
...@@ -44,9 +44,9 @@ namespace cppa { ...@@ -44,9 +44,9 @@ namespace cppa {
template<class Left, class Right> template<class Left, class Right>
class either { class either {
static_assert( std::is_convertible<Left, Right>::value == false //static_assert( std::is_convertible<Left, Right>::value == false
&& std::is_convertible<Right, Left>::value == false, // && std::is_convertible<Right, Left>::value == false,
"Left is not allowed to be convertible to Right"); // "Left is not allowed to be convertible to Right");
public: public:
...@@ -160,6 +160,30 @@ class either { ...@@ -160,6 +160,30 @@ class either {
return m_right; return m_right;
} }
template<typename F>
void apply(const F& fun) {
if (is_left()) fun(left());
else fun(right());
}
template<typename F>
void apply(const F& fun) const {
if (is_left()) fun(left());
else fun(right());
}
template<typename Result, typename F>
Result inspect(const F& fun) {
if (is_left()) return fun(left());
else return fun(right());
}
template<typename Result, typename F>
Result inspect(const F& fun) const {
if (is_left()) return fun(left());
else return fun(right());
}
private: private:
bool m_is_left; bool m_is_left;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment