add outputln variant
This commit is contained in:
parent
8b8cf836f3
commit
87d2db06c1
0
libvmake/examples/.hello_world.cpp.swo
Normal file
0
libvmake/examples/.hello_world.cpp.swo
Normal file
@ -3,11 +3,10 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
vmake::output(cout, " ", vmake::filter(vmake::range(1, 10), [](int x) {
|
vmake::outputln(cout, " ", vmake::filter(vmake::range(1, 10), [](int x) {
|
||||||
return x % 2 == 0;
|
return x % 2 == 0;
|
||||||
}));
|
}), '\n');
|
||||||
cout << endl;
|
vmake::outputln(cout, " ", vmake::take(vmake::filter(vmake::iota(1), [](int x) {
|
||||||
vmake::output(cout, " ", vmake::take(vmake::filter(vmake::iota(1), [](int x) {
|
|
||||||
return x <= 5;
|
return x <= 5;
|
||||||
}), 5));
|
}), 5));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -3,7 +3,7 @@ using namespace std;
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
vector<string> a{"HELLO", "WORLD", "!"};
|
vector<string> a{"HELLO", "WORLD", "!"};
|
||||||
vmake::output(cout, " ", vmake::transform(vmake::extract(a.begin(), a.end()), [](auto &&s) {
|
vmake::outputln(cout, " ", vmake::transform(vmake::extract(a.begin(), a.end()), [](auto &&s) {
|
||||||
std::transform(s.cbegin(), s.cend(), s.begin(), [] (auto c) { return std::tolower(c); });
|
std::transform(s.cbegin(), s.cend(), s.begin(), [] (auto c) { return std::tolower(c); });
|
||||||
return s;
|
return s;
|
||||||
}));
|
}));
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
vmake::output(cout, " ", vmake::take(vmake::rng::uniform_ints(1, 10), 15));
|
vmake::outputln(cout, " ", vmake::take(vmake::rng::uniform_ints(1, 10), 15));
|
||||||
cout << endl;
|
vmake::outputln(cout, " ", vmake::take(vmake::rng::uniform_reals(1., 10.), 5));
|
||||||
vmake::output(cout, " ", vmake::take(vmake::rng::uniform_reals(1., 10.), 5));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -436,26 +436,60 @@ inline OutputIt copy_n(OutputIt it, size_t n, Gen&& g) {
|
|||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename OutputStream, typename Gen>
|
template<typename CharT, typename Traits, typename Gen>
|
||||||
inline auto output(OutputStream& out, const char *delim, Gen &&g) {
|
inline auto output(std::basic_ostream<CharT, Traits>& out, const char *delim, Gen &&g) {
|
||||||
return copy(std::ostream_iterator<typename std::decay<Gen>::type::result>(out, delim), std::move(g));
|
return copy(std::ostream_iterator<typename std::decay<Gen>::type::result>(out, delim), std::move(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename OutputStream, typename Gen>
|
template<typename CharT, typename Traits, typename Gen>
|
||||||
inline auto output(OutputStream& out, Gen &&g) {
|
inline auto output(std::basic_ostream<CharT, Traits>& out, Gen &&g) {
|
||||||
return copy(std::ostream_iterator<typename std::decay<Gen>::type::result>(out), std::move(g));
|
return copy(std::ostream_iterator<typename std::decay<Gen>::type::result>(out), std::move(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename OutputStream, typename Gen>
|
template<typename CharT, typename Traits, typename Gen>
|
||||||
inline auto output_n(OutputStream& out, size_t n, const char *delim, Gen &&g) {
|
inline auto output_n(std::basic_ostream<CharT, Traits>& out, size_t n, const char *delim, Gen &&g) {
|
||||||
return copy_n(std::ostream_iterator<typename std::decay<Gen>::type::result>(out, delim), n, std::move(g));
|
return copy_n(std::ostream_iterator<typename std::decay<Gen>::type::result>(out, delim), n, std::move(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename OutputStream, typename Gen>
|
template<typename CharT, typename Traits, typename Gen>
|
||||||
inline auto output_n(OutputStream& out, size_t n, Gen &&g) {
|
inline auto output_n(std::basic_ostream<CharT, Traits>& out, size_t n, Gen &&g) {
|
||||||
return copy_n(std::ostream_iterator<typename std::decay<Gen>::type::result>(out), n, std::move(g));
|
return copy_n(std::ostream_iterator<typename std::decay<Gen>::type::result>(out), n, std::move(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename CharT, typename Traits, typename Gen, typename Endl = decltype(std::endl<CharT, Traits>)>
|
||||||
|
inline auto outputln(std::basic_ostream<CharT, Traits>& out, const char *delim, Gen &&g, const Endl &endl = std::endl<CharT, Traits>) {
|
||||||
|
auto res = copy(std::ostream_iterator<typename std::decay<Gen>::type::result>(out, delim), std::move(g));
|
||||||
|
out << endl;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename CharT, typename Traits, typename Gen, typename Endl = decltype(std::endl<CharT, Traits>)>
|
||||||
|
inline auto outputln(std::basic_ostream<CharT, Traits>& out, Gen &&g, const Endl &endl = std::endl<CharT, Traits>) {
|
||||||
|
auto res = copy(std::ostream_iterator<typename std::decay<Gen>::type::result>(out), std::move(g));
|
||||||
|
out << endl;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename CharT, typename Traits, typename Gen, typename Endl = decltype(std::endl<CharT, Traits>)>
|
||||||
|
inline auto outputln_n(std::basic_ostream<CharT, Traits>& out, size_t n
|
||||||
|
, const char *delim, Gen &&g, const Endl &endl = std::endl<CharT, Traits>) {
|
||||||
|
auto res = copy_n(std::ostream_iterator<typename std::decay<Gen>::type::result>(out, delim), n, std::move(g));
|
||||||
|
out << endl;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename CharT, typename Traits, typename Gen, typename Endl = decltype(std::endl<CharT, Traits>)>
|
||||||
|
inline auto outputln_n(std::basic_ostream<CharT, Traits>& out, size_t n, Gen &&g, const Endl &endl = std::endl<CharT, Traits>) {
|
||||||
|
auto res = copy_n(std::ostream_iterator<typename std::decay<Gen>::type::result>(out), n, std::move(g));
|
||||||
|
out << endl;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename CharT, typename Traits, typename Endl = decltype(std::endl<CharT, Traits>)>
|
||||||
|
inline void outputln(std::basic_ostream<CharT, Traits>& out, const Endl &endl = std::endl<CharT, Traits>) {
|
||||||
|
out << endl;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user