Skip to content

Commit

Permalink
implement stringify for std::nullopt_t
Browse files Browse the repository at this point in the history
  • Loading branch information
mjerabek committed Aug 30, 2023
1 parent f24d39e commit a62dcc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/catch2/catch_tostring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,12 @@ namespace Catch {
}
}
};
template <>
struct StringMaker<std::nullopt_t> {
static std::string convert(const std::nullopt_t&) {
return "{ }";
}
};
}
#endif // CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER

Expand Down
4 changes: 4 additions & 0 deletions tests/SelfTest/UsageTests/ToStringOptional.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ TEST_CASE( "std::vector<std::optional<int> > -> toString", "[toString][optional]
REQUIRE( "{ 0, { }, 2 }" == ::Catch::Detail::stringify( type{ 0, {}, 2 } ) );
}

TEST_CASE( "std::nullopt -> toString", "[toString][optional][approvals]" ) {
REQUIRE( "{ }" == ::Catch::Detail::stringify( std::nullopt ) );
}

#endif // CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL

0 comments on commit a62dcc9

Please sign in to comment.