Skip to content

Simplify instantiated_t by specializing for std::tuple to improve code clarity and reduce compilation time #30

@Kim-J-Smith

Description

@Kim-J-Smith

Hi,

I noticed that instantiated_t is widely used in the codebase. The current implementation works well, but it is somewhat indirect and may introduce unnecessary compilation overhead.

Current implementation:

template <template <class...> class T, class TL, class Is, class... Args>
struct instantiated_traits;
template <template <class...> class T, class TL, std::size_t... Is,
          class... Args>
struct instantiated_traits<T, TL, std::index_sequence<Is...>, Args...>
    : std::type_identity<T<Args..., std::tuple_element_t<Is, TL>...>> {};
template <template <class...> class T, class TL, class... Args>
using instantiated_t = typename instantiated_traits<
    T, TL, std::make_index_sequence<std::tuple_size_v<TL>>, Args...>::type;

Proposed simplified implementation:

template <template <class...> class T, class TL, class... Args>
struct instantiated_traits;
template <template <class...> class T, class... Ts, class... Args>
struct instantiated_traits<T, std::tuple<Ts...>, Args...>
    : std::type_identity<T<Args..., Ts...>> {};
template <template <class...> class T, class TL, class... Args>
using instantiated_t = typename instantiated_traits<T, TL, Args...>::type;

Why this is better:

  • Clearer intent – the code directly expresses "append the types from the tuple".
  • Faster compilation – avoids instantiating std::make_index_sequence and repeated std::tuple_element lookups.
  • Less template bloat – only one partial specialization is needed.

Important prerequisite:
The new version requires that TL is exactly std::tuple<...>. From my analysis of the current codebase, all existing uses of instantiated_t pass a std::tuple (e.g., C::overload_types, F::convention_types, etc.). So this condition holds.

Would you be open to accepting a PR that makes this change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions