1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <optional>
struct A
{
bool b; char c; int i;
constexpr bool compare(std::optional<bool> b0,
std::optional<char> c0,
std::optional<int> i0) const noexcept
{
return (! b0.has_value() || *b0 == b) &&
(! c0.has_value() || *c0 == c) &&
(! i0.has_value() || *i0 == i);
}
};
int main()
{
constexpr A a{ false, 'a', 42 };
static_assert( a.compare( false, 'a', 42 ));
static_assert(! a.compare( true, 'a', 42 ));
static_assert( a.compare( std::nullopt, 'a', 42 ));
static_assert(! a.compare( std::nullopt, 'b', 42 ));
static_assert( a.compare( std::nullopt, std::nullopt, std::nullopt ));
static_assert(! a.compare( std::nullopt, std::nullopt, 9000 ));
}
|