Comments (5)
Would you like to create a pull request, adding this to show.hpp
, and, if you like, your test case from above to show_test.cpp
?
from functionalplus.
Hi, thanks for the positive feedback and the excellent idea.
So far, there is nothing in FunctionalPlus to print tuples.
To keep it generic (and reuse the separator/prefix/suffix logic from the fplus::show_cont...
function family), I guess it would make sense not to add something to directly print a tuple but to just convert it into a list of strings.
Would you like to give the implementation a try in a pull request?
Otherwise, I'd see if I can do something, based on the cppreference example.
from functionalplus.
Thanks for the swift reply.
To keep it generic (and reuse the separator/prefix/suffix logic from the
fplus::show_cont...
function family), I guess it would make sense not to add something to directly print a tuple but to just convert it into a list of strings.
You mean using stringstream instead of iostream ?
from functionalplus.
This could do the job:
#include <iostream>
#include <tuple>
#include <string>
#include <sstream>
#include <list>
template<class Tuple, std::size_t N>
struct TuplePrinter {
static void print(const Tuple& t, std::list<std::string>& sl)
{
TuplePrinter<Tuple, N-1>::print(t,sl);
std::stringstream ss;
ss << std::get<N-1>(t);
sl.emplace_back(ss.str());
}
};
template<class Tuple>
struct TuplePrinter<Tuple, 1> {
static void print(const Tuple& t, std::list<std::string>& sl)
{
std::stringstream ss;
ss << std::get<0>(t);
sl.emplace_back(ss.str());
}
};
template<typename... Args, std::enable_if_t<sizeof...(Args) == 0, int> = 0>
void print(const std::tuple<Args...>& t, std::list<std::string>& sl)
{
return;
}
template<typename... Args, std::enable_if_t<sizeof...(Args) != 0, int> = 0>
std::list<std::string> print(const std::tuple<Args...>& t)
{
std::list<std::string> sl;
TuplePrinter<decltype(t), sizeof...(Args)>::print(t,sl);
return std::move(sl);
}
int main() {
std::tuple<int, std::string, float> t1(10, "Test", 3.14);
std::list<std::string> lt1 = print(t1);
for(auto &l : lt1) std::cout << l << ", ";
}
from functionalplus.
Yes, exactly!
And then, one could use std::cout << fplus::show_cont(lt1);
instead of for(auto &l : lt1) std::cout << l << ", ";
.
from functionalplus.
Related Issues (20)
- Clean install rules up? HOT 1
- Reconsider install location HOT 11
- implement either class HOT 2
- implement drop_last_while method HOT 2
- Unit tests always succeeding, even when breaking them on purpose HOT 5
- Consecutive build should only re-build changed files instead of all. (Circular build dependency in CMake setup?) HOT 2
- error: exception handling disabled, use ‘-fexceptions’ to enable HOT 1
- keep_by_idx() returns list of empty elements. HOT 4
- Branch `master` will be renamed to `main` in November HOT 1
- 0.2.16-p0: Tests fail to build: "EQUAL" "1" Unknown arguments specified HOT 10
- Cannot compile with gcc 11.2 in C++20 mode HOT 3
- make c++ class function to c pointer HOT 7
- Add int overrides for (some) size_t params as a convenience for fplus::fwd? HOT 3
- fplus::compose with yet unknown output type HOT 3
- parallel_for ? (no, this is not the 1st of April ;-) HOT 3
- IO Monad HOT 5
- composition.hpp uses std::result_of HOT 5
- Some List Functions (in particular, fplus::transform etc.) do not work with custom container. What needs to be added? HOT 6
- Clang 16: incompatible initializer of type (container_common_test) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from functionalplus.