Got a new skill :P Thanks very much! --- Original Message ---
From: "Stephen Tu" <[email protected]> Sent: January 22, 2015 1:28 AM To: "Ji Wan" <[email protected]> Cc: [email protected] Subject: Re: [protobuf] Can protobuf work with C++ templates? This is not really a protobuf question, moreso a C++ question. But anyways, the typical way to do this is: template <typename T> struct MatrixTraits { }; template <> struct MatrixTraits<double> { typedef DoubleMatrix type; }; template <> struct MatrixTraits<float> { typedef FloatMatrix type; }; template <typename DType> class Matrix { typename MatrixTraits<DType>::type mat_data_; }; On Mon, Jan 19, 2015 at 5:41 PM, Ji Wan <[email protected]> wrote: > Suppose I have two message types `DoubleMatrix` and `FloatMatrix`, and a > template class `Matrix`: > > > message DoubleMatrix { > required uint32 rows = 1; > required uint32 cols = 2; > repeated double data = 3 [packed=true]; > } > > > message FloatMatrix { > required uint32 rows = 1; > required uint32 cols = 2; > repeated float data = 3 [packed=true]; > } > > > template<typename DType> > class Matrix { > MSTType mat_data_; > }; > > > > Is it possible to make `MSTType` as `FloatMatrix` if `DType` is `float`, as > `DoubleMatrix` if `DType` is `double`? > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/protobuf. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
