4 General utilities library [utilities]

4.1 General [utilities.general]

This clause describes generally useful utilities.
These utilities are summarized in Table 2.
Table 2: General utilities library summary   [tab:utilities.summary]
Subclause
Header
Utility components
<jegp/utility.hpp>

4.2 Utility components [utility]

4.2.1 Header <jegp/utility.hpp> synopsis [utility.syn]

The header <jegp/utility.hpp> contains some basic constructs.
namespace jegp
{
// [utility.underlying], underlying
template <class Enum>
constexpr std::underlying_type_t<Enum> underlying(Enum e) noexcept;

// [static.downcast], static_­downcast
template <class DerivedRef, class Base>
constexpr DerivedRef static_downcast(Base&& base) noexcept;

// [hash.combine], hash_­combine
template <class... Args>
constexpr std::size_t hash_combine(const Args&... args) noexcept(see below);

} // namespace jegp

4.2.2 underlying [utility.underlying]

template <class Enum> constexpr std::underlying_type_t<Enum> underlying(Enum e) noexcept;
Constraints: std​::​is_­enum_­v<Enum> is true.
Returns: static_­cast<std​::​underlying_­type_­t<Enum>>(e).

4.2.3 static_­downcast [static.downcast]

A static_­cast that performs a downcast.
template <class DerivedRef, class Base> constexpr DerivedRef static_downcast(Base&& base) noexcept;
Let derived-ref be static_­cast<DerivedRef>(std​::​forward<Base>(base)).
Constraints:
  • DerivedRef is a reference type,
  • std​::​remove_­cvref_­t<DerivedRef> is derived from std​::​remove_­cvref_­t<Base>, and
  • derived-ref is well-formed.
Preconditions: derived-ref has well-defined behavior.
Returns: derived-ref.

4.2.4 hash_­combine [hash.combine]

Insipred by Boost.ContainerHash.
Useful in the specializations of std​::​hash whose Key's salient parts consist of two or more objects.
template <class... Args> constexpr std::size_t hash_combine(const Args&... args) noexcept(see below);
Constraints:
  • and
  • std​::​hash<T> is enabled (C++ Standard's [unord.hash]) for all T in Args.
Effects: Equivalent to:
std::size_t seed{0};
return (..., (seed ^= std::hash<Args>{}(args) + (seed << 6) + (seed >> 2)));
Remarks: The expression inside noexcept is equivalent to
(noexcept(std::hash<Args>{}(args)) && ...)