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
964a41f5
Commit
964a41f5
authored
Apr 03, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prototyping
parent
704aa400
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
0 deletions
+112
-0
unit_testing/test__match.cpp
unit_testing/test__match.cpp
+112
-0
No files found.
unit_testing/test__match.cpp
View file @
964a41f5
...
...
@@ -11,10 +11,122 @@ using namespace cppa;
using
std
::
vector
;
using
std
::
string
;
template
<
typename
T
>
std
::
function
<
bool
(
T
const
&
)
>
is_any_of
(
std
::
vector
<
T
>
vec
)
{
return
[
=
](
T
const
&
value
)
{
return
std
::
any_of
(
vec
.
begin
(),
vec
.
end
(),
[
&
](
T
const
&
v
)
{
return
value
==
v
;
});
};
}
template
<
typename
T
>
std
::
function
<
bool
(
T
const
&
)
>
is_none_of
(
std
::
vector
<
T
>
vec
)
{
return
[
=
](
T
const
&
value
)
{
return
std
::
none_of
(
vec
.
begin
(),
vec
.
end
(),
[
&
](
T
const
&
v
)
{
return
value
==
v
;
});
};
}
struct
placeholder
{
constexpr
placeholder
()
{
}
template
<
typename
T
>
std
::
function
<
bool
(
T
const
&
)
>
operator
<
(
T
const
&
value
)
const
{
return
[
=
](
T
const
&
other
)
{
return
other
<
value
;
};
}
template
<
typename
T
>
std
::
function
<
bool
(
T
const
&
)
>
operator
<=
(
T
const
&
value
)
const
{
return
[
=
](
T
const
&
other
)
{
return
other
<=
value
;
};
}
template
<
typename
T
>
std
::
function
<
bool
(
T
const
&
)
>
operator
>
(
T
const
&
value
)
const
{
return
[
=
](
T
const
&
other
)
{
return
other
>
value
;
};
}
template
<
typename
T
>
std
::
function
<
bool
(
T
const
&
)
>
operator
>=
(
T
const
&
value
)
const
{
return
[
=
](
T
const
&
other
)
{
return
other
>=
value
;
};
}
template
<
typename
T
>
std
::
function
<
bool
(
T
const
&
)
>
operator
==
(
T
const
&
value
)
const
{
return
[
=
](
T
const
&
other
)
{
return
other
==
value
;
};
}
template
<
typename
T
>
std
::
function
<
bool
(
T
const
&
)
>
operator
!=
(
T
const
&
value
)
const
{
return
[
=
](
T
const
&
other
)
{
return
other
!=
value
;
};
}
template
<
typename
T
>
std
::
function
<
bool
(
T
const
&
)
>
any_of
(
std
::
vector
<
T
>
vec
)
const
{
return
[
=
](
T
const
&
value
)
{
return
std
::
any_of
(
vec
.
begin
(),
vec
.
end
(),
[
&
](
T
const
&
v
)
{
return
value
==
v
;
});
};
}
template
<
typename
T
>
std
::
function
<
bool
(
typename
detail
::
implicit_conversions
<
T
>::
type
const
&
)
>
any_of
(
std
::
initializer_list
<
T
>
list
)
const
{
typedef
typename
detail
::
implicit_conversions
<
T
>::
type
ctype
;
vector
<
ctype
>
vec
;
for
(
auto
&
i
:
list
)
vec
.
emplace_back
(
i
);
//vec.insert(vec.begin(), list.begin(), list.end());
return
[
vec
](
ctype
const
&
value
)
{
return
std
::
any_of
(
vec
.
begin
(),
vec
.
end
(),
[
&
](
ctype
const
&
v
)
{
return
value
==
v
;
});
};
}
template
<
typename
T
>
std
::
function
<
bool
(
T
const
&
)
>
none_of
(
std
::
vector
<
T
>
vec
)
const
{
return
[
=
](
T
const
&
value
)
{
return
std
::
none_of
(
vec
.
begin
(),
vec
.
end
(),
[
&
](
T
const
&
v
)
{
return
value
==
v
;
});
};
}
};
static
constexpr
placeholder
_x
;
template
<
typename
...
Args
>
void
_on
(
Args
&&
...)
{
}
size_t
test__match
()
{
CPPA_TEST
(
test__match
);
auto
xfun
=
_x
.
any_of
<
int
>
({
1
,
2
,
3
});
cout
<<
"xfun(4) = "
<<
xfun
(
4
)
<<
endl
;
cout
<<
"xfun(2) = "
<<
xfun
(
2
)
<<
endl
;
auto
lfun
=
_x
<
5
;
cout
<<
"lfun(4) = "
<<
lfun
(
4
)
<<
endl
;
cout
<<
"lfun(6) = "
<<
lfun
(
6
)
<<
endl
;
cout
<<
"sizeof(std::function<bool (int const&)>) = "
<<
sizeof
(
std
::
function
<
bool
(
int
const
&
)
>
)
<<
endl
;
_on
(
_x
.
any_of
({
"-h"
,
"--help"
}),
_x
==
5
);
auto
hfun
=
_x
.
any_of
({
"-h"
,
"--help"
});
cout
<<
"hfun(-h) = "
<<
hfun
(
"-h"
)
<<
endl
;
cout
<<
"hfun(-r) = "
<<
hfun
(
"-r"
)
<<
endl
;
bool
invoked
=
false
;
match
(
"abc"
)
(
...
...
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