File TypeTraits.hpp

namespace Acts

Note

This file is foreseen for the Geometry module to replace Extent

namespace Concepts

Typedefs

using detected_or = detail::detector<Default, void, Op, Args...>

Helper which invokes the detector with a default type, and resolves to the type.

Template Parameters
  • Default – The type to resolve to if Op<Args...> does not resolve.

  • Op – The operation

  • Args – The argument to the operation

using detected_t = typename detail::detector<detail::nonesuch, void, Op, Args...>::type

This type calls into the detector (same as is_detected) but it extracts the return type of Op<Args...>.

Template Parameters
  • Op – The operation

  • Args – The arguments to the operation

using is_detected = typename detail::detector<detail::nonesuch, void, Op, Args...>::value_t

This type ties together the detection idiom.

It instantiates the detector template with the Op and Args and resolves to the exact value type. In essence, if Op<Args...> succeeds, this will evaluate to std::true_type, and if not, it will evaluate to std::false_type.

Template Parameters
  • Op – The operation to test

  • Args – The arguments to the operation

using is_detected_convertible = std::is_convertible<detected_t<Op, Args...>, To>

This evaluates Op inside the detector, and checks whether the resolved type is convertible to To.

Template Parameters
  • To – The type to check convertibility to.

  • Op – The operation

  • Args – The arguments to the operation

using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>

This invokes detected_t, and checks whether its result matches Expected.

Template Parameters
  • Expected – The expected result of the operation.

  • Op – The operation

  • Args – The arguments to the operation

Variables

template<class To, template<class...> class Op, class ...Args>
constexpr bool converts_to = is_detected_convertible<To, Op, Args...>::value

Alias to conversion check, which also extracts the constexpr boolean value.

Template Parameters
  • To – The type to check convertibility to.

  • Op – The operation

  • Args – The arguments to the operation.

template<bool... Bs>
constexpr bool disallow = not require<Bs...>

Alias for the negation of a require.

This is essentially a NOT ANY test.

Template Parameters

Bs – The booleans.

template<bool... Bs>
constexpr bool either = std::disjunction<std::bool_constant<Bs>...>::value

Helper which forms the logical OR of its arguments.

Converts to std::bool_constant.

Template Parameters

Bs – The booleans to combine.

template<template<class...> class Op, class ...Args>
constexpr bool exists = is_detected<Op, Args...>::value

Alias to is_detected which unpacks the constexpr boolean value.

Template Parameters
  • Op – The operation

  • Args – The arguments to the operation.

template<typename T, template<class...> class M, typename V>
constexpr bool has_member = identical_to<V, M, T>

Helper to assert if a member of a given type exists.

Basically only calls into identical_to but is nicer to read.

Template Parameters
  • T – The type to check existence of member on.

  • M – The member type trait

  • V – The type that the member is supposed to have.

template<typename T, typename R, template<class...> class M, typename ...Arguments>
constexpr bool has_method = M<T, R, Arguments...>::template tv<T>::value

Helper which evaluates whether the type T has a method with a given signature.

Template Parameters
  • T – The type to check on. This can contain a const qualifier if you want to check on that.

  • R – The return type

  • M – The method trait, as generated by METHOD_TRAIT

  • Arguments – The argument types that make up the signature.

template<class Exact, template<class...> class Op, class ...Args>
constexpr bool identical_to = is_detected_exact<Exact, Op, Args...>::value

Unpacks the constexpr boolean value from is_detected_exact

Template Parameters
  • Exact – The type to check identity against

  • Op – The operation

  • Args – The arguments to the operation.

template<bool... Bs>
constexpr bool require = std::conjunction<std::bool_constant<Bs>...>::value

Define some sort of “Domain Specific Language” to declare concepts a little more naturally.

These are taken from https://izzys.casa/2016/09/implementing-concepts-in-cxx/ Helper which combines a set of predicates (constexpr bools) with a logical AND. Converts to std::bool_constant.

Template Parameters

Bs – The booleans to combine