Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2008-06-16 07:01:58


On Mon, Jun 16, 2008 at 10:45 AM, Marc Horowitz <marc_at_[hidden]> wrote:

> "Ovanes Markarian" <om_boost_at_[hidden]> writes:
>
> >> in this case template deduction does not work (or works a bit
> >> different as assumed).
> >>
> >> This one should work:
> >> (std::tr1::bind(f, _1))(static_cast<const char*>(NULL));
>
> This works, but it is inconvenient. It is not always clear at first
> what the type of an argument which takes NULL is, especially if one is
> modifying existing code. You can compile, see what the error message
> says, and copy that type into the code, but I was hoping to avoid
> this.
>
This is static type safety of C++. The next standard will introduce
null_ptr. If used as you suggested, then nothing prevents this BAD code to
compile:
 (std::tr1::bind(f, _1))(1);

> >> NullPlaceholder works, because it makes the cast in operator() for
> >> you.
>
> Yes, I am aware of this, which is why I wrote it that way. I was
> hoping to learn if someone had developed a cleaner workaround, and to
> get the documentation improved if not.

I don't see it as a workaround, but a clean approach to initialize pointer
values with NULL-value only. This approach cleanly prevents the upper error
case as well.

>
> Marc
>
Regards,
Ovanes



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net