[std-interval] C++ interval std
Steve Clamage
Stephen.Clamage at Sun.COM
Wed Apr 5 02:02:40 PDT 2006
Bill Clarke wrote:
>
> Surely it is possible to permit the implementer to choose the parameter
> passing convention, between pass-by-value and pass-by-const-ref? It
> should have no visible impact on the programmer which is used.
The standard can state, for example, that that whether a parameter is passed by
value or by reference is implementation-defined, meaning that an implementation
can choose either and must document the choice. Or it could say that the choice
is unspecified, meaning that the implementation does not need to document what
it does, and does not need to be consistent.
The choice can have an effect on programmers, however, since the types of the
functions
interval foo(interval);
interval foo(const interval&);
are different.
1. If you create a function pointer interval(*)(interval), it cannot be used to
hold the address of "interval foo(const interval&)". I don't know of a
convenient way to deal with this problem, where you need to modify your code
based on details of a predefined type.
2. The result of typeid(foo) is different in the two cases, which can affect the
operation of a program.
interval bar(const interval&);
if( typeid(foo) == typeid(bar) ) ...
That said, it is already the case that member functions of classes in the
standard library are explicitly allowed to vary from the exemplars listed in the
standard. But the implementation is required to accept code that is valid for
the exemplars.
Example: An implementation can add a default parameter to a class member
function. If the standard says this:
class Foo {
public:
fun(int);
};
An implemtation can have this:
class Foo {
public:
fun(int, int=0);
};
According to the standard, the following is valid:
Foo f;
f.fun(3);
and indeed that code compiles with the modified implementation.
Similarly, code that can call one of the versions of the interval function foo
above can also call the other version.
My point is that allowing freedom of implementation is not without consequences
for C++ programmers, but there is already some precedent for that freedom of
implementation. We need to be aware of the potential problems for programmers,
and make a considered choice.
---
Steve Clamage, stephen.clamage at sun.com
More information about the Std-interval
mailing list