Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef IO_HPP_
- #define IO_HPP_
- #include <iostream>
- #include "exception.hpp"
- namespace ws {
- namespace io {
- inline void write(const std::string& s){
- if(long(s.find('%')) >= 0)
- throw Exception("writeln: expected argument for each %");
- std::cout << s;
- }
- inline void write(const std::wstring& s){
- if(long(s.find('%')) >= 0)
- throw Exception("writeln: expected argument for each %");
- std::wcout << s;
- }
- template<typename T>
- inline void write(const T& o){
- std::cout << o;
- }
- inline void writeln(const std::string& s){
- if(long(s.find('%')) >= 0)
- throw Exception("writeln: expected argument for each %");
- std::cout << s << std::endl;
- }
- inline void writeln(const std::wstring& s){
- if(long(s.find('%')) >= 0)
- throw Exception("writeln: expected argument for each %");
- std::wcout << s << std::endl;
- }
- template<typename T>
- inline void writeln(const T& o){
- std::cout << o << std::endl;
- }
- template<typename T, typename... Args>
- inline void writeln(std::string s, T value, Args... args) {
- if(s.find('%') >= 0){
- long i = s.find('%');
- write(s.substr(0, i));
- write(value);
- s.erase(0, i+1);
- writeln(s, args...);
- }else
- throw Exception("writeln: expected argument IDs (%)");
- }
- template<typename T, typename... Args>
- inline void writeln(std::wstring s, T value, Args... args) {
- if(s.find('%') >= 0){
- long i = s.find('%');
- write(s.substr(0, i));
- write(value);
- s.erase(0, i+1);
- writeln(s, args...);
- }else
- throw Exception("writeln: expected argument IDs (%)");
- }
- }
- }
- #endif /* IO_HPP_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement