The "+" (plus) symbol C ++ before the class instance

Helllo, I am reading the following code from Mach7 (which looks great, I wonder why C ++ 17 did not accept it, but this is not the topic ...)

bool operator==(const Term& left, const Term& right)
{
    //std::clog << "(" << left << ',' << right << ')' << std::endl;
    var<std::string> s;
    //var<const Var&>  v;
    var<const Term&> v,t,f;

    Match(left,right)
    {
    Case(C<Var>(s),     C<Var>(+s)     ) return true;
    Case(C<Abs>(&v,&t), C<Abs>(&+v,&+t)) return true;
    Case(C<App>(&f,&t), C<App>(&+f,&+t)) return true;
    Otherwise()                          return false;
    }
    EndMatch

    return false; // To prevent all control path warning
}

(see here )

What does “+ s” mean in the second case of the match? Semantically, this should mean: "do something else, for example, by calling the constructor," but I never saw this syntax.

+4
source share
1 answer

After being deflated (since no class of this type implements unary operator +, I was surprised to learn about it) it seems that they create an operator unary +that they include from equivalence.hpp.

TL DR, in the global namespace, they have the following meanings:

template <typename T>
inline auto operator+(T&& t) noexcept { return true; }

, - .:)

+4

Source: https://habr.com/ru/post/1696241/


All Articles