Skip to content

Commit

Permalink
Add util::algorithm::raw_type
Browse files Browse the repository at this point in the history
Signed-off-by: janus_wel <janus.wel.3@gmail.com>
  • Loading branch information
januswel committed Jun 18, 2010
1 parent 2b0e6e8 commit 75fe431
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions header/algorithm.hpp
Expand Up @@ -23,6 +23,15 @@ namespace util {
void operator()(T* p) { delete p; }
};

// for binary operation
struct raw_type { char c; };
std::istream& operator >>(std::istream& in, raw_type& r) {
return in.get(r.c);
}
std::ostream& operator <<(std::ostream& out, const raw_type& r) {
return out.put(r.c);
}

// copy_if
template< typename InputIterator, typename OstreamIterator,
typename Predicate>
Expand Down
7 changes: 7 additions & 0 deletions sample/algorithm/main.cpp
Expand Up @@ -16,6 +16,7 @@
#include <locale>
#include <string>
#include <vector>
#include <fstream>

template<typename Char>
inline bool is(const std::ctype_base::mask mask, const Char c) {
Expand Down Expand Up @@ -108,6 +109,12 @@ int main(const int argc, const char* const argv[]) {
std::cout, "\n",
util::algorithm::basic_progress<std::string, unsigned int>(
std::cerr, 1, params.size()));

std::cout << "binary operation\n";
std::ifstream fin("main.cpp", std::ios_base::binary);
std::istream_iterator<util::algorithm::raw_type> iitr(fin), end;
util::algorithm::print<util::algorithm::raw_type>(iitr, end, std::cout, "");

std::cerr << std::endl;

return 0;
Expand Down

0 comments on commit 75fe431

Please sign in to comment.