Aug 30, 2018

[C++] fold expression for inserting space between value for print out.

trick:
, as binary operator

#include <iostream>
using namespace std;


template<typename U, typename ... T>
void run(T... a){
    ((cout << a << ' '), ...);
}

int main(){
    // run(1,2,32,4);
    run<int>(1,3, 42.0, "haha");
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.