aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-24 11:06:39 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-24 11:06:39 +0100
commitd3b974490cf7482b034f1a6779b65e411616f84c (patch)
tree1e03f8aadf76c94e7049c953c7626836dcf21263
parent60a7c102aaedb56844c8a054c62bcc9dfe91bde7 (diff)
downloadpaludis-d3b974490cf7482b034f1a6779b65e411616f84c.tar.gz
paludis-d3b974490cf7482b034f1a6779b65e411616f84c.tar.xz
Support initializer_list for Options
-rw-r--r--paludis/util/options.hh11
-rw-r--r--paludis/util/options_TEST.cc22
2 files changed, 32 insertions, 1 deletions
diff --git a/paludis/util/options.hh b/paludis/util/options.hh
index bfe9681..fe00e2d 100644
--- a/paludis/util/options.hh
+++ b/paludis/util/options.hh
@@ -22,6 +22,7 @@
#include <paludis/util/options-fwd.hh>
#include <paludis/util/attributes.hh>
+#include <initializer_list>
/** \file
* Declarations for the Options<> class.
@@ -121,6 +122,16 @@ namespace paludis
OptionsStore _store;
public:
+ Options() = default;
+ Options(const Options &) = default;
+
+ Options(std::initializer_list<E_> e)
+ {
+ for (auto i(e.begin()), i_end(e.end()) ;
+ i != i_end ; ++i)
+ _store.add(static_cast<unsigned>(*i));
+ }
+
/**
* Return a copy of ourself with the specified bit enabled.
*/
diff --git a/paludis/util/options_TEST.cc b/paludis/util/options_TEST.cc
index 3de24b2..2130648 100644
--- a/paludis/util/options_TEST.cc
+++ b/paludis/util/options_TEST.cc
@@ -83,7 +83,7 @@ namespace test_cases
TEST_CHECK(! options.any());
- second = MyOptions() + mo_three + mo_eight;
+ second = { mo_three, mo_eight };
options |= second;
options += mo_seven;
TEST_CHECK(options.any());
@@ -94,5 +94,25 @@ namespace test_cases
TEST_CHECK(options.highest_bit() >= static_cast<int>(last_mo));
}
} test_options;
+
+ struct OptionsInitialiserTest : TestCase
+ {
+ OptionsInitialiserTest() : TestCase("options initialiser") { }
+
+ void run()
+ {
+ MyOptions a({});
+ TEST_CHECK(! a.any());
+
+ MyOptions b({ mo_two, mo_four, mo_six });
+ TEST_CHECK(! b[mo_one]);
+ TEST_CHECK(b[mo_two]);
+ TEST_CHECK(! b[mo_three]);
+ TEST_CHECK(b[mo_four]);
+ TEST_CHECK(! b[mo_five]);
+ TEST_CHECK(b[mo_six]);
+ TEST_CHECK(! b[mo_seven]);
+ }
+ } test_options_initialiser;
}