Boost logo

Boost Users :

Subject: Re: [Boost-users] [optional]
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2009-05-06 04:58:05


2009/5/6 <dariomt_at_[hidden]>

> Hi list,
>
> In 'classic' C++ style I have signalled optional parameters in a function
> with pointers that might be null (I wouldn't like to create overloads for
> all possible combination of existing and non-existing parameters) e.g.
>
> // p1 is mandatory, p2, p3 and p4 are optional
> void f(const Param1& p1, const Param2* p2, const Param3* p3, const Param4*
> p4);
>
> And call it
> Param1p1; Param2 p2; Param4 p4;
> f(p1, &p2, 0, &p4);
>
> I thought I could use boost::optional like this
>
> void f(const Param1& p1, const boost::optional<Param2> & p2, const
> boost::optional<Param3> p3, const boost::optional<Param4> & p4);
>
> And call it
> Param1p1; Param2 p2; Param4 p4;
> f(p1, boost::optional<Param2>(p2), boost::optional<Param3>(),
> boost::optional<Param4>(p4) );
>

It's less efficient, because all arguments will be copied. It's also more
typing, longer compilation times and more code generated.

Roman Perepelitsa.



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