catchorg / Clara

A simple to use, composable, command line parser for C++ 11 and beyond
Boost Software License 1.0
650 stars 67 forks source link

Missing include for std::optional #60

Closed atomicflag closed 6 years ago

atomicflag commented 6 years ago

https://github.com/catchorg/Clara/blob/adb5ec3a5c20defc80286fd6e8c14aeef10fdcd7/include/clara.hpp#L21-L27

<optional> should probably be included here.

horenmar commented 6 years ago

You are right, I added it in bd21f701a03ad6cbe291d32312672ee492e0f755

philsquared commented 6 years ago

In fact the intention was to not include it explicitly - it's up to the user if they want to include it

horenmar commented 6 years ago

That breaks things, because

    template<typename T>
    inline auto convertInto( std::string const &source, CLARA_CONFIG_OPTIONAL_TYPE<T>& target ) -> ParserResult {
        T temp;
        auto result = convertInto( source, temp );
        if( result )
            target = std::move(temp);
        return result;
    }

expects whatever type CLARA_CONFIG_OPTIONAL_TYPE changes into to exist. If it doesn't, it will not compile, so all users would have to add #include <optional> to prevent Clara from breaking with -std=c++17...

It just so happens that for libstdc++7 <optional> is included transitively, but that does not have to always be the case.

philsquared commented 6 years ago

Yes, you're right - this is the automatic detection - I missed that. It should be included here.