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

Making it compatible with gcc 4.8 #150

Merged
merged 1 commit into from
Jul 15, 2020
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
3 changes: 2 additions & 1 deletion include/inja/environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ class Environment {
}

json load_json(const std::string &filename) {
std::ifstream file = open_file_or_throw(input_path + filename);
std::ifstream file;
open_file_or_throw(input_path + filename, file);
json j;
file >> j;
return j;
Expand Down
3 changes: 2 additions & 1 deletion include/inja/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ class Parser {
}

std::string load_file(nonstd::string_view filename) {
std::ifstream file = open_file_or_throw(static_cast<std::string>(filename));
std::ifstream file;
open_file_or_throw(static_cast<std::string>(filename), file);
std::string text((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
return text;
}
Expand Down
4 changes: 1 addition & 3 deletions include/inja/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@

namespace inja {

inline std::ifstream open_file_or_throw(const std::string &path) {
std::ifstream file;
inline void open_file_or_throw(const std::string &path, std::ifstream &file) {
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try {
file.open(path);
} catch (const std::ios_base::failure & /*e*/) {
throw FileError("failed accessing file at '" + path + "'");
}
return file;
}

namespace string_view {
Expand Down
10 changes: 5 additions & 5 deletions single_include/inja/inja.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1829,15 +1829,13 @@ struct Token {

namespace inja {

inline std::ifstream open_file_or_throw(const std::string &path) {
std::ifstream file;
inline void open_file_or_throw(const std::string &path, std::ifstream &file) {
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try {
file.open(path);
} catch (const std::ios_base::failure & /*e*/) {
throw FileError("failed accessing file at '" + path + "'");
}
return file;
}

namespace string_view {
Expand Down Expand Up @@ -3222,7 +3220,8 @@ class Parser {
}

std::string load_file(nonstd::string_view filename) {
std::ifstream file = open_file_or_throw(static_cast<std::string>(filename));
std::ifstream file;
open_file_or_throw(static_cast<std::string>(filename), file);
std::string text((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
return text;
}
Expand Down Expand Up @@ -3971,7 +3970,8 @@ class Environment {
}

json load_json(const std::string &filename) {
std::ifstream file = open_file_or_throw(input_path + filename);
std::ifstream file;
open_file_or_throw(input_path + filename, file);
json j;
file >> j;
return j;
Expand Down