Skip to content

Instantly share code, notes, and snippets.

@SLSNe
Created August 9, 2019 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SLSNe/ed9c43030326c79b4339a143971be3f1 to your computer and use it in GitHub Desktop.
Save SLSNe/ed9c43030326c79b4339a143971be3f1 to your computer and use it in GitHub Desktop.
C++17 Python like?? Print Function
#pragma once
#include <iostream>
template<auto sep = ' ', auto end = '\n', typename FirstType, typename... Types>
void print(const FirstType& firstArg, const Types... args)
{
std::cout << firstArg;
auto separator = [](const auto &arg) {
std::cout << sep << arg;
};
(... , separator(args));
std::cout << end;
}
/*
Example Usage:
print(2, 5, 7, 8); Output: 2 5 7 8
print<'-'>(2, 5, 7, 8); Output: 2-5-7-8
print<'-', '\t'>(2, 5, 7, 8) Output: 2-5-7-8\t
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment