Skip to content

std::array becomes std::std::array in the insight window #747

Description

@TedLyngmo

https://cppinsights.io/s/b6a35a2d

In this example, the return std::array{...}; lines become return std::std::array{...};. It could be due to an implementation detail, but I'd expect that to be std::__std::array or similar in that case - and the result is the same for both libstdc++ and libc++.

#include <array>
#include <cstddef>
#include <type_traits>
#include <utility>

template <class T, std::size_t... Is, class... Rest>
constexpr auto make_md_array_impl(const T& val, std::index_sequence<Is...>, Rest... rs) {
    if constexpr (sizeof...(Rest) != 0) {
        // recurse sizeof...(Is) times to create inner arrays
        return std::array{((void)Is, make_md_array_impl(val, rs...))...};
    } else {
        // inner most array, initialize it with sizeof...(Is) val's:
        return std::array{((void)Is, val)...};
    }
}

template <std::size_t... Ns, class T>
constexpr auto make_md_array(const T& val) {
    return make_md_array_impl(val, std::make_index_sequence<Ns>{}...);
}

int main() {
    const std::array<std::array<std::array<double, 1000>, 3>, 4> ref{};
    
    constexpr auto arr = make_md_array<4, 3, 1000>(-1.);  // double[4][3][1000]

    static_assert(std::is_same_v<decltype(ref), decltype(arr)>);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions