[core] Added mbgl::util::convert helper function
Converts a given std::array into another using a different (convertible) type.
This commit is contained in:
17
include/mbgl/util/convert.hpp
Normal file
17
include/mbgl/util/convert.hpp
Normal 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
|
||||
9
src/mbgl/util/convert.cpp
Normal file
9
src/mbgl/util/convert.cpp
Normal 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
|
||||
Reference in New Issue
Block a user