to_array
namespace opentl {
template <typename T, opentl::size_t N>
constexpr opentl::array<opentl::remove_cv_t<T>, N> to_array(T (&a)[N]);
template <typename T, opentl::size_t N>
constexpr opentl::array<opentl::remove_cv_t<T>, N> to_array(T (&&a)[N]);
}
Creates an array from a C-style array.
Declared in <array/to_array.hpp>.
Template Parameters
| Name | Description |
|---|---|
T |
The element type. |
N |
The array size. |
Parameters
| Name | Description |
|---|---|
a |
The C-style array to convert. |
Return Value
An opentl::array with the same elements as the source C-style array. The element type has const and volatile qualifiers removed, matching the source element type otherwise.
Overloads
| Overload | Description |
|---|---|
to_array(T (&)[N]) |
Copies elements from an l-value C-style array. |
to_array(T (&&)[N]) |
Moves elements from an r-value C-style array. |
Example
#include <opentl/array.hpp>
#include <array/to_array.hpp>
int main() {
int c_arr[3] = {1, 2, 3};
opentl::array<int, 3> arr = opentl::to_array(c_arr);
const int const_arr[2] = {4, 5};
opentl::array<int, 2> arr2 = opentl::to_array(const_arr); // const removed
}