Skip to content

Commit

Permalink
Merge pull request #61 from mateidavid/gcc4_8
Browse files Browse the repository at this point in the history
allow backward compatibility with gcc 4.8
  • Loading branch information
ferdymercury authored Dec 6, 2022
2 parents 3fdb027 + 8d9cb19 commit 755da78
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Method 3. Add path containing 'zstr.hpp' to your target's include directories

**** Requisites

If you use GCC, you need to deploy at least version 5.1.
If you use GCC and want to use the `fs.open()` function, you need to deploy at least GCC version 5.1.

**** License

Expand Down
12 changes: 12 additions & 0 deletions src/zstr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
#include <iostream>
#include "strict_fstream.hpp"

#if defined(__GNUC__) && !defined(__clang__)
#if (__GNUC__ > 5) || (__GNUC__ == 5 && __GNUC_MINOR__>0)
#define CAN_MOVE_IOSTREAM
#endif
#else
#define CAN_MOVE_IOSTREAM
#endif

namespace zstr
{

Expand Down Expand Up @@ -423,10 +431,12 @@ class ifstream
void close() {
_fs.close();
}
#ifdef CAN_MOVE_IOSTREAM
void open(const std::string filename, std::ios_base::openmode mode = std::ios_base::in) {
_fs.open(filename, mode);
std::istream::operator=(std::istream(new istreambuf(_fs.rdbuf())));
}
#endif
bool is_open() const {
return _fs.is_open();
}
Expand Down Expand Up @@ -460,11 +470,13 @@ class ofstream
std::ostream::flush();
_fs.close();
}
#ifdef CAN_MOVE_IOSTREAM
void open(const std::string filename, std::ios_base::openmode mode = std::ios_base::out, int level = Z_DEFAULT_COMPRESSION) {
flush();
_fs.open(filename, mode | std::ios_base::binary);
std::ostream::operator=(std::ostream(new ostreambuf(_fs.rdbuf(), default_buff_size, level)));
}
#endif
bool is_open() const {
return _fs.is_open();
}
Expand Down

0 comments on commit 755da78

Please sign in to comment.