Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow backward compatibility with gcc 4.8 #61

Merged
merged 2 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <memory>
#include <iostream>

#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