Hi Raghava,

I'm surprised that none of the developers have chimed in, but I'll give it a 
try.

The compiler declares the operator, but it can't define it for you because, in 
general, it can't know what "less than" means for your thrift struct. But the 
compiler does know that you'll need to define this operator if you want to put 
your structure into a set, or use it as a key in a map, so it helpfully 
provides the declaration. You need to provide the definition.

I would imaging that we are like many other thrift users. We use it for many 
things, and have lots of fairly complicated structures defined, but I have yet 
to need to write an implementation for operator<, because we don't use the 
thrift classes in a way that requires it.

- Rush

On Jul 26, 2010, at 2:18 PM, Raghava Mutharaju wrote:

> Hi,
> 
> I got the answer on why overloading of operator < is required. std::set
> orders its elements, so "<" operator is required for comparison on the type
> of elements it is holding.
> 
> But I haven't got answer to my other question -- why doesn't thrift compiler
> generate code for this? Does the thrift community write their own
> implementations for "operator <" ?
> 
> Thank you.
> 
> Regards,
> Raghava.
> 
> On Mon, Jul 26, 2010 at 4:09 PM, Raghava Mutharaju <
> [email protected]> wrote:
> 
>> Hello all,
>> 
>> In the code that thrift generates for C++, in all the classes, it overloads
>> 3 operators, ==, != and <. Implementations for == and != are provided but
>> there won't be any implementation for < operator. Why is this so? How come
>> it doesn't generate any compilation errors? (except in one case I got a
>> linker error -- mentioned in my previous post). How are these overloaded
>> operators used?
>> 
>> Thank you.
>> 
>> Regards,
>> Raghava.
>> 

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to