Skip to content

Commit 2135e5a

Browse files
limqiyingfacebook-github-bot
authored andcommitted
add missing explicit specifier (#4564)
Summary: Pull Request resolved: #4564 The C++ Core Guidelines recommend marking single-argument constructors as `explicit` unless implicit conversion is specifically intended. (if implicit conversion is needed for any of these, let me know!) Reviewed By: junjieqi Differential Revision: D81175916 fbshipit-source-id: f7167a3042e65d585c0f8c8265efa61b3dd1de4e
1 parent 0031d61 commit 2135e5a

9 files changed

Lines changed: 16 additions & 15 deletions

File tree

faiss/IVFlib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct SlidingIndexWindow {
100100
std::vector<std::vector<size_t>> sizes;
101101

102102
/// index should be initially empty and trained
103-
SlidingIndexWindow(Index* index);
103+
explicit SlidingIndexWindow(Index* index);
104104

105105
/** Add one index to the current index and remove the oldest one.
106106
*

faiss/IndexIVFRaBitQ.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ struct RaBitInvertedListScanner : InvertedListScanner {
156156

157157
uint8_t qb = 0;
158158

159-
RaBitInvertedListScanner(
159+
explicit RaBitInvertedListScanner(
160160
const IndexIVFRaBitQ& ivf_rabitq_in,
161161
bool store_pairs = false,
162162
const IDSelector* sel = nullptr,

faiss/IndexRaBitQ.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct IndexRaBitQ : IndexFlatCodes {
2828

2929
IndexRaBitQ();
3030

31-
IndexRaBitQ(idx_t d, MetricType metric = METRIC_L2);
31+
explicit IndexRaBitQ(idx_t d, MetricType metric = METRIC_L2);
3232

3333
void train(idx_t n, const float* x) override;
3434

faiss/impl/IDSelector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct IDSelectorBitmap : IDSelector {
116116
/** reverts the membership test of another selector */
117117
struct IDSelectorNot : IDSelector {
118118
const IDSelector* sel;
119-
IDSelectorNot(const IDSelector* sel) : sel(sel) {}
119+
explicit IDSelectorNot(const IDSelector* sel) : sel(sel) {}
120120
bool is_member(idx_t id) const final {
121121
return !sel->is_member(id);
122122
}

faiss/impl/io.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ struct FileIOReader : IOReader {
6565
FILE* f = nullptr;
6666
bool need_close = false;
6767

68-
FileIOReader(FILE* rf);
68+
explicit FileIOReader(FILE* rf);
6969

70-
FileIOReader(const char* fname);
70+
explicit FileIOReader(const char* fname);
7171

7272
~FileIOReader() override;
7373

@@ -80,9 +80,9 @@ struct FileIOWriter : IOWriter {
8080
FILE* f = nullptr;
8181
bool need_close = false;
8282

83-
FileIOWriter(FILE* wf);
83+
explicit FileIOWriter(FILE* wf);
8484

85-
FileIOWriter(const char* fname);
85+
explicit FileIOWriter(const char* fname);
8686

8787
~FileIOWriter() override;
8888

faiss/impl/mapped_io.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct MmappedFileMappingOwner::PImpl {
3333
void* ptr = nullptr;
3434
size_t ptr_size = 0;
3535

36-
PImpl(const std::string& filename) {
36+
explicit PImpl(const std::string& filename) {
3737
auto f = std::unique_ptr<FILE, decltype(&fclose)>(
3838
fopen(filename.c_str(), "r"), &fclose);
3939
FAISS_THROW_IF_NOT_FMT(
@@ -64,7 +64,7 @@ struct MmappedFileMappingOwner::PImpl {
6464
ptr_size = filesize;
6565
}
6666

67-
PImpl(FILE* f) {
67+
explicit PImpl(FILE* f) {
6868
// get the size
6969
struct stat s;
7070
int status = fstat(fileno(f), &s);

faiss/impl/mapped_io.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ namespace faiss {
1818

1919
// holds a memory-mapped region over a file
2020
struct MmappedFileMappingOwner : public MaybeOwnedVectorOwner {
21-
MmappedFileMappingOwner(const std::string& filename);
22-
MmappedFileMappingOwner(FILE* f);
21+
explicit MmappedFileMappingOwner(const std::string& filename);
22+
explicit MmappedFileMappingOwner(FILE* f);
2323
~MmappedFileMappingOwner();
2424

2525
void* data() const;
@@ -37,7 +37,8 @@ struct MappedFileIOReader : IOReader {
3737

3838
size_t pos = 0;
3939

40-
MappedFileIOReader(const std::shared_ptr<MmappedFileMappingOwner>& owner);
40+
explicit MappedFileIOReader(
41+
const std::shared_ptr<MmappedFileMappingOwner>& owner);
4142

4243
// perform a copy
4344
size_t operator()(void* ptr, size_t size, size_t nitems) override;

faiss/impl/maybe_owned_vector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct MaybeOwnedVector {
5151
size_t c_size = 0;
5252

5353
MaybeOwnedVector() = default;
54-
MaybeOwnedVector(const size_t initial_size) {
54+
explicit MaybeOwnedVector(const size_t initial_size) {
5555
is_owned = true;
5656

5757
owned_data.resize(initial_size);

tests/test_dealloc_invlists.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ std::vector<idx_t> search_index(Index* index, const float* xq) {
7070
struct EncapsulateInvertedLists : InvertedLists {
7171
const InvertedLists* il;
7272

73-
EncapsulateInvertedLists(const InvertedLists* il)
73+
explicit EncapsulateInvertedLists(const InvertedLists* il)
7474
: InvertedLists(il->nlist, il->code_size), il(il) {}
7575

7676
static void* memdup(const void* m, size_t size) {

0 commit comments

Comments
 (0)