Scalar Subqueries

If q is a query with value type T, and if:

then scalar(q) builds and returns an exprn_mapper<T>, which executes by executing q and taking q's output as its value.

In this context, q is known as a scalar subquery.

Scalar subqueries (like the subqueries that we pass to exists()) are allowed to use mappers that belong to an outer context.

We saw a typical use of scalar() in the introduction:

score(const exprn_mapper<serial> &movie_id) {
    return scalar(
        .where(critics->favorite_movie == movie_id)

It is typical in these ways:

The example also shows a typical feature of my coding style: When I'm building a query that depends on an outer context to provide a mapper, I write a C++ function for the purpose, with an argument to advertise the dependency.