diff options
-rw-r--r-- | include/mbgl/util/convert.hpp | 17 | ||||
-rw-r--r-- | src/mbgl/util/convert.cpp | 9 |
2 files changed, 26 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 diff --git a/src/mbgl/util/convert.cpp b/src/mbgl/util/convert.cpp new file mode 100644 index 0000000000..97bfe9108d --- /dev/null +++ b/src/mbgl/util/convert.cpp @@ -0,0 +1,9 @@ +#include <mbgl/util/convert.hpp> + +namespace mbgl { +namespace util { + +template std::array<float, 2> convert(const std::array<int32_t, 2>&); + +} // namespace util +} // namespace mbgl |