Skip to content

Instantly share code, notes, and snippets.

@NTG-TPL
Forked from ilebedie/python_like_print.hpp
Last active July 11, 2023 10:57
Show Gist options
  • Save NTG-TPL/63e1924b7901986f3ead950d5de3b2ee to your computer and use it in GitHub Desktop.
Save NTG-TPL/63e1924b7901986f3ead950d5de3b2ee to your computer and use it in GitHub Desktop.
python "print" in c++
#include <iostream>
using namespace std;
namespace detail {
template <typename T, typename... Tail>
void print_impl(const T& t, const Tail&... tail) {
using namespace std::literals;
std::cout << t;
(..., (std::cout << " "sv << tail));
}
} // namespace detail
template <typename... Tail>
void print(const Tail&... tail) {
if constexpr (sizeof...(tail) != 0) {
detail::print_impl(tail...);
}
std::cout << std::endl;
}
int main(){
print();
print("abc", "bcd");
print(1, 2, 3, 4);
print(3, 4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment