Thanks to visit codestin.com
Credit goes to github.com

Skip to content

cpp 20: use concepts to improve compiler errors for RAJA users #1882

@johnbowen42

Description

@johnbowen42

If a developer calls RAJA::forall with incorrect arguments, the compiler can sometimes emit confusing errors. This could be improved with cpp 20 concepts. For example, here is a concept in the context of RangeSegments

// GOAL: SIMPLIFY COMPILER ERRORS FROM forall
// Define concepts
template<typename ExecPolicy>
concept ExecutionPolicy = requires {
  typename ExecPolicy::policy_tag; // or a RAJA-specific trait check
};

template<typename T>
concept Iterable = requires(T t) {
  std::begin(t);
  std::end(t);
};

template<typename F, typename Index>
concept CallableWithIndex = requires(F f, Index i) {
  { f(i) };
};

// Constrained forall version
template<
  ExecutionPolicy ExecPolicy,
  Iterable Range,
  typename Body
> requires CallableWithIndex<Body, decltype(*std::begin(std::declval<Range>()))>
void forall(ExecPolicy, Range&& range, Body&& body) {
  for (auto i : range) {
    body(i);
  }
}

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