With C++ and STL, more options
Data
Z given sets can map to C++ class or primitive types
Z free types can map to C++ enumerations (or ??)
Z variables map to C++ variables
Z set variables map to STL sets (or ??)
Predicates
Testing set membership
if (mySet.find(theValue) != mySet.end()) . . .
Quantifiers
Generally represented by a loop (or STL algorithm equivalent)
For multiple bound variables, use nested loops (or algorithms)
Loop operation
Existential ("exists") quantifier . . .
Initialize result to "false"
Single "successful" case terminates loop with "true"
Universal ("for all") quantifier . . .
Initialize result to "true"
Single "failed" case terminates the loop with "false"
State schemas
Represent by a C++ class?
State variables become C++ data members
What about "invariant" predicates?
May add "AssertValid" member function to test them
Return boolean, or throw exception on failure?
Initialization schemas
Represent by C++ class constructor?
Operation schemas
Represent by C++ class member functions?
How should partial operations be handled?
Option 1: Each partial operation is a separate member function
Implement operation predicates:
Test precondition
Perform actions (but be careful . . .)
Action should be all or nothing, as determined by precondition
Usually no need to explicitly implement "no change" predicates
Combine partial operations with "main" operation member function
If logic is more than simple disjunction, look out for side effects!
Must test that postconditions (invariants applied to result) are OK before storing results
Option 2: Integrate partial operations into one member function
Be careful, and document well
Functions and relations
Can implement in Z style
Perhaps using STL map or multimap, or STL set of pairs
Look up values or perform other set operations
Or, implement directly as C++ function
If function is generated by a Z expression (e.g., lambda) . . .
Function body may implement generating expression