summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-07-12 20:35:25 +0200
committerljfa-ag <ljfa-ag@web.de>2015-07-12 20:35:25 +0200
commit125a60596531cb0717869dd8c54147f79335f5c2 (patch)
treedbddd443502e72c3713c809c89f2acc499ebf188 /include
parent37717c56332a524026272c4d91b7bd01b3c699fc (diff)
downloadProject-Tick-125a60596531cb0717869dd8c54147f79335f5c2.tar.gz
Project-Tick-125a60596531cb0717869dd8c54147f79335f5c2.zip
Create tag_list::of function
Diffstat (limited to 'include')
-rw-r--r--include/tag_compound.h1
-rw-r--r--include/tag_list.h22
2 files changed, 23 insertions, 0 deletions
diff --git a/include/tag_compound.h b/include/tag_compound.h
index 0789bed295..abf1df239a 100644
--- a/include/tag_compound.h
+++ b/include/tag_compound.h
@@ -42,6 +42,7 @@ public:
///Constructs an empty compound
tag_compound() {}
+ ///Constructs a compound with the given key-value pairs
tag_compound(std::initializer_list<std::pair<std::string, value_initializer>> init);
/**
diff --git a/include/tag_list.h b/include/tag_list.h
index 12aa86d965..b69eeba2fa 100644
--- a/include/tag_list.h
+++ b/include/tag_list.h
@@ -46,6 +46,13 @@ public:
static constexpr tag_type type = tag_type::List;
/**
+ * @brief Constructs a list with the given contents of type T
+ * @param init list of values that are, one by one, given to a constructor of T
+ */
+ template<class T, class Arg>
+ static tag_list of(std::initializer_list<Arg> init);
+
+ /**
* @brief Constructs an empty list
*
* The content type is determined when the first tag is added.
@@ -159,6 +166,12 @@ private:
tag_list(T dummy, std::initializer_list<Arg> init);
};
+template<class T, class Arg>
+tag_list tag_list::of(std::initializer_list<Arg> init)
+{
+ return tag_list(T(), std::move(init));
+}
+
template<class T, class... Args>
void tag_list::emplace_back(Args&&... args)
{
@@ -169,6 +182,15 @@ void tag_list::emplace_back(Args&&... args)
tags.emplace_back(T(std::forward<Args>(args)...));
}
+template<class T, class Arg>
+tag_list::tag_list(T dummy, std::initializer_list<Arg> init):
+ el_type_(T::type)
+{
+ tags.reserve(init.size());
+ for(const Arg& arg: init)
+ tags.emplace_back(T(arg));
+}
+
}
#endif // TAG_LIST_H_INCLUDED