-
-
Save NTG-TPL/63e1924b7901986f3ead950d5de3b2ee to your computer and use it in GitHub Desktop.
python "print" in c++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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