|
Boost Users : |
Subject: Re: [Boost-users] Data type to handle C++ and Boost streams?
From: Richard (legalize+jeeves_at_[hidden])
Date: 2009-09-13 10:57:19
[Please do not mail me a copy of your followup]
boost-users_at_[hidden] spake the secret code
<h8hjl9$5h0$1_at_[hidden]> thusly:
>Bit of a basic question - I'd like to have some functions that work with files
>(using std::fstream) but can also handle boost::iostreams. Is there a data
>type I can use that can handle both? For example:
>
> void writeSomeData(std::fstream out);
>
>I can't pass a boost::iostream::stream to this function. What type can I use
>to achieve this?
Use the common base of std::basic_istream, std::basic_ostream,
std::basic_iostream.
I describe doing this in order to be able to unit test file handling
code with a string stream in this blog post:
How Do I Unit Test Something That Writes To A File? <http://wp.me/pyVNs-V>
-- "The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download <http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/> Legalize Adulthood! <http://legalizeadulthood.wordpress.com>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net