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
41839213
Commit
41839213
authored
May 28, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove non-standard operator== for variant<...>
parent
63052d26
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
117 additions
and
47 deletions
+117
-47
libcaf_core/caf/variant.hpp
libcaf_core/caf/variant.hpp
+1
-14
libcaf_core/test/variant.cpp
libcaf_core/test/variant.cpp
+12
-0
libcaf_io/src/basp_broker.cpp
libcaf_io/src/basp_broker.cpp
+2
-2
libcaf_io/test/basp.cpp
libcaf_io/test/basp.cpp
+10
-10
libcaf_io/test/basp_udp.cpp
libcaf_io/test/basp_udp.cpp
+10
-10
libcaf_test/caf/test/unit_test.hpp
libcaf_test/caf/test/unit_test.hpp
+82
-11
No files found.
libcaf_core/caf/variant.hpp
View file @
41839213
...
...
@@ -193,7 +193,7 @@ public:
template
<
int
Pos
>
bool
is
(
std
::
integral_constant
<
int
,
Pos
>
)
const
{
return
type_
==
Pos
;
return
type_
==
static_cast
<
size_t
>
(
Pos
)
;
}
template
<
class
T
>
...
...
@@ -348,19 +348,6 @@ bool operator==(const variant<Ts...>& x, const variant<Ts...>& y) {
return
visit
(
f
,
y
);
}
/// @relates variant
template
<
class
T
,
class
...
Ts
>
bool
operator
==
(
const
T
&
x
,
const
variant
<
Ts
...
>&
y
)
{
variant_compare_helper
<
variant
<
Ts
...
>
,
std
::
equal_to
>
f
{
y
};
return
f
(
x
);
}
/// @relates variant
template
<
class
T
,
class
...
Ts
>
bool
operator
==
(
const
variant
<
Ts
...
>&
x
,
const
T
&
y
)
{
return
y
==
x
;
}
/// @relates variant
template
<
class
...
Ts
>
bool
operator
<
(
const
variant
<
Ts
...
>&
x
,
const
variant
<
Ts
...
>&
y
)
{
...
...
libcaf_core/test/variant.cpp
View file @
41839213
...
...
@@ -138,6 +138,18 @@ struct test_visitor {
}
// namespace <anonymous>
CAF_TEST
(
constructors
)
{
variant
<
int
,
string
>
a
{
42
};
variant
<
string
,
atom_value
>
b
{
atom
(
"foo"
)};
variant
<
float
,
int
,
string
>
c
{
string
{
"bar"
}};
variant
<
int
,
string
,
double
>
d
{
123
};
CAF_CHECK_EQUAL
(
a
,
42
);
CAF_CHECK_EQUAL
(
b
,
atom
(
"foo"
));
CAF_CHECK_EQUAL
(
d
,
123
);
CAF_CHECK_EQUAL
(
d
,
123.0
);
// the unit test framework supports fuzzy compare
CAF_CHECK_NOT_EQUAL
(
d
,
std
::
string
{
"123"
});
}
CAF_TEST
(
n_ary_visit
)
{
variant
<
int
,
string
>
a
{
42
};
variant
<
string
,
atom_value
>
b
{
atom
(
"foo"
)};
...
...
libcaf_io/src/basp_broker.cpp
View file @
41839213
...
...
@@ -490,7 +490,7 @@ void basp_broker_state::cleanup(connection_handle hdl) {
auto
i
=
ctx_tcp
.
find
(
hdl
);
if
(
i
!=
ctx_tcp
.
end
())
{
auto
&
ref
=
i
->
second
;
CAF_ASSERT
(
i
->
first
==
ref
.
hdl
);
CAF_ASSERT
(
i
->
first
==
get
<
connection_handle
>
(
ref
.
hdl
)
);
if
(
ref
.
callback
)
{
CAF_LOG_DEBUG
(
"connection closed during handshake"
);
ref
.
callback
->
deliver
(
sec
::
disconnect_during_handshake
);
...
...
@@ -513,7 +513,7 @@ void basp_broker_state::cleanup(datagram_handle hdl) {
auto
i
=
ctx_udp
.
find
(
hdl
);
if
(
i
!=
ctx_udp
.
end
())
{
auto
&
ref
=
i
->
second
;
CAF_ASSERT
(
i
->
first
==
ref
.
hdl
);
CAF_ASSERT
(
i
->
first
==
get
<
datagram_handle
>
(
ref
.
hdl
)
);
if
(
ref
.
callback
)
{
CAF_LOG_DEBUG
(
"connection closed during handshake"
);
ref
.
callback
->
deliver
(
sec
::
disconnect_during_handshake
);
...
...
libcaf_io/test/basp.cpp
View file @
41839213
...
...
@@ -43,6 +43,16 @@ struct anything { };
anything
any_vals
;
template
<
class
T
>
bool
operator
==
(
anything
,
const
T
&
)
{
return
true
;
}
template
<
class
T
>
bool
operator
==
(
const
T
&
,
anything
)
{
return
true
;
}
template
<
class
T
>
using
maybe
=
caf
::
variant
<
anything
,
T
>
;
...
...
@@ -76,16 +86,6 @@ ostream& operator<<(ostream& out, const maybe<T>& x) {
namespace
caf
{
template
<
class
T
,
class
U
>
bool
operator
==
(
const
maybe
<
T
>&
x
,
const
U
&
y
)
{
return
get_if
<
anything
>
(
&
x
)
!=
nullptr
||
get
<
T
>
(
x
)
==
y
;
}
template
<
class
T
,
class
U
>
bool
operator
==
(
const
T
&
x
,
const
maybe
<
U
>&
y
)
{
return
(
y
==
x
);
}
template
<
class
T
>
std
::
string
to_string
(
const
maybe
<
T
>&
x
)
{
return
!
get_if
<
anything
>
(
&
x
)
?
std
::
string
{
"*"
}
:
deep_to_string
(
get
<
T
>
(
x
));
...
...
libcaf_io/test/basp_udp.cpp
View file @
41839213
...
...
@@ -47,6 +47,16 @@ struct anything { };
anything
any_vals
;
template
<
class
T
>
bool
operator
==
(
anything
,
const
T
&
)
{
return
true
;
}
template
<
class
T
>
bool
operator
==
(
const
T
&
,
anything
)
{
return
true
;
}
template
<
class
T
>
using
maybe
=
caf
::
variant
<
anything
,
T
>
;
...
...
@@ -62,16 +72,6 @@ constexpr auto config_serv_atom = caf::atom("ConfigServ");
namespace
caf
{
template
<
class
T
,
class
U
>
bool
operator
==
(
const
maybe
<
T
>&
x
,
const
U
&
y
)
{
return
get_if
<
anything
>
(
&
x
)
!=
nullptr
||
get
<
T
>
(
x
)
==
y
;
}
template
<
class
T
,
class
U
>
bool
operator
==
(
const
T
&
x
,
const
maybe
<
U
>&
y
)
{
return
(
y
==
x
);
}
template
<
class
T
>
std
::
string
to_string
(
const
maybe
<
T
>&
x
)
{
return
!
get_if
<
anything
>
(
&
x
)
?
std
::
string
{
"*"
}
:
deep_to_string
(
get
<
T
>
(
x
));
...
...
libcaf_test/caf/test/unit_test.hpp
View file @
41839213
...
...
@@ -34,6 +34,7 @@
#include "caf/logger.hpp"
#include "caf/optional.hpp"
#include "caf/term.hpp"
#include "caf/variant.hpp"
#include "caf/detail/arg_wrapper.hpp"
...
...
@@ -51,12 +52,24 @@ struct negated {
}
};
struct
equal_to
{
template
<
class
T
,
class
Comparator
>
struct
compare_visitor
{
const
T
&
rhs
;
template
<
class
U
>
bool
operator
()(
const
U
&
lhs
)
const
{
Comparator
f
;
return
f
(
lhs
,
rhs
);
}
};
struct
equality_operator
{
template
<
class
T
,
class
U
,
typename
std
::
enable_if
<
std
::
is_floating_point
<
T
>
::
value
||
std
::
is_floating_point
<
U
>::
value
,
typename
std
::
enable_if
<
(
std
::
is_floating_point
<
T
>
::
value
||
std
::
is_floating_point
<
U
>::
value
)
&&
detail
::
is_comparable
<
T
,
U
>::
value
,
int
>::
type
=
0
>
bool
operator
()(
const
T
&
t
,
const
U
&
u
)
{
bool
operator
()(
const
T
&
t
,
const
U
&
u
)
const
{
auto
x
=
static_cast
<
long
double
>
(
t
);
auto
y
=
static_cast
<
long
double
>
(
u
);
auto
max
=
std
::
max
(
std
::
abs
(
x
),
std
::
abs
(
y
));
...
...
@@ -66,22 +79,80 @@ struct equal_to {
template
<
class
T
,
class
U
,
typename
std
::
enable_if
<!
std
::
is_floating_point
<
T
>
::
value
&&
!
std
::
is_floating_point
<
U
>::
value
,
&&
!
std
::
is_floating_point
<
U
>::
value
&&
detail
::
is_comparable
<
T
,
U
>::
value
,
int
>::
type
=
0
>
bool
operator
()(
const
T
&
x
,
const
U
&
y
)
{
bool
operator
()(
const
T
&
x
,
const
U
&
y
)
const
{
return
x
==
y
;
}
template
<
class
T
,
class
U
,
typename
std
::
enable_if
<!
detail
::
is_comparable
<
T
,
U
>
::
value
,
int
>::
type
=
0
>
bool
operator
()(
const
T
&
,
const
U
&
)
const
{
return
false
;
}
};
// note: we could use negated<equal_to>, but that would give us `!(x == y)`
// instead of `x != y` and thus messes with coverage testing
struct
not_equal_to
{
template
<
class
T
,
class
U
>
bool
operator
()(
const
T
&
x
,
const
U
&
y
)
{
struct
inequality_operator
{
template
<
class
T
,
class
U
,
typename
std
::
enable_if
<
(
std
::
is_floating_point
<
T
>
::
value
||
std
::
is_floating_point
<
U
>::
value
)
&&
detail
::
is_comparable
<
T
,
U
>::
value
,
int
>::
type
=
0
>
bool
operator
()(
const
T
&
x
,
const
U
&
y
)
const
{
equality_operator
f
;
return
!
f
(
x
,
y
);
}
template
<
class
T
,
class
U
,
typename
std
::
enable_if
<!
std
::
is_floating_point
<
T
>
::
value
&&
!
std
::
is_floating_point
<
U
>::
value
&&
detail
::
is_comparable
<
T
,
U
>::
value
,
int
>::
type
=
0
>
bool
operator
()(
const
T
&
x
,
const
U
&
y
)
const
{
return
x
!=
y
;
}
template
<
class
T
,
class
U
,
typename
std
::
enable_if
<!
detail
::
is_comparable
<
T
,
U
>
::
value
,
int
>::
type
=
0
>
bool
operator
()(
const
T
&
,
const
U
&
)
const
{
return
true
;
}
};
template
<
class
Operator
>
struct
comparison
{
// -- default case -----------------------------------------------------------
template
<
class
T
,
class
U
>
detail
::
enable_if_t
<!
SumType
<
T
>
()
&&
!
SumType
<
U
>
(),
bool
>
operator
()(
const
T
&
x
,
const
U
&
y
)
{
Operator
f
;
return
f
(
x
,
y
);
}
// -- automagic unboxing of sum types ----------------------------------------
template
<
class
T
,
class
U
>
detail
::
enable_if_t
<
SumType
<
T
>
(),
bool
>
operator
()(
const
T
&
lhs
,
const
U
&
rhs
)
const
{
compare_visitor
<
U
,
comparison
>
f
{
rhs
};
return
visit
(
f
,
lhs
);
}
template
<
class
T
,
class
U
>
detail
::
enable_if_t
<!
SumType
<
T
>
()
&&
SumType
<
U
>
(),
bool
>
operator
()(
const
T
&
lhs
,
const
U
&
rhs
)
const
{
return
(
*
this
)(
rhs
,
lhs
);
}
};
using
equal_to
=
comparison
<
equality_operator
>
;
using
not_equal_to
=
comparison
<
inequality_operator
>
;
struct
less_than
{
template
<
class
T
,
class
U
>
bool
operator
()(
const
T
&
x
,
const
U
&
y
)
{
...
...
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