Poplar and PopLibs
CallbackTraits.hpp
1// Copyright (c) 2021 Graphcore Ltd. All rights reserved.
2#ifndef poplar_CallbackTraits_hpp
3#define poplar_CallbackTraits_hpp
4
5#include <poplar/ArrayRef.hpp>
6
7#include <type_traits>
8
9namespace poplar {
10namespace traits {
11
12// This fails to evaluate if any element in Args is not a valid type.
13// Otherwise it evaluates to void.
14template <typename... Args> using void_type = void;
15
16// In general terms, not everything is invocable.
17template <typename Result, typename Ret, typename = void>
18struct is_invocable_impl : std::false_type {};
19
20// Specialization for is_invocable_impl used when Result is a valid
21// specialization of std::result_of<...>.
22template <typename Result, typename Ret>
23struct is_invocable_impl<Result, Ret, void_type<typename Result::type>>
24 : std::is_void<Ret> {};
25
26// Provides a boolean constant type that specifies whether or not the type F
27// provides a function call operator that takes a void* argument and returns
28// void.
29template <typename F>
30struct is_callback : is_invocable_impl<std::result_of<F &(void *)>, void> {};
31
32// Provides a boolean constant type that specifies whether or not the type F
33// provides a function call operator that takes a void* argument and returns
34// void.
35template <typename F>
36struct is_host_callback
37 : is_invocable_impl<
38 std::result_of<F &(ArrayRef<const void *>, ArrayRef<void *>)>, void> {
39};
40
41template <typename T>
42struct remove_cvref : std::remove_cv<typename std::remove_reference<T>::type> {
43};
44
45} // namespace traits
46} // namespace poplar
47
48#endif // poplar_CallbackTraits_hpp
References to arrays.
Poplar classes and functions.
Definition: ArrayRef.hpp:14