The empty_member class is in the header file empty_member.h.
When implementing some classes, the objects often need to keep a member object of a template type which may or may not be an empty class. A good example is the STL containers needing to keep copies of their allocator objects, which are normally empty classes.
This will cause wasted space if the classes are empty because the ANSI specification requires member subobjects of class type to have nonzero size [ANSI 9.0.3]. However, the ANSI specification does not require empty base class subobjects to have nonzero size [ANSI 9.0.3, Note 94].
The solution is to bundle the possibly empty class type with another member of the same object whose size is known to be nonzero. This solution was first invented by Nathan C. Myers (www.cantrip.org) and his paper on the subject may be found at http://www.cantrip.org/emptyopt.html.
Base: The (possibly empty) base class that empty_member is to derive from
Member: The (not empty) member class that empty_member is to hold; Member may be a reference type
base_type: The template parameter Base
member_type: The template parameter Member
m: An object of type Member
empty_member(): Initializes the base class and member object with their default constructors.
explicit empty_member(const Base & nb): Initializes the base class with nb and the member object with its default constructor.
explicit empty_member(const Member & nm): [For non-reference types of Member only] Initializes the base class with its default constructor and the member object with nm.
explicit empty_member(Member & nm): [For reference types of Member only] Initializes the base class with its default constructor and the member reference with nm.
empty_member(const Base & nb, const Member & nm): [For non-reference types of Member only] Initializes the base class with nb and the member object with nm.
empty_member(const Base & nb, Member & nm): [For reference types of Member only] Initializes the base class with nb and the member object with nm.
Note: There is an ambiguity danger with the single-parameter constructors; if Base could be the same class as Member, then always use the constructor which takes both arguments.
This technique is used because it is not unusual to have unrelated objects grouped in empty_members.