Boost logo

Boost :

From: Marco Servetto (marco.servetto_at_[hidden])
Date: 2007-08-24 12:23:40

Providing alpha-numeric operator with "less less" or "star star" syntax.

Hello, I'm new here,

You surely know that is possible to use operator redefinition to
obtain a syntax like
a -in- b ( or a *in* b)
where -in- is a constant that is used as a alpha-numeric operator.

on the bottom of the mail there is a code that is a simple proof of
concept on how obtain this syntax

I don't know if you have never thought that is possible to use this
syntax to make lot's of much more interesting stuff ( the 'in'
keyword is a simple example...)

For example we can use this solution to implement a compile time
checker for SQL code,
admitting syntax like
Table t=....;
Query q=SELECT-t["name"],t["telephone"]-WHERE-t["surname"]="Smith"-AND-t["age"]>50;

The choose from less less and star star (and other less polish symbols
like &in& or |in| is about operator precedence and must be very

Another idea could be using it on the bind function to obtain a syntax
like myFun-Call(par1,par2,par3,...)

Of course that is only a very little example of what is possible to do
whit this type of syntax.

I have think about this only few days before, and I'm not still
convinced if it is good or no,
but you surely can help me to decide about it.
By Marco.

NOTE: this code is only a proof of concept, lot of optimization can be
added to, like
using In::Binded<T&> when is opportune, and providing ways to generate
other binary operator without redundancy in the code....

using std::vector;

namespace inKeyword{
 class In{
   template<typename T>
   class Binded{
     T binded;
     inline explicit Binded(T binded_):binded(binded_){}
 template<typename T>
 inline In::Binded<T> operator-( T elem,In in){
   return In::Binded<T>(elem);
 template<typename T,typename C>
 inline bool operator-(In::Binded<T> binded, C & v){
   return std::find(v.begin(), v.end(), binded.binded)!=v.end();
 const In in=In();

using inKeyword::in;

int main(){
 vector<int> v;
 bool ris=3-in-v;
 return 0;

Boost list run by bdawes at, gregod at, cpdaniel at, john at