Boost logo

Boost :

From: Robert Dailey (rcdailey_at_[hidden])
Date: 2008-03-17 09:54:15


On Sun, Mar 16, 2008 at 9:30 PM, Sean Hunt <rideau3_at_[hidden]> wrote:

> Robert Dailey wrote:
> > On Sun, Mar 16, 2008 at 5:44 PM, Eric Niebler <eric_at_[hidden]
> >
> > wrote:
> >
> >> I've made a small addition ... the formatter can be a lambda, too, if
> >> you #include <boost/xpressive/regex_actions.hpp>. The above can now be
> >> written simply as:
> >>
> >> using xpressive::ref;
> >> string output = regex_replace(input, rx, ref(replacements)[_]);
> >>
> >> Here, "_" gets substituted with a sub_match representing the current
> >> match. You can also use s1, s2, etc., to access the other sub-matches.
> >>
> >
> >
> > How is "[_]" legal C++ syntax?
> > _______________________________________________
> > Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
> >
> "_" is just an identifier, so "[_]" is calling the [] operator with the
> parameter being whatever "_" refers to. In this case, it allows for the
> creation of lambda expressions.

Wow, I have never created a variable without alphabetic characters in it
before. I never considered for a minute that '_' would be a legal variable
name, just as a variable starting with numbers isn't legal. Now that you've
explained it, it seems pretty obvious. The syntax itself just threw me off
:)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk