[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 1948890 3/3: Modernize for statements
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 1948890 3/3: Modernize for statements |
Date: |
Thu, 19 Jan 2017 09:27:46 +0000 (UTC) |
branch: master
commit 194889036197bc6a8492d08da5c96b9825519f1f
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Modernize for statements
Struct template xml_sequence_io is documented thus:
/// Serialization for sequences [23.1.1].
but it was not transparently obvious whether it might be used with a
container that is not a sequence, so a static assertion more or less
to that effect has been added. Even a coarse assertion is stronger
than a mere comment.
---
xml_serialize.hpp | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/xml_serialize.hpp b/xml_serialize.hpp
index 1f0944a..bdb44e9 100644
--- a/xml_serialize.hpp
+++ b/xml_serialize.hpp
@@ -82,23 +82,26 @@ struct xml_io
/// from_xml() reads only <item> elements, ignoring other elements
/// (and non-element nodes) that might have been added manually,
/// e.g., as documentation.
+///
+/// C++11 has no way to assert that T is a Sequence; for the nonce,
+/// no other Sequence being used, assert that it's a vector.
template<typename T>
struct xml_sequence_io
{
typedef typename T::value_type item_t;
+ static_assert(std::is_same<T,std::vector<item_t> >::value, "");
static void to_xml(xml::element& e, T const& t)
{
// XMLWRAPP !! Add a clear() function.
e.erase(e.begin(), e.end());
- typedef typename T::const_iterator tci;
- for(tci i = t.begin(); i != t.end(); ++i)
+ for(auto const& i : t)
{
// This is not equivalent to calling set_element():
// multiple <item> elements are expressly permitted.
xml::element z("item");
- xml_io<item_t>::to_xml(z, *i);
+ xml_io<item_t>::to_xml(z, i);
e.push_back(z);
}
}
@@ -106,12 +109,10 @@ struct xml_sequence_io
static void from_xml(xml::element const& e, T& t)
{
t.clear();
- xml::const_nodes_view const items(e.elements("item"));
- typedef xml::const_nodes_view::const_iterator cnvi;
- for(cnvi i = items.begin(); i != items.end(); ++i)
+ for(auto const& i : e.elements("item"))
{
item_t z;
- xml_io<item_t>::from_xml(*i, z);
+ xml_io<item_t>::from_xml(i, z);
t.push_back(z);
}
}