@@ -11,16 +11,6 @@ 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
@@ -40,48 +30,30 @@ 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_fn {
45- template <typename SdkType>
46- auto operator ()(const SdkType& t) const {
47- using ProtoReturnType = ProtoArgType<to_proto_impl<SdkType>>;
48-
49- ProtoReturnType ret;
50- to_proto_impl<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_fn {
58- template <typename ProtoType>
59- auto operator ()(const ProtoType& proto) const { // NOLINT(misc-no-recursion)
60- return from_proto_impl<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_fn>::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_fn>::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) {
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) {
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.
0 commit comments