An invariant is something that is assumed to be true. For example, the sole integer member variable of a class called 'OddIntegerNumber' can reasonably be assumed to be an odd number.
- Let a constructor establish an invariant, and throw if it cannot [1]
- Use RAII and exception handlers to maintain invariants [2]
- Design your error-handling strategy around invariants [3]
- Use PODs only when it really is just data and no invariant is meaningful for the data members [4]
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 13.7. Advice. page 387: '[11] Let a constructor establish an invariant, and throw if it cannot'
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 13.7. Advice. page 387: '[18] Use "Resource Acquisition Is Initialization" and exception handlers to maintain invariants'
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 13.7. Advice. page 387: '[20] Design your error-handling strategy around invariants'
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 16.4. Advice. page 479: '[3] Use public data (structs) only when it really is just data and no invariant is meaningful for the data members'