@@ -11,27 +11,17 @@ namespace sdk {
1111
1212namespace proto_convert_details {
1313
14- // This is copied from range-v3 to allow the definition of callable object instances without
15- // ODR/linkage issues. It is obviated in C++17 and onwards by constexpr inline.
16- template <typename T>
17- struct static_const {
18- static constexpr const T value{};
19- };
20-
21- template <typename T>
22- constexpr const T static_const<T>::value;
23-
2414// This struct should be explicitly specialized with a
2515// void operator()(const SdkType&, common::v1::ApiType*) const
2616// to provide API/ABI insulated proto conversion
2717template <typename SdkType>
28- struct to_proto ;
18+ struct to_proto_impl ;
2919
3020// This struct should be explicitly specialized with a
3121// SdkType operator()(const ProtoType*) const
3222// to provided API/ABI insulated construction from proto
3323template <typename ProtoType>
34- struct from_proto ;
24+ struct from_proto_impl ;
3525
3626// This is a helper type trait for deducing corresponding API types from a to_proto specialization.
3727// We use boost::callable_traits to generate a tuple of the arguments to the to_proto call operator,
@@ -40,60 +30,42 @@ template <typename Callable>
4030using ProtoArgType = std::remove_pointer_t <
4131 boost::mp11::mp_back<boost::callable_traits::args_t <Callable, boost::mp11::mp_list>>>;
4232
43- // Implementation struct for the omni-to_proto callable defined below.
44- struct to_proto_impl {
45- template <typename SdkType>
46- auto operator ()(const SdkType& t) const {
47- using ProtoReturnType = ProtoArgType<to_proto<SdkType>>;
48-
49- ProtoReturnType ret;
50- to_proto<SdkType>{}(t, &ret);
51-
52- return ret;
53- }
54- };
55-
56- // Implementation struct for the omni-from_proto callable defined below.
57- struct from_proto_impl {
58- template <typename ProtoType>
59- auto operator ()(const ProtoType& proto) const { // NOLINT(misc-no-recursion)
60- return from_proto<ProtoType>{}(&proto);
61- }
62- };
63-
6433} // namespace proto_convert_details
6534
66- namespace v2 {
67-
68- namespace {
69-
70- // / @brief Function object implementing conversion from an SDK type to an API type.
71- // / This callable works for any type with a proto_convert_details::to_proto specialization as
72- // / described above.
73- constexpr auto & to_proto =
74- proto_convert_details::static_const<proto_convert_details::to_proto_impl>::value;
75-
76- // / @brief Function object implementing conversion from an API type to an SDK type.
77- // / This callable works for any type with a proto_convert_details::from_proto specialization as
78- // / described above.
79- constexpr auto & from_proto =
80- proto_convert_details::static_const<proto_convert_details::from_proto_impl>::value;
81-
82- } // namespace
83-
84- } // namespace v2
35+ // / @brief Convert an SDK type to its corresponding API type.
36+ // / @remark Only participates in overload resolution if to_proto_impl<SdkType> has been specialized.
37+ template <typename SdkType,
38+ typename = decltype (sizeof (proto_convert_details::to_proto_impl<SdkType>))>
39+ auto to_proto (const SdkType& t) { // NOLINT(misc-no-recursion)
40+ namespace pcd = proto_convert_details;
41+ using ProtoReturnType = pcd::ProtoArgType<pcd::to_proto_impl<SdkType>>;
42+
43+ ProtoReturnType ret;
44+ pcd::to_proto_impl<SdkType>{}(t, &ret);
45+
46+ return ret;
47+ }
48+
49+ // / @brief Convert an API type to its corresponding SDK type.
50+ // / @remark Only participates in overload resolution if from_proto_impl<ApiType> has been
51+ // / specialized.
52+ template <typename ApiType,
53+ typename = decltype (sizeof (proto_convert_details::from_proto_impl<ApiType>))>
54+ auto from_proto (const ApiType& proto) { // NOLINT(misc-no-recursion)
55+ return proto_convert_details::from_proto_impl<ApiType>{}(&proto);
56+ }
8557
8658// / @brief Type alias for the API type corresponding to a given SDK type.
8759// / This is the return type of calling to_proto on an instance of SdkType.
8860template <typename SdkType>
8961using EquivalentApiType =
90- proto_convert_details::ProtoArgType<proto_convert_details::to_proto <SdkType>>;
62+ proto_convert_details::ProtoArgType<proto_convert_details::to_proto_impl <SdkType>>;
9163
9264// / @brief Type alias for the SDK type corresponding to a given API type.
9365// / This is the return type of calling from_proto on an instance of ApiType.
9466template <typename ApiType>
9567using EquivalentSdkType =
96- boost::callable_traits::return_type_t <proto_convert_details::from_proto <ApiType>>;
68+ boost::callable_traits::return_type_t <proto_convert_details::from_proto_impl <ApiType>>;
9769
9870} // namespace sdk
9971} // namespace viam
0 commit comments