Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
1c883a73
Commit
1c883a73
authored
Apr 16, 2012
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved guard expressions
parent
cf13709e
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
260 additions
and
124 deletions
+260
-124
cppa/detail/projection.hpp
cppa/detail/projection.hpp
+6
-2
cppa/guard_expr.hpp
cppa/guard_expr.hpp
+163
-104
cppa/option.hpp
cppa/option.hpp
+12
-12
unit_testing/test__match.cpp
unit_testing/test__match.cpp
+79
-6
No files found.
cppa/detail/projection.hpp
View file @
1c883a73
...
...
@@ -171,8 +171,12 @@ class projection<util::type_list<> >
template
<
class
PartialFun
>
bool
operator
()(
PartialFun
&
fun
)
const
{
fun
();
return
true
;
if
(
fun
.
defined_at
())
{
fun
();
return
true
;
}
return
false
;
}
};
...
...
cppa/guard_expr.hpp
View file @
1c883a73
This diff is collapsed.
Click to expand it.
cppa/option.hpp
View file @
1c883a73
...
...
@@ -220,45 +220,45 @@ class option
};
/** @relates option */
template
<
typename
T
>
bool
operator
==
(
option
<
T
>
const
&
lhs
,
option
<
T
>
const
&
rhs
)
template
<
typename
T
,
typename
U
>
bool
operator
==
(
option
<
T
>
const
&
lhs
,
option
<
U
>
const
&
rhs
)
{
if
((
lhs
)
&&
(
rhs
))
return
*
lhs
==
*
rhs
;
return
false
;
}
/** @relates option */
template
<
typename
T
>
bool
operator
==
(
option
<
T
>
const
&
lhs
,
T
const
&
rhs
)
template
<
typename
T
,
typename
U
>
bool
operator
==
(
option
<
T
>
const
&
lhs
,
U
const
&
rhs
)
{
if
(
lhs
)
return
*
lhs
==
rhs
;
return
false
;
}
/** @relates option */
template
<
typename
T
>
bool
operator
==
(
T
const
&
lhs
,
option
<
T
>
const
&
rhs
)
template
<
typename
T
,
typename
U
>
bool
operator
==
(
T
const
&
lhs
,
option
<
U
>
const
&
rhs
)
{
return
rhs
==
lhs
;
}
/** @relates option */
template
<
typename
T
>
bool
operator
!=
(
option
<
T
>
const
&
lhs
,
option
<
T
>
const
&
rhs
)
template
<
typename
T
,
typename
U
>
bool
operator
!=
(
option
<
T
>
const
&
lhs
,
option
<
U
>
const
&
rhs
)
{
return
!
(
lhs
==
rhs
);
}
/** @relates option */
template
<
typename
T
>
bool
operator
!=
(
option
<
T
>
const
&
lhs
,
T
const
&
rhs
)
template
<
typename
T
,
typename
U
>
bool
operator
!=
(
option
<
T
>
const
&
lhs
,
U
const
&
rhs
)
{
return
!
(
lhs
==
rhs
);
}
/** @relates option */
template
<
typename
T
>
bool
operator
!=
(
T
const
&
lhs
,
option
<
T
>
const
&
rhs
)
template
<
typename
T
,
typename
U
>
bool
operator
!=
(
T
const
&
lhs
,
option
<
U
>
const
&
rhs
)
{
return
!
(
lhs
==
rhs
);
}
...
...
unit_testing/test__match.cpp
View file @
1c883a73
#include <functional>
#include "test.hpp"
#include "cppa/cppa.hpp"
#include "cppa/on.hpp"
#include "cppa/match.hpp"
#include "cppa/announce.hpp"
...
...
@@ -34,15 +35,19 @@ size_t test__match()
using
namespace
std
::
placeholders
;
using
namespace
cppa
::
placeholders
;
auto
expr0
=
gcall
(
ascending
,
_x1
,
_x2
,
_x3
);
CPPA_CHECK
(
ge_invoke
(
expr0
,
1
,
2
,
3
));
CPPA_CHECK
(
!
ge_invoke
(
expr0
,
3
,
2
,
1
));
auto
expr0
_a
=
gcall
(
ascending
,
_x1
,
_x2
,
_x3
);
CPPA_CHECK
(
ge_invoke
(
expr0
_a
,
1
,
2
,
3
));
CPPA_CHECK
(
!
ge_invoke
(
expr0
_a
,
3
,
2
,
1
));
int
ival0
=
2
;
auto
expr0
1
=
gcall
(
ascending
,
_x1
,
std
::
ref
(
ival0
),
_x2
);
CPPA_CHECK
(
ge_invoke
(
expr0
1
,
1
,
3
));
auto
expr0
_b
=
gcall
(
ascending
,
_x1
,
std
::
ref
(
ival0
),
_x2
);
CPPA_CHECK
(
ge_invoke
(
expr0
_b
,
1
,
3
));
++
ival0
;
CPPA_CHECK
(
!
ge_invoke
(
expr01
,
1
,
3
));
CPPA_CHECK
(
!
ge_invoke
(
expr0_b
,
1
,
3
));
auto
expr0_c
=
gcall
(
ascending
,
10
,
_x1
,
30
);
CPPA_CHECK
(
!
ge_invoke
(
expr0_c
,
10
));
CPPA_CHECK
(
ge_invoke
(
expr0_c
,
11
));
auto
expr1
=
_x1
+
_x2
;
auto
expr2
=
_x1
+
_x2
<
_x3
;
...
...
@@ -106,6 +111,34 @@ size_t test__match()
"wrong return type"
);
CPPA_CHECK_EQUAL
(
42
,
(
ge_invoke
(
expr15
,
7
,
10
,
25
)));
std
::
string
expr16_str
;
// = "expr16";
auto
expr16_a
=
_x1
.
size
();
auto
expr16_b
=
_x1
.
front
()
==
'e'
;
CPPA_CHECK_EQUAL
(
false
,
ge_invoke
(
expr16_b
,
expr16_str
));
CPPA_CHECK_EQUAL
(
0
,
ge_invoke
(
expr16_a
,
expr16_str
));
expr16_str
=
"expr16"
;
CPPA_CHECK_EQUAL
(
true
,
ge_invoke
(
expr16_b
,
expr16_str
));
CPPA_CHECK_EQUAL
(
expr16_str
.
size
(),
ge_invoke
(
expr16_a
,
expr16_str
));
expr16_str
.
front
()
=
'_'
;
CPPA_CHECK_EQUAL
(
false
,
ge_invoke
(
expr16_b
,
expr16_str
));
int
expr17_value
=
42
;
auto
expr17
=
gref
(
expr17_value
)
==
42
;
CPPA_CHECK_EQUAL
(
true
,
ge_invoke
(
expr17
));
expr17_value
=
0
;
CPPA_CHECK_EQUAL
(
false
,
ge_invoke
(
expr17
));
int
expr18_value
=
42
;
auto
expr18_a
=
gref
(
expr18_value
)
==
42
;
CPPA_CHECK_EQUAL
(
true
,
ge_invoke
(
expr18_a
));
expr18_value
=
0
;
CPPA_CHECK_EQUAL
(
false
,
ge_invoke
(
expr18_a
));
auto
expr18_b
=
gref
(
expr18_value
)
==
_x1
;
auto
expr18_c
=
std
::
ref
(
expr18_value
)
==
_x1
;
CPPA_CHECK_EQUAL
(
true
,
ge_invoke
(
expr18_b
,
0
));
CPPA_CHECK_EQUAL
(
true
,
ge_invoke
(
expr18_c
,
0
));
bool
invoked
=
false
;
match
(
"abc"
)
(
...
...
@@ -117,6 +150,46 @@ size_t test__match()
if
(
!
invoked
)
{
CPPA_ERROR
(
"match(
\"
abc
\"
) failed"
);
}
invoked
=
false
;
bool
disable_case1
=
true
;
bool
case1_invoked
=
false
;
bool
case2_invoked
=
false
;
auto
expr19
=
(
on
<
anything
>
().
when
(
gref
(
disable_case1
)
==
false
)
>>
[
&
]()
{
case1_invoked
=
true
;
},
on
<
anything
>
()
>>
[
&
]()
{
case2_invoked
=
true
;
}
);
any_tuple
expr19_tup
=
make_cow_tuple
(
"hello guard!"
);
expr19
(
expr19_tup
);
CPPA_CHECK
(
!
case1_invoked
);
CPPA_CHECK
(
case2_invoked
);
partial_function
expr20
=
expr19
;
case1_invoked
=
false
;
case2_invoked
=
false
;
disable_case1
=
false
;
expr20
(
expr19_tup
);
CPPA_CHECK
(
case1_invoked
);
CPPA_CHECK
(
!
case2_invoked
);
std
::
vector
<
int
>
expr21_vec_a
{
1
,
2
,
3
};
std
::
vector
<
int
>
expr21_vec_b
{
1
,
0
,
2
};
auto
vec_sorted
=
[](
std
::
vector
<
int
>
const
&
vec
)
{
return
std
::
is_sorted
(
vec
.
begin
(),
vec
.
end
());
};
auto
expr21
=
gcall
(
vec_sorted
,
_x1
);
CPPA_CHECK
(
ge_invoke
(
expr21
,
expr21_vec_a
));
CPPA_CHECK
(
!
ge_invoke
(
expr21
,
expr21_vec_b
));
auto
expr22
=
_x1
.
empty
()
&&
_x2
.
not_empty
();
CPPA_CHECK
(
ge_invoke
(
expr22
,
std
::
string
(
""
),
std
::
string
(
"abc"
)));
match
(
std
::
vector
<
int
>
{
1
,
2
,
3
})
(
on
<
int
,
int
,
int
>
().
when
(
_x1
+
_x2
+
_x3
==
6
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment