29 #ifndef PIRANHA_CONVERT_TO_HPP 30 #define PIRANHA_CONVERT_TO_HPP 32 #include <type_traits> 35 #include <piranha/detail/sfinae_types.hpp> 42 template <
typename To,
typename From,
typename =
void>
45 template <
typename From2>
46 using return_type_ = decltype(static_cast<To>(std::declval<const From2 &>()));
47 template <
typename From2>
48 using return_type =
typename std::enable_if<is_returnable<return_type_<From2>>::value, return_type_<From2>>::type;
68 template <
typename From2>
71 return static_cast<To
>(x);
80 template <
typename To,
typename From>
81 using convert_to_enabler =
82 typename std::enable_if<std::is_same<decltype(convert_to_impl<typename std::decay<To>::type, From>{}(
83 std::declval<const From &>())),
84 typename std::decay<To>::type>::value
85 && is_returnable<
typename std::decay<To>::type>::value,
116 template <
typename To,
typename From, detail::convert_to_enabler<To, From> = 0>
127 template <
typename To,
typename From>
130 using Tod =
typename std::decay<To>::type;
131 using Fromd =
typename std::decay<From>::type;
132 template <
typename To1,
typename From1>
133 static auto test(
const To1 &,
const From1 &x) -> decltype(convert_to<To1>(x),
void(), yes());
135 static const bool implementation_defined
136 = std::is_same<decltype(test(std::declval<Tod>(), std::declval<Fromd>())), yes>
::value;
140 static const bool value = implementation_defined;
144 template <
typename To,
typename From>
return_type< From2 > operator()(const From2 &x) const
Call operator.
static const bool value
Value of the type trait.
Type trait to detect piranha::convert_to().
To convert_to(const From &x)
Generic conversion function.
Default functor for the implementation of piranha::convert_to().