1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

Merge pull request #11 from osyo-manga/apply_visitor_bug_fix

fix apply_visitor.
This commit is contained in:
Bolero MURAKAMI 2012-12-18 15:34:24 -08:00
commit 9ee3e03ddd
3 changed files with 18 additions and 6 deletions

View file

@ -170,6 +170,18 @@ namespace testspr {
TESTSPR_ASSERT(var3.which() == 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<<
{

View file

@ -6,7 +6,7 @@
namespace sprout {
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) {
return sprout::forward<Visitable>(visitable).apply_visitor(sprout::forward<Visitor>(visitor));
}

View file

@ -127,14 +127,14 @@ namespace sprout {
template<int I, typename Tuple, typename Visitor>
static SPROUT_CONSTEXPR typename std::enable_if<
I == sizeof...(Types),
typename Visitor::result_type
typename std::decay<Visitor>::type::result_type
>::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>
static SPROUT_CONSTEXPR typename std::enable_if<
I != sizeof...(Types),
typename Visitor::result_type
typename std::decay<Visitor>::type::result_type
>::type visit(Tuple&& t, Visitor&& v, int which) {
return I == which
? sprout::forward<Visitor>(v)(sprout::tuples::get<I>(sprout::forward<Tuple>(t)))
@ -249,11 +249,11 @@ namespace sprout {
}
// visitation support
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_);
}
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_);
}
};