mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
fix apply_visitor.
This commit is contained in:
parent
8b80b159c8
commit
16e7ddf0bf
3 changed files with 18 additions and 6 deletions
|
@ -170,6 +170,18 @@ namespace testspr {
|
||||||
TESTSPR_ASSERT(var3.which() == 0);
|
TESTSPR_ASSERT(var3.which() == 0);
|
||||||
TESTSPR_ASSERT(sprout::get<int>(var3) == 0);
|
TESTSPR_ASSERT(sprout::get<int>(var3) == 0);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
testspr::x2_visitor<double> visitor1 = {};
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::apply_visitor(visitor1, var1) == 2.0);
|
||||||
|
TESTSPR_BOTH_ASSERT(sprout::apply_visitor(visitor1, var2) == 0.0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto var3 = var2;
|
||||||
|
testspr::x2_assign_visitor<double> visitor1 = {};
|
||||||
|
TESTSPR_ASSERT(sprout::apply_visitor(visitor1, var3) == 0.0);
|
||||||
|
TESTSPR_ASSERT(var3.which() == 0);
|
||||||
|
TESTSPR_ASSERT(sprout::get<int>(var3) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
// operator<<
|
// operator<<
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
template<typename Visitor, typename Visitable>
|
template<typename Visitor, typename Visitable>
|
||||||
inline SPROUT_CONSTEXPR typename Visitor::result_type
|
inline SPROUT_CONSTEXPR typename std::decay<Visitor>::type::result_type
|
||||||
apply_visitor(Visitor&& visitor, Visitable&& visitable) {
|
apply_visitor(Visitor&& visitor, Visitable&& visitable) {
|
||||||
return sprout::forward<Visitable>(visitable).apply_visitor(sprout::forward<Visitor>(visitor));
|
return sprout::forward<Visitable>(visitable).apply_visitor(sprout::forward<Visitor>(visitor));
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,14 +127,14 @@ namespace sprout {
|
||||||
template<int I, typename Tuple, typename Visitor>
|
template<int I, typename Tuple, typename Visitor>
|
||||||
static SPROUT_CONSTEXPR typename std::enable_if<
|
static SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
I == sizeof...(Types),
|
I == sizeof...(Types),
|
||||||
typename Visitor::result_type
|
typename std::decay<Visitor>::type::result_type
|
||||||
>::type visit(Tuple&& t, Visitor&& v, int which) {
|
>::type visit(Tuple&& t, Visitor&& v, int which) {
|
||||||
return typename Visitor::result_type();
|
return typename std::decay<Visitor>::type::result_type();
|
||||||
}
|
}
|
||||||
template<int I, typename Tuple, typename Visitor>
|
template<int I, typename Tuple, typename Visitor>
|
||||||
static SPROUT_CONSTEXPR typename std::enable_if<
|
static SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
I != sizeof...(Types),
|
I != sizeof...(Types),
|
||||||
typename Visitor::result_type
|
typename std::decay<Visitor>::type::result_type
|
||||||
>::type visit(Tuple&& t, Visitor&& v, int which) {
|
>::type visit(Tuple&& t, Visitor&& v, int which) {
|
||||||
return I == which
|
return I == which
|
||||||
? sprout::forward<Visitor>(v)(sprout::tuples::get<I>(sprout::forward<Tuple>(t)))
|
? sprout::forward<Visitor>(v)(sprout::tuples::get<I>(sprout::forward<Tuple>(t)))
|
||||||
|
@ -249,11 +249,11 @@ namespace sprout {
|
||||||
}
|
}
|
||||||
// visitation support
|
// visitation support
|
||||||
template<typename Visitor>
|
template<typename Visitor>
|
||||||
SPROUT_CONSTEXPR typename Visitor::result_type apply_visitor(Visitor&& visitor) const {
|
SPROUT_CONSTEXPR typename std::decay<Visitor>::type::result_type apply_visitor(Visitor&& visitor) const {
|
||||||
return visit<0>(tuple_, sprout::forward<Visitor>(visitor), which_);
|
return visit<0>(tuple_, sprout::forward<Visitor>(visitor), which_);
|
||||||
}
|
}
|
||||||
template<typename Visitor>
|
template<typename Visitor>
|
||||||
typename Visitor::result_type apply_visitor(Visitor&& visitor) {
|
typename std::decay<Visitor>::type::result_type apply_visitor(Visitor&& visitor) {
|
||||||
return visit<0>(tuple_, sprout::forward<Visitor>(visitor), which_);
|
return visit<0>(tuple_, sprout::forward<Visitor>(visitor), which_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue