Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Add support for std::optional if macro '__cpp_if_constexpr' returns 1 #45

Closed
wants to merge 3 commits into from

Conversation

ferkulat
Copy link

I really like the idea to put command line options into optional values.
This way the parser is not responsible for setting default values.
And if one compiles with C++17 this PR would make it possible to deal with std::optional variables

@codecov
Copy link

codecov bot commented Dec 22, 2017

Codecov Report

Merging #45 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #45   +/-   ##
=======================================
  Coverage   90.36%   90.36%           
=======================================
  Files           2        2           
  Lines         685      685           
=======================================
  Hits          619      619           
  Misses         66       66
Impacted Files Coverage Δ
include/clara.hpp 87.67% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a66d275...db3f8a1. Read the comment docs.

@philsquared
Copy link
Collaborator

I've just implemented support for optionals. I forgot about this PR, so I did it slightly differently - although it's very similar.

The main difference is I do use __has_include(<optional>) for detection, but along with __cplusplus >= 201703L. It seems to work on all GCC (and Clang) versions we currently support - and doesn't break on Windows, AFAICS (but I don't think the auto-detection kicks in there, yet).
You can also manually override, and supply alternate optional types by #defineing CLARA_CONFIG_OPTIONAL_TYPE to some (template) type, e.g. boost::optional (although I haven't tested that). It should work for any optional type that supports ! for validity and * for extracting the value. The underlying type must still be default constructible.

@horenmar
Copy link
Member

horenmar commented Mar 8, 2018

I fixed parts of the optional support and added the extra tests.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants