Defined in carb/Defines.h

template<class First, class Second, bool = std::is_empty<First>::value && !std::is_final<First>::value>
class EmptyMemberPair : private First

Attempts to invoke the Empty Member Optimization by inheriting from the First element if possible, which, if empty will eliminate the storage necessary for an empty class; the Second element is always stored as a separate member. The First element is inherited from if it is an empty class/struct and is not declared final.

Template Parameters
  • First – The first element of the pair that the pair will inherit from if empty and not final.

  • Second – The second element of the pair that will always be a member.

Public Types

using FirstType = First

Type of the First element.

using SecondType = Second

Type of the Second element.

Public Functions

template<class ...Args2>
inline explicit constexpr EmptyMemberPair(ValueInitFirst, Args2&&... args)

Constructor that default-initializes the First member and passes all arguments to the constructor of Second.


args – arguments passed to the constructor of second.

template<class Arg1, class ...Args2>
inline explicit constexpr EmptyMemberPair(InitBoth, Arg1 &&arg1, Args2&&... args2)

Constructor that initializes both members.

  • arg1 – the argument that is forwarded to the First constructor.

  • args2 – arguments passed to the constructor of second.

inline constexpr FirstType &first() noexcept

Non-const access to First.


a non-const reference to First.

inline constexpr const FirstType &first() const noexcept

Const access to First.


a const reference to First.

Public Members

SecondType second

Direct access to the Second member.