> On Sept. 1, 2015, 9:46 a.m., Joseph Wu wrote: > > 3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp, lines 553-555 > > <https://reviews.apache.org/r/37826/diff/3/?file=1061137#file1061137line553> > > > > Can you explain why this is a struct rather than a function? > > Alexander Rukletsov wrote: > It's because we cannot partially specialize function templates and > overload won't work since we take the same argument. Do you think a comment > should be expanded? > > Alexander Rukletsov wrote: > http://www.gotw.ca/publications/mill17.htm > > Joseph Wu wrote: > Yes, I think a comment would be good regardless of how it ends up. > > What about using some C++11 type traits? (But I'm not sure if this will > work.) > Something like: > ``` > // Specialization for non-repeated fields. > template <typename T> > Try<T> parse(const JSON::Value& value, > typename std::enable_if<std::is_base_of<T, > google::protobuf::Message>, int>::type = 0) {...} > ``` > > Note: This file uses some similar Boost type traits further up. > > Alexander Rukletsov wrote: > I'm not sure how we can use type traits here. IIUC type traits facilitate > compile-time checks, and not compile-time dispatch. If we want to keep the > same function signature, we should rely on partial specialization. However, > we can still add these checks into `Parse<>::operator()` methods. > > Alexander Rukletsov wrote: > Which boils down to replacing > ``` > { google::protobuf::Message* message = (T*) NULL; (void) message; } > ``` > with > ``` > static_assert(std::is_base_of<google::protobuf::Message, T>::value, > "T must be a protobuf message"); > ``` > Does it make sense?
That part makes sense. And just to make sure, you can't use the same pattern found here? (Which looks a lot like compile-time dispatch.) https://github.com/apache/mesos/blob/master/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp#L165-L177 - Joseph ----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: https://reviews.apache.org/r/37826/#review97302 ----------------------------------------------------------- On Sept. 3, 2015, 6:32 a.m., Alexander Rukletsov wrote: > > ----------------------------------------------------------- > This is an automatically generated e-mail. To reply, visit: > https://reviews.apache.org/r/37826/ > ----------------------------------------------------------- > > (Updated Sept. 3, 2015, 6:32 a.m.) > > > Review request for mesos, Joseph Wu and Michael Park. > > > Bugs: MESOS-3312 > https://issues.apache.org/jira/browse/MESOS-3312 > > > Repository: mesos > > > Description > ------- > > See summary. > > > Diffs > ----- > > 3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp > 57d5fdf45273c620655b44b5f5572290cffa4bf6 > > Diff: https://reviews.apache.org/r/37826/diff/ > > > Testing > ------- > > make check (Mac OS 10.10.4) > > > Thanks, > > Alexander Rukletsov > >