mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
Add an operator< for Thrift structs (in C++).
Some people want to use sets of Thrift structs. This has interesting implications, but it is a reasonable request. However, in C++, this requires structures to have a less-than operator. It seems a little dangerous to auto-generate an arbitrary comparator, but allowing users to define their own operator< implementations seems fine. This change makes that a lot easier. The one downside of this change is that developers who try to compare structures with operator< (including trying to make sets of them) will now get a linker error instead of a compiler error. However, the old compiler error was so scary that I'm not sure this is any worse. Reviewed By: kholst, mcslee Test Plan: make check git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665527 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f0cf2a3745
commit
cf2e8d9af3
@ -770,6 +770,13 @@ void t_cpp_generator::generate_struct_definition(ofstream& out,
|
||||
indent() << "bool operator != (const " << tstruct->get_name() << " &rhs) const {" << endl <<
|
||||
indent() << " return !(*this == rhs);" << endl <<
|
||||
indent() << "}" << endl << endl;
|
||||
|
||||
// Generate the declaration of a less-than operator. This must be
|
||||
// implemented by the application developer if they wish to use it. (They
|
||||
// will get a link error if they try to use it without an implementation.)
|
||||
out <<
|
||||
indent() << "bool operator < (const "
|
||||
<< tstruct->get_name() << " & ) const;" << endl << endl;
|
||||
}
|
||||
if (read) {
|
||||
out <<
|
||||
|
Loading…
Reference in New Issue
Block a user