Boost logo

Boost :

Subject: Re: [boost] Boost.Algorithm design question
From: Nevin Liber (nevin_at_[hidden])
Date: 2011-11-02 11:48:49


On 2 November 2011 08:20, Andrew Sutton <asutton.list_at_[hidden]> wrote:
> I look at the problem like this: if you don't assign types, then the
> question is, for which set of types of a and b can the expression a ==
> b define an equivalence relation? I know that the behavior is correct
> for char and int or string and const char*. Why? What's special about
> those types that make them behave as if I was comparing objects of a
> single type?

They are special because we give them higher level semantics which
define what that equivalence relation is and under what conditions it
holds.

We tend to be imprecise with (or just plain leave out) those
preconditions. Take you example of string and const char*; the
following asserts will either sometimes fire or invoke undefined
behavior for a given std::string s, const char* p, or string literal
l:

assert(s == s.c_str());
assert(std::string(p) == p);
assert(std::string(l, sizeof(l) - 1) == l);

Now, I can easily state the preconditions, but those requirements are
no longer on the types themselves but upon the values they represent.

-- 
 Nevin ":-)" Liber  <mailto:nevin_at_[hidden]>  (847) 691-1404

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk