summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-15 16:33:14 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-15 18:41:56 +0300
commit121b4ca9ca0fdf4d46c296ffc0372beca80b1cb6 (patch)
treea5583e61404545db54b52fc08969b54e63f7a796 /include
parenta1b848913fc44a5829e1c44819171bee5b8a0f9c (diff)
downloadqtlocation-mapboxgl-121b4ca9ca0fdf4d46c296ffc0372beca80b1cb6.tar.gz
[core] Added mbgl::util::convert helper function
Converts a given std::array into another using a different (convertible) type.
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/util/convert.hpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/mbgl/util/convert.hpp b/include/mbgl/util/convert.hpp
new file mode 100644
index 0000000000..c2b3d9950d
--- /dev/null
+++ b/include/mbgl/util/convert.hpp
@@ -0,0 +1,17 @@
+#include <array>
+#include <type_traits>
+#include <utility>
+
+namespace mbgl {
+namespace util {
+
+template<typename To, typename From, std::size_t Size,
+ typename = std::enable_if_t<std::is_convertible<From, To>::value>>
+constexpr std::array<To, Size> convert(const std::array<From, Size>&from) {
+ std::array<To, Size> to {};
+ std::copy(std::begin(from), std::end(from), std::begin(to));
+ return to;
+}
+
+} // namespace util
+} // namespace mbgl