5 #ifndef VECTOR_CONVERTER_HPP
6 #define VECTOR_CONVERTER_HPP
8 #include <experimental/type_traits>
14 using unw_t = std::tuple<double, double, double>;
18 #define GENERATE_HAS_MEMBER_FUNC(func, rettype) \
19 template<class T> using _has_##func##fun_chk = \
20 decltype(std::declval<T &>().func()); \
21 template<class T> constexpr bool has_##func##fun_v = \
22 std::experimental::is_detected_convertible_v<rettype, _has_##func##fun_chk, T>;
24 #define GENERATE_HAS_MEMBER(memb, type) \
25 template<class T> using _has_##memb##mem_chk = \
26 decltype(std::declval<T &>().memb); \
27 template<class T> constexpr bool has_##memb##mem_v = \
28 std::experimental::is_detected_convertible_v<type, _has_##memb##mem_chk, T>;
30 GENERATE_HAS_MEMBER_FUNC(x,
double)
31 GENERATE_HAS_MEMBER(x,
double)
33 template<
class T>
using _has_squarebracket_operator_chk = decltype(std::declval<T &>()[0]);
34 template<
class T> constexpr
bool has_squarebracket_operator_v = std::experimental::is_detected_convertible_v<double, _has_squarebracket_operator_chk, T>;
36 template<
class T> constexpr
bool has_xyz_constructor_v = std::experimental::is_constructible_v<T, double, double, double>;
41 template <
typename in_t>
42 std::enable_if_t<has_xfun_v<in_t>, unw_t> convertFrom(
const in_t& in)
44 return {in.x(), in.y(), in.z()};
48 template <
typename in_t>
49 std::enable_if_t<has_xmem_v<in_t>, unw_t> convertFrom(
const in_t& in)
51 return {in.x, in.y, in.z};
55 template <
typename in_t>
56 std::enable_if_t<has_squarebracket_operator_v<in_t> && !has_xfun_v<in_t>, unw_t> convertFrom(
const in_t& in)
58 return {in[0], in[1], in[2]};
62 template <
typename ret_t>
63 std::enable_if_t<has_xyz_constructor_v<ret_t>,
void> convertTo(ret_t& out,
const double x,
const double y,
const double z)
69 template <
typename ret_t>
70 std::enable_if_t<!has_xyz_constructor_v<ret_t> && has_xmem_v<ret_t>,
void> convertTo(ret_t& out,
const double x,
const double y,
const double z)
77 template <
typename ret_t>
78 ret_t convertTo(
const double x,
const double y,
const double z)
81 convertTo(ret, x, y, z);
89 #endif // VECTOR_CONVERTER_HPP