Skip to content

Commit 61c8878

Browse files
committed
Updated style [skip ci]
1 parent 321185e commit 61c8878

7 files changed

Lines changed: 16 additions & 16 deletions

File tree

examples/cohere/example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ std::vector<std::string> embed(const std::vector<std::string>& texts, const std:
2828
cpr::Header{{"Content-Type", "application/json"}}
2929
);
3030
if (r.status_code != 200) {
31-
throw std::runtime_error("Bad status: " + std::to_string(r.status_code));
31+
throw std::runtime_error{"Bad status: " + std::to_string(r.status_code)};
3232
}
3333
json response = json::parse(r.text);
3434

examples/hybrid/example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ std::vector<std::vector<float>> embed(const std::vector<std::string>& texts, con
3333
cpr::Header{{"Content-Type", "application/json"}}
3434
);
3535
if (r.status_code != 200) {
36-
throw std::runtime_error("Bad status: " + std::to_string(r.status_code));
36+
throw std::runtime_error{"Bad status: " + std::to_string(r.status_code)};
3737
}
3838
json response = json::parse(r.text);
3939

examples/openai/example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ std::vector<std::vector<float>> embed(const std::vector<std::string>& input, cha
2525
cpr::Header{{"Content-Type", "application/json"}}
2626
);
2727
if (r.status_code != 200) {
28-
throw std::runtime_error("Bad status: " + std::to_string(r.status_code));
28+
throw std::runtime_error{"Bad status: " + std::to_string(r.status_code)};
2929
}
3030
json response = json::parse(r.text);
3131

examples/sparse/example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ std::vector<pgvector::SparseVector> embed(const std::vector<std::string>& inputs
2929
cpr::Header{{"Content-Type", "application/json"}}
3030
);
3131
if (r.status_code != 200) {
32-
throw std::runtime_error("Bad status: " + std::to_string(r.status_code));
32+
throw std::runtime_error{"Bad status: " + std::to_string(r.status_code)};
3333
}
3434
json response = json::parse(r.text);
3535

include/pgvector/pqxx.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ template<> struct nullness<pgvector::Vector> : no_null<pgvector::Vector> {};
2828
template<> struct string_traits<pgvector::Vector> {
2929
static pgvector::Vector from_string(std::string_view text, ctx c = {}) {
3030
if (text.size() < 2 || text.front() != '[' || text.back() != ']') {
31-
throw conversion_error("Malformed vector literal");
31+
throw conversion_error{"Malformed vector literal"};
3232
}
3333

3434
std::vector<float> values;
@@ -96,7 +96,7 @@ template<> struct nullness<pgvector::HalfVector> : no_null<pgvector::HalfVector>
9696
template<> struct string_traits<pgvector::HalfVector> {
9797
static pgvector::HalfVector from_string(std::string_view text, ctx c = {}) {
9898
if (text.size() < 2 || text.front() != '[' || text.back() != ']') {
99-
throw conversion_error("Malformed halfvec literal");
99+
throw conversion_error{"Malformed halfvec literal"};
100100
}
101101

102102
std::vector<pgvector::Half> values;
@@ -164,17 +164,17 @@ template<> struct nullness<pgvector::SparseVector> : no_null<pgvector::SparseVec
164164
template<> struct string_traits<pgvector::SparseVector> {
165165
static pgvector::SparseVector from_string(std::string_view text, ctx c = {}) {
166166
if (text.size() < 4 || text.front() != '{') {
167-
throw conversion_error("Malformed sparsevec literal");
167+
throw conversion_error{"Malformed sparsevec literal"};
168168
}
169169

170170
size_t n = text.find("}/", 1);
171171
if (n == std::string_view::npos) {
172-
throw conversion_error("Malformed sparsevec literal");
172+
throw conversion_error{"Malformed sparsevec literal"};
173173
}
174174

175175
int dimensions = pqxx::from_string<int>(text.substr(n + 2), c);
176176
if (dimensions < 0) {
177-
throw conversion_error("Dimensions cannot be negative");
177+
throw conversion_error{"Dimensions cannot be negative"};
178178
}
179179

180180
std::vector<int> indices;
@@ -184,14 +184,14 @@ template<> struct string_traits<pgvector::SparseVector> {
184184
auto add_element = [&](std::string_view substr) {
185185
size_t ne = substr.find(":");
186186
if (ne == std::string::npos) {
187-
throw conversion_error("Malformed sparsevec literal");
187+
throw conversion_error{"Malformed sparsevec literal"};
188188
}
189189

190190
int index = pqxx::from_string<int>(substr.substr(0, ne), c);
191191
float value = pqxx::from_string<float>(substr.substr(ne + 1), c);
192192

193193
if (index < 1) {
194-
throw conversion_error("Index out of bounds");
194+
throw conversion_error{"Index out of bounds"};
195195
}
196196

197197
indices.push_back(index - 1);

include/pgvector/sparsevec.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SparseVector {
2121
/// @private
2222
SparseVector(int dimensions, std::vector<int>&& indices, std::vector<float>&& values) {
2323
if (values.size() != indices.size()) {
24-
throw std::invalid_argument("indices and values must be the same length");
24+
throw std::invalid_argument{"indices and values must be the same length"};
2525
}
2626
dimensions_ = dimensions;
2727
indices_ = std::move(indices);
@@ -55,13 +55,13 @@ class SparseVector {
5555
/// Creates a sparse vector from a map of non-zero elements.
5656
SparseVector(const std::unordered_map<int, float>& map, int dimensions) {
5757
if (dimensions < 1) {
58-
throw std::invalid_argument("sparsevec must have at least 1 dimension");
58+
throw std::invalid_argument{"sparsevec must have at least 1 dimension"};
5959
}
6060
dimensions_ = dimensions;
6161

6262
for (const auto& [i, v] : map) {
6363
if (i < 0 || i >= dimensions) {
64-
throw std::invalid_argument("sparsevec index out of bounds");
64+
throw std::invalid_argument{"sparsevec index out of bounds"};
6565
}
6666

6767
if (v != 0) {

test/helper.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void assert_equal(const T& left, const U& right, const std::source_location& loc
1212
std::ostringstream message;
1313
message << left << " != " << right;
1414
message << " in " << loc.function_name() << " " << loc.file_name() << ":" << loc.line();
15-
throw std::runtime_error(message.str());
15+
throw std::runtime_error{message.str()};
1616
}
1717
}
1818

@@ -26,6 +26,6 @@ void assert_exception(std::function<void(void)> code, std::optional<std::string_
2626
}
2727
assert_equal(exception.has_value(), true);
2828
if (message) {
29-
assert_equal(std::string_view((*exception).what()), *message);
29+
assert_equal(std::string_view{(*exception).what()}, *message);
3030
}
3131
}

0 commit comments

Comments
 (0)