diff --git a/google/cloud/options.cc b/google/cloud/options.cc index 1dd11fe2b8c75..5dcd29bc952ab 100644 --- a/google/cloud/options.cc +++ b/google/cloud/options.cc @@ -35,6 +35,8 @@ void CheckExpectedOptionsImpl(std::set const& expected, } } +bool IsEmpty(Options const& options) { return options.m_.empty(); } + Options MergeOptions(Options preferred, Options alternatives) { if (preferred.m_.empty()) return alternatives; preferred.m_.insert(std::make_move_iterator(alternatives.m_.begin()), diff --git a/google/cloud/options.h b/google/cloud/options.h index a92077dc5974e..9f0a31b5aa72e 100644 --- a/google/cloud/options.h +++ b/google/cloud/options.h @@ -33,6 +33,8 @@ namespace internal { Options MergeOptions(Options, Options); void CheckExpectedOptionsImpl(std::set const&, Options const&, char const*); +// TODO(#8800) - Remove when bigtable::Table no longer uses bigtable::DataClient +bool IsEmpty(Options const&); template inline T const& DefaultValue() { static auto const* const kDefaultValue = new T{}; @@ -209,6 +211,7 @@ class Options { friend Options internal::MergeOptions(Options, Options); friend void internal::CheckExpectedOptionsImpl( std::set const&, Options const&, char const*); + friend bool internal::IsEmpty(Options const&); // The type-erased data holder of all the option values. class DataHolder { diff --git a/google/cloud/options_test.cc b/google/cloud/options_test.cc index 9f238776636e3..ecc76d8d951c9 100644 --- a/google/cloud/options_test.cc +++ b/google/cloud/options_test.cc @@ -251,6 +251,16 @@ TEST(CheckUnexpectedOptions, OptionsListOneUnexpected) { Contains(ContainsRegex("caller: Unexpected option.+FooOption"))); } +TEST(IsEmpty, Yes) { + Options opts; + EXPECT_TRUE(internal::IsEmpty(opts)); +} + +TEST(IsEmpty, No) { + auto opts = Options{}.set(0); + EXPECT_FALSE(internal::IsEmpty(opts)); +} + TEST(MergeOptions, Basics) { auto a = Options{}.set("from a").set(42); auto b = Options{}.set("from b").set(true);