diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2014-05-06 12:35:50 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2014-05-06 12:35:50 +0200 |
| commit | a8d753c769fb98dc27066aed0f4df8fe101ad842 (patch) | |
| tree | c38bc3c6a2ee513a565364a6686f5b3f2c2d899e /fusion_outputter.hpp | |
| parent | dfefe42d0fe40dd97260d3ec0b3e1cb7690cf669 (diff) | |
| download | generic-gui-a8d753c769fb98dc27066aed0f4df8fe101ad842.tar.gz generic-gui-a8d753c769fb98dc27066aed0f4df8fe101ad842.tar.bz2 generic-gui-a8d753c769fb98dc27066aed0f4df8fe101ad842.zip | |
Cleaned up the interface a bit more.
Diffstat (limited to 'fusion_outputter.hpp')
| -rw-r--r-- | fusion_outputter.hpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/fusion_outputter.hpp b/fusion_outputter.hpp new file mode 100644 index 0000000..d148c8d --- /dev/null +++ b/fusion_outputter.hpp @@ -0,0 +1,78 @@ +#pragma once + +#include "friendly_fusion.hpp" + +#include <boost/fusion/include/pair.hpp> +#include <boost/fusion/include/map.hpp> +#include <boost/fusion/include/vector.hpp> + +#include <iostream> +#include <ostream> +#include <vector> +#include <string> + +//Workaround for argument dependent lookup +namespace std +{ + +struct Outputter +{ + template <typename I, typename E> + static typename std::enable_if<!std::is_same<I,E>::value, std::ostream&>::type + output(std::ostream& os, I const& it, E const& end) + { + if(std::is_same<typename std::decay<typename friendly_fusion::result_of::deref<I>::type>::type, bool>::value) { + os << std::boolalpha; + } + + os << friendly_fusion::deref(it); + + if(!std::is_same<typename friendly_fusion::result_of::advance_c<I, 1>::type, E>::value) { + os << ", "; + } + + return Outputter::output(os, friendly_fusion::advance_c<1>(it), end); + } + + template <typename I, typename E> + static typename std::enable_if<std::is_same<I,E>::value, std::ostream&>::type + output(std::ostream& os, I const&, E const&) + { + return os; + } + + +}; + +template <typename T, typename U> +std::ostream& operator<<(std::ostream& os, std::map<T, U> map) +{ + os << "{" << std::endl; + for (auto&& x : map) { + os << "\t{" << x.first << ", " << x.second << "}" << std::endl; + } + os << "}" << std::endl; + return os; +} + +template <typename T> +std::ostream& operator<<(std::ostream& os, std::vector<T> vec) +{ + os << "{" << std::endl; + for (auto&& x : vec) { + os << "\t" << x << std::endl; + } + os << "}" << std::endl; + return os; +} + +template <typename T> +typename std::enable_if<friendly_fusion::traits::is_sequence<T>::value, std::ostream&>::type +operator<<(std::ostream& os, T x) +{ + return std::Outputter::output(os, friendly_fusion::begin(x), friendly_fusion::end(x)); +} + +} + + |
