[glibmm/glibmm-2-54] tests/glibmm_variant: Use C++14 features conditionally
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/glibmm-2-54] tests/glibmm_variant: Use C++14 features conditionally
- Date: Tue, 19 Sep 2017 15:14:13 +0000 (UTC)
commit 75c06a9e9a2cc6d15bcc428c7cdc997995b8e2d6
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Tue Sep 19 17:11:16 2017 +0200
tests/glibmm_variant: Use C++14 features conditionally
* glib/src/variant.hg: Add (void) to intentionally unused variables,
thus avoiding warnings when the test case is built with clang++.
* tests/glibmm_variant/main.cc: Use std::get<Number>(std::tuple)
(not std::get<Type>()) when compiling with only C++11 support.
Bug 787648
glib/src/variant.hg | 4 ++--
tests/glibmm_variant/main.cc | 10 ++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/glib/src/variant.hg b/glib/src/variant.hg
index 4fe5719..837ee13 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -1497,7 +1497,7 @@ const VariantType& Variant<std::tuple<Types...>>::variant_type()
// expands the variadic template parameters
using swallow = int[]; // ensures left to right order
- swallow{(expander(Variant<Types>::variant_type()))...};
+ (void)swallow{(expander(Variant<Types>::variant_type()))...};
static auto type = VariantType::create_tuple(types);
return type;
@@ -1652,7 +1652,7 @@ std::tuple<Types...> Variant<std::tuple<Types...>>::get() const
variants.push_back(variant);
return i++;
};
- swallow{(expander(get_child_variant<Types>(i)))...};
+ (void)swallow{(expander(get_child_variant<Types>(i)))...};
detail::assign_tuple(variants, data, detail::index_sequence_for<Types...>{});
return data;
diff --git a/tests/glibmm_variant/main.cc b/tests/glibmm_variant/main.cc
index 7431a9a..8c521f9 100644
--- a/tests/glibmm_variant/main.cc
+++ b/tests/glibmm_variant/main.cc
@@ -57,16 +57,26 @@ bool test_tuple()
ostr << "Index of first map entry: " << child0.first << std::endl;
result_ok &= child0.first == 4;
auto extracted_tuple = child0.second;
+#if __cplusplus > 201103L // C++14 or higher
auto q3 = std::get<guint16>(extracted_tuple);
auto s3 = std::get<Glib::ustring>(extracted_tuple);
auto b3 = std::get<bool>(extracted_tuple);
+#else // C++11
+ auto q3 = std::get<0>(extracted_tuple);
+ auto s3 = std::get<1>(extracted_tuple);
+ auto b3 = std::get<2>(extracted_tuple);
+#endif
ostr << "Extracted tuple1 from map: (" << q3 << ", " << s3 << ", " << b3 << ")" << std::endl;
result_ok &= q3 == q1 && s3 == s1 && b3 == b1;
// Extract from a tuple.
auto q4 = tuple2_variant.get_child<guint16>(0);
auto s4 = tuple2_variant.get_child_variant<Glib::ustring>(1).get();
+#if __cplusplus > 201103L // C++14 or higher
auto b4 = std::get<bool>(tuple2_variant.get());
+#else // C++11
+ auto b4 = std::get<2>(tuple2_variant.get());
+#endif
ostr << "Extracted tuple2: (" << q4 << ", " << s4 << ", " << b4 << ")" << std::endl;
result_ok &= q4 == q2 && s4 == s2 && b4 == b2;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]