jpeach commented on code in PR #9482:
URL: https://github.com/apache/trafficserver/pull/9482#discussion_r1252471343


##########
iocore/net/I_NetVConnection.h:
##########
@@ -857,7 +857,20 @@ class NetVConnection : public VConnection, public 
PluginUserArgs<TS_USER_ARGS_VC
   bool has_proxy_protocol(IOBufferReader *);
   bool has_proxy_protocol(char *, int64_t *);
 
+  template <typename S> S *get_service() const;
+

Review Comment:
   I'm not sure that I follow. Something needs to bind the enum to the actual 
concrete type - intrinsically that requires knowing about both the enum values 
and the concrete classes.
   
   People better at metaprograming than me can probably think of something 
cleaner, but here's another approach to mapping the types. You could put it in 
a separate header 
   
   ```C++
   #include <typeinfo>
   #include <iostream>
   #include <cxxabi.h>
   
   class HttpServiceType;
   class SshServiceType;
   class FtpServiceType;
   
   enum class service : int {
       http,
       ssh,
       ftp,
   };
   
   template <service s> struct service_type;
   
   template<> struct service_type<service::http> {
       using type = HttpServiceType;
   };
   
   template<> struct service_type<service::ssh> {
       using type = SshServiceType;
   };
   
   #define typename_of(expr) abi::__cxa_demangle(typeid(expr).name(), nullptr, 
nullptr, nullptr)
   
   int main()
   {
       service_type<service::http>::type * h;
       service_type<service::ssh>::type * s;
   
       std::cout
           << typename_of(h) << "\n"
           << typename_of(s) << "\n";
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to