C++Guns – RoboBlog

12.05.2018

C++ Guns: print std::array with std::integer_sequence

Filed under: Allgemein — Tags: — Thomas @ 15:05

Part1: print std::array with std:integer_sequence
Part 2: convert tuple to parameter pack
Part 3: print std::array with std::apply and fold
Part 4: fold over std::tuple und erzeugten Assembler Code
Part 5: fold over std::tuple of std::vector of Types ...
Part 6: apply generic lambda to tuple
Part 7: Play with std::tuple and std::apply

Wird an der Zeit, dass ich das auch mal versuche:

#include <array>
#include <iostream>

template<size_t N, std::size_t... Ints>
void print_impl(const std::array<double,N>& arr, std::index_sequence<Ints...>) {
    ((std::cout << std::get<Ints>(arr)),...);
}

template<size_t N>
void print(const std::array<double,N>& arr) {
    print_impl(arr, std::make_index_sequence<N>{});
}

void func() {
    std::array<double,4> arr{1,2,3,4};
    print(arr);
}

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress