Skip to content

Commit e25311b

Browse files
committed
Updated example [skip ci]
1 parent 2b84a56 commit e25311b

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

examples/disco/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 20)
66

77
include(FetchContent)
88

9-
FetchContent_Declare(disco GIT_REPOSITORY https://github.com/ankane/disco-cpp.git GIT_TAG v0.1.3)
9+
FetchContent_Declare(disco GIT_REPOSITORY https://github.com/ankane/disco-cpp.git GIT_TAG v0.1.4)
1010
FetchContent_Declare(libpqxx GIT_REPOSITORY https://github.com/jtv/libpqxx.git GIT_TAG 8.0.0)
1111
FetchContent_MakeAvailable(disco libpqxx)
1212

examples/disco/example.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#include <cassert>
21
#include <cstdlib>
32
#include <fstream>
43
#include <iostream>
54
#include <sstream>
5+
#include <stdexcept>
66
#include <string>
77
#include <unordered_map>
88
#include <utility>
@@ -32,19 +32,24 @@ Dataset<int, std::string> load_movielens(const std::string& path) {
3232
// read movies
3333
std::unordered_map<std::string, std::string> movies;
3434
std::ifstream movies_file(path + "/u.item");
35-
assert(movies_file.is_open());
35+
if (!movies_file.is_open()) {
36+
throw std::runtime_error{"Could not open file"};
37+
}
3638
while (std::getline(movies_file, line)) {
3739
std::string::size_type n = line.find('|');
3840
std::string::size_type n2 = line.find('|', n + 1);
3941
movies.emplace(
40-
std::make_pair(line.substr(0, n), convert_to_utf8(line.substr(n + 1, n2 - n - 1)))
42+
line.substr(0, n),
43+
convert_to_utf8(line.substr(n + 1, n2 - n - 1))
4144
);
4245
}
4346

4447
// read ratings and create dataset
4548
Dataset<int, std::string> data;
4649
std::ifstream ratings_file(path + "/u.data");
47-
assert(ratings_file.is_open());
50+
if (!ratings_file.is_open()) {
51+
throw std::runtime_error{"Could not open file"};
52+
}
4853
while (std::getline(ratings_file, line)) {
4954
std::string::size_type n = line.find('\t');
5055
std::string::size_type n2 = line.find('\t', n + 1);

0 commit comments

Comments
 (0)