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
ee62b236
Commit
ee62b236
authored
Apr 05, 2012
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
guards
parent
cdd9aa4d
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
470 additions
and
84 deletions
+470
-84
cppa/on.hpp
cppa/on.hpp
+8
-11
cppa/pattern.hpp
cppa/pattern.hpp
+6
-6
cppa/util/apply_tuple.hpp
cppa/util/apply_tuple.hpp
+34
-16
cppa/util/static_foreach.hpp
cppa/util/static_foreach.hpp
+10
-0
src/pattern.cpp
src/pattern.cpp
+1
-1
unit_testing/test__match.cpp
unit_testing/test__match.cpp
+411
-50
No files found.
cppa/on.hpp
View file @
ee62b236
...
...
@@ -80,7 +80,9 @@ class rvalue_builder
typedef
util
::
arg_match_t
arg_match_t
;
typedef
util
::
type_list
<
TypeList
...
>
raw_types
;
typedef
util
::
type_list
<
typename
detail
::
implicit_conversions
<
TypeList
>::
type
...
>
raw_types
;
static
constexpr
bool
is_complete
=
!
std
::
is_same
<
arg_match_t
,
typename
raw_types
::
back
>::
value
;
...
...
@@ -94,12 +96,7 @@ class rvalue_builder
static_assert
(
util
::
tl_find
<
types
,
arg_match_t
>::
value
==
-
1
,
"arg_match is allowed only as last parameter for on()"
);
typedef
typename
util
::
tl_apply
<
types
,
detail
::
implicit_conversions
>::
type
converted_types
;
typedef
typename
pattern_from_type_list
<
converted_types
>::
type
pattern_type
;
typedef
typename
pattern_from_type_list
<
types
>::
type
pattern_type
;
std
::
unique_ptr
<
value_matcher
>
m_vm
;
...
...
@@ -115,11 +112,11 @@ class rvalue_builder
{
using
namespace
::
cppa
::
util
;
typedef
typename
get_callable_trait
<
F
>::
type
ctrait
;
typedef
typename
ctrait
::
arg_types
raw_types
;
typedef
typename
ctrait
::
arg_types
raw_
arg_
types
;
static_assert
(
raw_types
::
size
>
0
,
"functor has no arguments"
);
typedef
typename
tl_apply
<
raw_
types
,
rm_ref
>::
type
new
_types
;
typedef
typename
tl_concat
<
converted_types
,
new_types
>::
type
types
;
typedef
typename
pattern_from_type_list
<
types
>::
type
epattern
;
typedef
typename
tl_apply
<
raw_
arg_types
,
rm_ref
>::
type
arg
_types
;
typedef
typename
tl_concat
<
types
,
arg_types
>::
type
full_
types
;
typedef
typename
pattern_from_type_list
<
full_
types
>::
type
epattern
;
return
get_invokable_impl
<
epattern
>
(
std
::
forward
<
F
>
(
f
),
std
::
move
(
m_vm
));
}
...
...
cppa/pattern.hpp
View file @
ee62b236
...
...
@@ -87,13 +87,13 @@ struct value_matcher
const
bool
is_dummy
;
inline
value_matcher
(
bool
dummy_impl
=
false
)
:
is_dummy
(
dummy_impl
)
{
}
virtual
~
value_matcher
();
virtual
bool
operator
()(
any_tuple
const
&
)
=
0
;
virtual
bool
operator
()(
any_tuple
const
&
)
const
=
0
;
};
struct
dummy_matcher
:
value_matcher
{
inline
dummy_matcher
()
:
value_matcher
(
true
)
{
}
bool
operator
()(
any_tuple
const
&
);
bool
operator
()(
any_tuple
const
&
)
const
;
};
struct
cmp_helper
...
...
@@ -135,7 +135,7 @@ class value_matcher_impl<wildcard_position::nil,
template
<
typename
...
Args
>
value_matcher_impl
(
Args
&&
...
args
)
:
m_values
(
std
::
forward
<
Args
>
(
args
)...)
{
}
bool
operator
()(
any_tuple
const
&
tup
)
bool
operator
()(
any_tuple
const
&
tup
)
const
{
cmp_helper
h
{
tup
};
return
util
::
static_foreach
<
0
,
sizeof
...(
Vs
)
>::
eval
(
m_values
,
h
);
...
...
@@ -177,7 +177,7 @@ class value_matcher_impl<wildcard_position::leading,
template
<
typename
...
Args
>
value_matcher_impl
(
Args
&&
...
args
)
:
m_values
(
std
::
forward
<
Args
>
(
args
)...)
{
}
bool
operator
()(
any_tuple
const
&
tup
)
bool
operator
()(
any_tuple
const
&
tup
)
const
{
cmp_helper
h
{
tup
,
tup
.
size
()
-
sizeof
...(
Ts
)};
return
util
::
static_foreach
<
0
,
sizeof
...(
Vs
)
>::
eval
(
m_values
,
h
);
...
...
@@ -198,7 +198,7 @@ class value_matcher_impl<wildcard_position::in_between,
template
<
typename
...
Args
>
value_matcher_impl
(
Args
&&
...
args
)
:
m_values
(
std
::
forward
<
Args
>
(
args
)...)
{
}
bool
operator
()(
any_tuple
const
&
tup
)
bool
operator
()(
any_tuple
const
&
tup
)
const
{
static
constexpr
size_t
wcpos
=
static_cast
<
size_t
>
(
util
::
tl_find
<
util
::
type_list
<
Ts
...
>
,
anything
>::
value
);
...
...
@@ -225,7 +225,7 @@ class value_matcher_impl<wildcard_position::multiple,
template
<
typename
...
Args
>
value_matcher_impl
(
Args
&&
...)
{
}
bool
operator
()(
any_tuple
const
&
)
bool
operator
()(
any_tuple
const
&
)
const
{
throw
std
::
runtime_error
(
"not implemented yet, sorry"
);
}
...
...
cppa/util/apply_tuple.hpp
View file @
ee62b236
...
...
@@ -31,6 +31,7 @@
#ifndef APPLY_TUPLE_HPP
#define APPLY_TUPLE_HPP
#include "cppa/get.hpp"
#include "cppa/util/enable_if.hpp"
#include "cppa/util/disable_if.hpp"
#include "cppa/util/is_manipulator.hpp"
...
...
@@ -38,40 +39,43 @@
namespace
cppa
{
namespace
util
{
template
<
size_t
...
Range
>
template
<
typename
Result
,
bool
IsManipulator
,
size_t
...
Range
>
struct
apply_tuple_impl
{
template
<
typename
F
,
template
<
typename
...
>
class
Tuple
,
typename
...
T
>
static
auto
apply
(
F
&&
f
,
Tuple
<
T
...
>
const
&
args
,
typename
disable_if
<
is_manipulator
<
F
>
,
int
>::
type
=
0
)
->
typename
get_result_type
<
F
>::
type
static
Result
apply
(
F
&&
f
,
Tuple
<
T
...
>
const
&
args
)
{
return
f
(
get
<
Range
>
(
args
)...);
}
};
template
<
typename
Result
,
size_t
...
Range
>
struct
apply_tuple_impl
<
Result
,
true
,
Range
...
>
{
template
<
typename
F
,
template
<
typename
...
>
class
Tuple
,
typename
...
T
>
static
auto
apply
(
F
&&
f
,
Tuple
<
T
...
>&
args
,
typename
enable_if
<
is_manipulator
<
F
>
,
int
>::
type
=
0
)
->
typename
get_result_type
<
F
>::
type
static
Result
apply
(
F
&&
f
,
Tuple
<
T
...
>&
args
)
{
return
f
(
get_ref
<
Range
>
(
args
)...);
}
};
template
<
int
From
,
int
To
,
int
...
Args
>
struct
apply_tuple_util
:
apply_tuple_util
<
From
,
To
-
1
,
To
,
Args
...
>
template
<
typename
Result
,
bool
IsManipulator
,
int
From
,
int
To
,
int
...
Args
>
struct
apply_tuple_util
:
apply_tuple_util
<
Result
,
IsManipulator
,
From
,
To
-
1
,
To
,
Args
...
>
{
};
template
<
int
X
,
int
...
Args
>
struct
apply_tuple_util
<
X
,
X
,
Args
...
>
:
apply_tuple_impl
<
X
,
Args
...
>
template
<
typename
Result
,
bool
IsManipulator
,
int
X
,
int
...
Args
>
struct
apply_tuple_util
<
Result
,
IsManipulator
,
X
,
X
,
Args
...
>
:
apply_tuple_impl
<
Result
,
IsManipulator
,
X
,
Args
...
>
{
};
template
<
>
struct
apply_tuple_util
<
1
,
0
>
template
<
typename
Result
,
bool
IsManipulator
>
struct
apply_tuple_util
<
Result
,
IsManipulator
,
1
,
0
>
{
template
<
typename
F
,
class
Unused
>
static
auto
apply
(
F
&&
f
,
Unused
const
&
)
->
typename
get_result_type
<
F
>::
type
static
Result
apply
(
F
&&
f
,
Unused
const
&
)
{
return
f
();
}
...
...
@@ -81,6 +85,7 @@ template<typename F, template<typename...> class Tuple, typename... T>
auto
apply_tuple
(
F
&&
fun
,
Tuple
<
T
...
>&
tup
)
->
typename
get_result_type
<
F
>::
type
{
typedef
typename
get_result_type
<
F
>::
type
result_type
;
typedef
typename
get_arg_types
<
F
>::
types
fun_args
;
static
constexpr
size_t
tup_size
=
sizeof
...(
T
);
static_assert
(
tup_size
>=
fun_args
::
size
,
...
...
@@ -88,13 +93,15 @@ auto apply_tuple(F&& fun, Tuple<T...>& tup)
static
constexpr
size_t
args_size
=
fun_args
::
size
;
static
constexpr
size_t
from
=
(
args_size
>
0
)
?
tup_size
-
args_size
:
1
;
static
constexpr
size_t
to
=
(
args_size
>
0
)
?
tup_size
-
1
:
0
;
return
apply_tuple_util
<
from
,
to
>::
apply
(
std
::
forward
<
F
>
(
fun
),
tup
);
return
apply_tuple_util
<
result_type
,
is_manipulator
<
F
>::
value
,
from
,
to
>
::
apply
(
std
::
forward
<
F
>
(
fun
),
tup
);
}
template
<
typename
F
,
template
<
typename
...
>
class
Tuple
,
typename
...
T
>
auto
apply_tuple
(
F
&&
fun
,
Tuple
<
T
...
>
const
&
tup
)
->
typename
get_result_type
<
F
>::
type
{
typedef
typename
get_result_type
<
F
>::
type
result_type
;
typedef
typename
get_arg_types
<
F
>::
types
fun_args
;
static
constexpr
size_t
tup_size
=
sizeof
...(
T
);
static_assert
(
tup_size
>=
fun_args
::
size
,
...
...
@@ -102,7 +109,18 @@ auto apply_tuple(F&& fun, Tuple<T...> const& tup)
static
constexpr
size_t
args_size
=
fun_args
::
size
;
static
constexpr
size_t
from
=
(
args_size
>
0
)
?
tup_size
-
args_size
:
1
;
static
constexpr
size_t
to
=
(
args_size
>
0
)
?
tup_size
-
1
:
0
;
return
apply_tuple_util
<
from
,
to
>::
apply
(
std
::
forward
<
F
>
(
fun
),
tup
);
return
apply_tuple_util
<
result_type
,
is_manipulator
<
F
>::
value
,
from
,
to
>
::
apply
(
std
::
forward
<
F
>
(
fun
),
tup
);
}
template
<
typename
Result
,
typename
F
,
template
<
typename
...
>
class
Tuple
,
typename
...
T
>
Result
unchecked_apply_tuple
(
F
&&
fun
,
Tuple
<
T
...
>&
tup
)
{
static
constexpr
size_t
tup_size
=
sizeof
...(
T
);
static
constexpr
size_t
from
=
0
;
static
constexpr
size_t
to
=
tup_size
-
1
;
return
apply_tuple_util
<
Result
,
false
,
from
,
to
>
::
apply
(
std
::
forward
<
F
>
(
fun
),
tup
);
}
}
}
// namespace cppa::util
...
...
cppa/util/static_foreach.hpp
View file @
ee62b236
...
...
@@ -50,6 +50,12 @@ struct static_foreach_impl
return
f
(
get
<
Begin
>
(
c
))
&&
static_foreach_impl
<
Begin
+
1
,
End
,
(
Begin
+
1
>
End
)
>::
eval
(
c
,
f
);
}
template
<
typename
Container
,
typename
Fun
>
static
inline
bool
eval_or
(
Container
const
&
c
,
Fun
&
f
)
{
return
f
(
get
<
Begin
>
(
c
))
||
static_foreach_impl
<
Begin
+
1
,
End
,
(
Begin
+
1
>
End
)
>::
eval_or
(
c
,
f
);
}
};
template
<
size_t
X
>
...
...
@@ -59,6 +65,8 @@ struct static_foreach_impl<X, X, false>
static
inline
void
_
(
Container
const
&
,
Fun
&
)
{
}
template
<
typename
Container
,
typename
Fun
>
static
inline
bool
eval
(
Container
const
&
,
Fun
&
)
{
return
true
;
}
template
<
typename
Container
,
typename
Fun
>
static
inline
bool
eval_or
(
Container
const
&
,
Fun
&
)
{
return
true
;
}
};
template
<
size_t
X
,
size_t
Y
>
...
...
@@ -68,6 +76,8 @@ struct static_foreach_impl<X, Y, true>
static
inline
void
_
(
Container
const
&
,
Fun
&
)
{
}
template
<
typename
Container
,
typename
Fun
>
static
inline
bool
eval
(
Container
const
&
,
Fun
&
)
{
return
true
;
}
template
<
typename
Container
,
typename
Fun
>
static
inline
bool
eval_or
(
Container
const
&
,
Fun
&
)
{
return
true
;
}
};
/**
...
...
src/pattern.cpp
View file @
ee62b236
...
...
@@ -34,7 +34,7 @@ namespace cppa {
value_matcher
::~
value_matcher
()
{
}
bool
dummy_matcher
::
operator
()(
any_tuple
const
&
)
bool
dummy_matcher
::
operator
()(
any_tuple
const
&
)
const
{
return
true
;
}
...
...
unit_testing/test__match.cpp
View file @
ee62b236
This diff is collapsed.
Click to expand it.
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