[core] Added mbgl::util::convert helper function

Converts a given std::array into another using a different (convertible)
type.
This commit is contained in:
Bruno de Oliveira Abinader
2016-06-15 16:33:14 +03:00
parent a1b848913f
commit 121b4ca9ca
2 changed files with 26 additions and 0 deletions

View File

@@ -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

View File

@@ -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