POV-Ray : Newsgroups : povray.off-topic : C++ questions : Re: C++ questions Server Time
7 Sep 2024 09:22:54 EDT (-0400)
  Re: C++ questions  
From: Orchid XP v8
Date: 28 Sep 2008 16:49:38
Message: <48dfede2$1@news.povray.org>
Warp wrote:
> Orchid XP v8 <voi### [at] devnull> wrote:
>> Question: What happens if your class doesn't have the comparison operator?
> 
>   If there's no way you can add an operator<() for your class, then you
> can give std::set a comparator.

>   It is also possible to create a comparison function and use as a functor
> (as you might remember). However, the syntax of the TheSetType definition
> becomes a bit complicated.
> 
>   By the way, std::set (as well as std::map) *always* takes a comparator
> (rather than using the < operator directly). When none is specified, the
> default comparator used is std::less which, by template magic, makes it
> completely equivalent to comparing the elements with the < operator
> directly.
> 
>   This is good to know because you might sometimes want the elements
> sorted in some other way.

Sounds quite flexible.

(In particular, Haskell's own Data.Set provides no way to specify an 
alternate comparison operator. But then again, it only needs *a* 
comparison operator; which one you use doesn't really affect anything 
user-visible. The "sort" function allows you to specify a comparison 
operator manually though...)

What I was really interested to know is whether trying to construct a 
set without a comparison operator yields a compile-time error, a runtime 
error, or simply undefined behaviour.

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.