History of normal type in C++
The ideas of regular data in C++ have a long and instructive history.
Articles in this series
- struct from C
- C copy
- C++ constructor, destructor and class
- Default constructor
- C++ copy
- Exception safety, noexcept
- C++ equality and order (first attempt)
- Templates and STL
- C++ move rationale
- Rule of three and composing
- Regular: syntax and semantics
- History of concepts in C++
- The many relations
- History of the three-way comparison, aka the spaceship operator
- Pragmatic Regular structs
- Regular wannabes
- The future of regular
- Efficiency and the things we know
Also see the above in presentation form
Introduction
Consider this type, person
that I introduced recently in the
series of articles on programming idioms.
1
2
3
4
5
6
7
8
9
struct person
{
std::string first_name;
std::string last_name;
int age{};
constexpr std::strong_ordering
operator<=>(const person &) const noexcept = default;
};
I called this a regular data type. Regular is another name for normal, usual.
person
is type that holds some data related to a person. Behind it’s relative
simplicity it’s a very flexible type: it can be copied, moved, compared for
equality and order, it will not leak memory.
Regularity is really the benchmark on which other types will be judged i.e. “this other type really can’t be regular because …”
In this series of articles I’m going to cover what I know about the history of the design supporting regular data types. The history is long and contains interesting deliberate and accidental events.
It is a selective history, so that if we look at the types like the
person
above we can remember: “this is like this because of this
reason/choice/accident”.
References
Again, a lot of the ideas in this series of articles come from Elements of Programming by Alexander Stepanov and Paul McJones, from comments done by Alexander Stepanov in recordings published on Youtube and from reading carefully some C++ committee papers.
The “Design and Evolution of C++” by Bjarne Stroustrup is an important source for how ideas that lead to C++ from C came to be. It does stop at about 1994, so it does not cover later developments.