Ross Bennett — written Dec 25, 2012 — source
The fact that expressions with binary logical operators
x < 4 create a logical sugar expression
(i.e. a LogicalVector type) is very powerful. This enables
one to easily write simple and expressive functions with
a LogicalVector as an argument.
Any of the logical operators
<, <=, >, >=, ==, != can be used
to create a logical sugar expression. The Rcpp sugar
vignette has additional examples of using binary logical operators.
A simple function using just C++ and the STL to count the
number of elements in a vector less than a given number could
be written as follows. While this function is simple, the
downside is that additional functions will have to be
written for other logical operators and other types.
Please see the references for the functional and algorithm
headers for information regarding