
Tomas :
I like this example. It seems to be more realistic then the previous. The column definition should be indeed local in table definition. Also random-access to result set is rarely required, this solution with cursors will map much better to underlying sql machinery. If I want to fetch records in certain index range I use LIMIT/OFFSET SQL commands.
Unfortunately this : cout << cursor[husband.id] << endl; ...cannot be made to work purely at compile-time. Consider cout << cursor[husband.id] << cursor[wife.id] << endl; Both ids have the same type. Some run-time discrimination would be needed (probably a lookup in a map keyed by the address of the table objects). It is type-safe however. I have ideas for purely compile-time alternatives but the syntax is heavier. OTOH positional access can be purely compile-time, but the syntax would not use brackets, rather tuple-style accessors : cout << cursor.get<0> << endl; // positional : husband.id Incidentally - my real interest is object-relational mapping, but before working on that I'd need a boost sql library. Hence my initial post... J-L