1 #ifndef canvas_Utilities_ensurePointer_h 2 #define canvas_Utilities_ensurePointer_h 13 #include "cetlib_except/demangle.h" 16 #include <type_traits> 20 template <
typename WANTED_POINTER,
typename InputIterator>
24 template <
typename T1,
typename T2>
26 using T1P = std::remove_cv_t<std::remove_pointer_t<T1>>;
27 using T2P = std::remove_cv_t<std::remove_pointer_t<T2>>;
28 static constexpr
bool value{std::is_base_of_v<T1P, T2P> ||
29 std::is_same_v<T1P, T2P>};
32 template <
typename TO,
typename FROM>
34 std::add_pointer_t<std::remove_pointer_t<TO>>>
40 template <
typename TO,
typename FROM>
43 std::add_pointer_t<std::remove_pointer_t<TO>>>
47 std::add_lvalue_reference_t<std::remove_pointer_t<TO>
>>(from);
50 template <
typename TO,
typename FROM>
55 return addr<TO>(from);
60 return addr<TO>(from);
64 template <
typename TO,
typename PFROM>
69 return addr<TO>(*from);
75 template <
typename WANTED_POINTER,
typename InputIterator>
79 static_assert(std::is_pointer_v<WANTED_POINTER>,
80 "Supplied template argument is not a pointer.");
83 typename std::iterator_traits<InputIterator>::value_type>{}(*it);
85 catch (std::bad_cast&) {
87 <<
"Iterator value type " 88 << cet::demangle_symbol(
89 typeid(
typename std::iterator_traits<InputIterator>::value_type)
91 <<
" and wanted pointer type " 92 << cet::demangle_symbol(
typeid(WANTED_POINTER).name())
93 <<
" are incompatible.\n";
std::remove_cv_t< std::remove_pointer_t< T1 >> T1P
constexpr TO operator()(FROM const &from) const
std::remove_cv_t< std::remove_pointer_t< T2 >> T2P
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
constexpr TO operator()(PFROM *from) const
static constexpr bool value
constexpr TO operator()(FROM &from) const
constexpr std::enable_if_t< are_cv_compatible< TO, FROM >::value, std::add_pointer_t< std::remove_pointer_t< TO > > > addr(FROM &from)
WANTED_POINTER ensurePointer(InputIterator it)