[pdal] questions about iterator and buffer semantics

Mateusz Loskot mateusz at loskot.net
Wed Jul 3 05:27:45 PDT 2013


On 3 July 2013 13:15, Chris Foster <chris42f at gmail.com> wrote:
> On Wed, Jul 3, 2013 at 7:21 PM, Mateusz Loskot <mateusz at loskot.net> wrote:
>> The problem I've got with nullptr is that it does not necessarily mean
>> "invalid value". It means, "something could not deliver a value",
>> but if something can deliver and the value delivered is invalid...
>
> Let me paraphrase to see if I understand you here.  The distinction is
> "a failure occurred while trying to find the value" vs
> "things worked but the value wasn't present".

or, in case when value is calculated,
"things worked and the value(s) was present, but the output
computation returned invalid valeu"

It all depends on particular situation, so obviously I gave somewhat
general point on
role of nullptr in defining an interface.

> For the getDimensionOptional() case, that would be something like
> "memory could not be allocated so the search for the dimension failed" vs
> "everything worked, but the dimension wasn't present"
>
> In my opinion the first is neatly captured by an exception (the program
> encountered a hard failure which the function wasn't prepared to deal with),
> whereas in the second case nullptr can simply be returned.  In this way it seems
> like nullptr can have perfectly well defined semantics.

Yes, for example.
The second case also may mean "skip dimension and continue", whereas the first
may lead to (graceful) termination.

To give a contrast of use of nullptr as part of interface:
std::malloc(...) == nullptr would be a hard error.


Best regards,
-- 
Mateusz  Loskot, http://mateusz.loskot.net


More information about the pdal mailing list