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 {
template<class Left, class Right>
class either {
static_assert( std::is_convertible<Left, Right>::value == false
&& std::is_convertible<Right, Left>::value == false,
"Left is not allowed to be convertible to Right");
//static_assert( std::is_convertible<Left, Right>::value == false
// && std::is_convertible<Right, Left>::value == false,
// "Left is not allowed to be convertible to Right");
public:
......@@ -160,6 +160,30 @@ class either {
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:
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