Boost logo

Boost Users :

Subject: Re: [Boost-users] Bug when using boost::optional with boost::program_options?
From: Xavier Besseron (xavier.besseron_at_[hidden])
Date: 2018-06-05 15:51:48


Dear Jim,

I remember having some troubles using boost::optional with
boost::program_options.
I fixed it by adding the following lines:

namespace boost
{// Add custom validator to use boost::program_options on
boost::optional<> typestemplate<class T>void validate(boost::any& v,
std::vector<std::string> const& values, boost::optional<T>* typeTag,
int)
{
    if (!values.empty())
    {
        boost::any a;
        using namespace boost::program_options;
        validate(a, values, (T*)0, 0);
        v = boost::any(boost::optional<T>(boost::any_cast<T>(a)));
    }
}
}

I don’t remember the details, but I think I took that from more recent
version of Boost to be able to use my code with older version of Boost.
With that, my code compiles and runs fine

   - on Linux for Boost from 1.54 to 1.66 with various compilers (GCC 4.8
   to 7.3, Intel Compiler, Clang)
   - on Windows for Boost 1.60 with MSVC++ from 9 (2008) to 14 (2015).

I hope this will help.

Best regards,

Xavier
​

On Tue, Jun 5, 2018 at 5:21 PM degski via Boost-users <
boost-users_at_[hidden]> wrote:

> On 5 June 2018 at 15:41, Chris Glover via Boost-users <
> boost-users_at_[hidden]> wrote:
>
>> Regardless of what was written above (or what permeates reddit, etc),
>> most shops are still using VS2015 or lower, so it does matter, actually.
>>
>
> If one doesn't care about bugs in compiler, STL and IDE, and support for
> later standards, why would one care to upgrade Boost at all?
>
> I was quoting Steven T. Lavavej <https://nuwen.net/stl.html> (STL) and
> Billy O'Neill, who both have leading roles in VC (and its STL) development.
> The fact you saw it on reddit.com might have something to do with the
> fact that STL is also one of the moderators of /r/cpp.
>
> degski
> --
> *"If something cannot go on forever, it will stop" - Herbert Stein*
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Dr Xavier BESSERON
Research associate
FSTC, University of Luxembourg
Campus Belval, Office MNO E04 0415-040
Phone: +352 46 66 44 5418
http://luxdem.uni.lu/


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