diff --git a/README.md b/README.md index b5a3b320..4d3bd121 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ An option name must start with a alphabetic character or underscore. For long op On a C++14 compiler, you can pass a callback function directly to `.add_flag`, while in C++11 mode you'll need to use `.add_flag_function` if you want a callback function. The function will be given the number of times the flag was passed. You can throw a relevant `CLI::ParseError` to signal a failure. -On a compiler that supports C++17's `__has_include`, you can also use `std::optional`, `std::experimental::optional`, and `boost::optional` directly in an `add_option` call. See [CLI11 Internals] for information on how this was done and how you can add your own converters. +On a compiler that supports C++17's `__has_include`, you can also use `std::optional`, `std::experimental::optional`, and `boost::optional` directly in an `add_option` call. If you don't have `__has_include`, you can define `CLI11_BOOST_OPTIONAL` before including CLI11 to manually add support for `boost::optional`. See [CLI11 Internals] for information on how this was done and how you can add your own converters. ### Example diff --git a/include/CLI/Optional.hpp b/include/CLI/Optional.hpp index 5b7d3e0b..1b2db6a2 100644 --- a/include/CLI/Optional.hpp +++ b/include/CLI/Optional.hpp @@ -29,7 +29,7 @@ namespace CLI { #ifdef CLI11_STD_OPTIONAL -template std::istream &operator>>(std::istream &in, std::optional &val) { +template std::istringstream &operator>>(std::istringstream &in, std::optional &val) { T v; in >> v; val = v; @@ -38,7 +38,7 @@ template std::istream &operator>>(std::istream &in, std::optional std::istream &operator>>(std::istream &in, std::experimental::optional &val) { +template std::istringstream &operator>>(std::istringstream &in, std::experimental::optional &val) { T v; in >> v; val = v; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ab760247..4c191fcc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -76,5 +76,9 @@ find_package(Boost 1.35) if(Boost_FOUND) target_link_libraries(informational PUBLIC Boost::boost) target_link_libraries(OptionalTest PUBLIC Boost::boost) + + # Enforce Boost::Optional even if __has_include is missing on your compiler + target_compile_definitions(informational PUBLIC CLI11_BOOST_OPTIONAL) + target_compile_definitions(OptionalTest PUBLIC CLI11_BOOST_OPTIONAL) endif()