Skip to content

Idea: concepts for template API #166

Description

@petiaccja

Just from a user perspective, the compiler errors were pretty arcane when I did not provide the right parameters to htile. htile implicitly requires all E&& elements to be derived from class element.

This is the general definition for these functions:

   template <typename... E>
   inline auto htile(E&&... elements)
   {
      using composite = array_composite<sizeof...(elements), htile_element>;
      using container = typename composite::container_type;
      composite r{};
      r = container{{ share(std::forward<E>(elements))... }};
      return r;
   }

It would be possible to add either

  1. an extra template parameter
std::enable_if_t<std::conjunction_v<std::is_convertible<E&, element&>...>, int> = 0
  1. a C++20 concept:
requires std::conjunction_v<std::is_convertible<E&, element&>...>
  1. or a static_assert:
static_assert(std::conjunction_v<std::is_convertible<E&, element&>...>, "All arguments must be convertible to 'element'");
  1. and 2) takes the function out of the overload resolution, so it trips the syntax error highlighting in IDEs right away, which is pretty helpful. 3) at least gives a more useful message on what to fix.

So I'm just throwing this idea in that it may be useful to enforce these conditions more explicitly in the interfaces.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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