Skip to content

Commit 0bd4945

Browse files
committed
restructure: change explicitness of ctors.
This commit follows applies the google-explicit-constructor rules as the default: * all ctors are explicit, * except ctors using the initializer list, those are never explicit. Exceptions are made for cases where conversion has little risk of being bugprone, e.g. because the type of the argument of the ctor is closely linked to the object being constructed.
1 parent 5bb7ace commit 0bd4945

File tree

9 files changed

+26
-26
lines changed

9 files changed

+26
-26
lines changed

include/highfive/H5DataSet.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class DataSet: public Object,
103103
protected:
104104
using Object::Object; // bring DataSet(hid_t)
105105

106-
DataSet(Object&& o) noexcept
106+
explicit DataSet(Object&& o) noexcept
107107
: Object(std::move(o)) {}
108108

109109
friend class Reference;

include/highfive/H5DataType.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class VariableLengthStringType: public StringType {
176176
///
177177
/// \brief Create a variable length string HDF5 datatype.
178178
///
179-
VariableLengthStringType(CharacterSet character_set = CharacterSet::Ascii);
179+
explicit VariableLengthStringType(CharacterSet character_set = CharacterSet::Ascii);
180180
};
181181

182182

@@ -231,7 +231,7 @@ class CompoundType: public DataType {
231231
///
232232
/// \brief Initializes a compound type from a DataType
233233
/// \param type
234-
inline CompoundType(DataType&& type)
234+
inline explicit CompoundType(DataType&& type)
235235
: DataType(type) {
236236
if (getClass() != DataTypeClass::Compound) {
237237
std::ostringstream ss;

include/highfive/H5Exception.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace HighFive {
2222
///
2323
class Exception: public std::exception {
2424
public:
25-
Exception(const std::string& err_msg)
25+
explicit Exception(const std::string& err_msg)
2626
: _errmsg(err_msg) {}
2727

2828
Exception(const Exception& other) = default;
@@ -87,7 +87,7 @@ class Exception: public std::exception {
8787
///
8888
class ObjectException: public Exception {
8989
public:
90-
ObjectException(const std::string& err_msg)
90+
explicit ObjectException(const std::string& err_msg)
9191
: Exception(err_msg) {}
9292
};
9393

@@ -96,7 +96,7 @@ class ObjectException: public Exception {
9696
///
9797
class DataTypeException: public Exception {
9898
public:
99-
DataTypeException(const std::string& err_msg)
99+
explicit DataTypeException(const std::string& err_msg)
100100
: Exception(err_msg) {}
101101
};
102102

@@ -105,7 +105,7 @@ class DataTypeException: public Exception {
105105
///
106106
class FileException: public Exception {
107107
public:
108-
FileException(const std::string& err_msg)
108+
explicit FileException(const std::string& err_msg)
109109
: Exception(err_msg) {}
110110
};
111111

@@ -114,7 +114,7 @@ class FileException: public Exception {
114114
///
115115
class DataSpaceException: public Exception {
116116
public:
117-
DataSpaceException(const std::string& err_msg)
117+
explicit DataSpaceException(const std::string& err_msg)
118118
: Exception(err_msg) {}
119119
};
120120

@@ -123,7 +123,7 @@ class DataSpaceException: public Exception {
123123
///
124124
class AttributeException: public Exception {
125125
public:
126-
AttributeException(const std::string& err_msg)
126+
explicit AttributeException(const std::string& err_msg)
127127
: Exception(err_msg) {}
128128
};
129129

@@ -132,7 +132,7 @@ class AttributeException: public Exception {
132132
///
133133
class DataSetException: public Exception {
134134
public:
135-
DataSetException(const std::string& err_msg)
135+
explicit DataSetException(const std::string& err_msg)
136136
: Exception(err_msg) {}
137137
};
138138

@@ -141,7 +141,7 @@ class DataSetException: public Exception {
141141
///
142142
class GroupException: public Exception {
143143
public:
144-
GroupException(const std::string& err_msg)
144+
explicit GroupException(const std::string& err_msg)
145145
: Exception(err_msg) {}
146146
};
147147

@@ -150,7 +150,7 @@ class GroupException: public Exception {
150150
///
151151
class PropertyException: public Exception {
152152
public:
153-
PropertyException(const std::string& err_msg)
153+
explicit PropertyException(const std::string& err_msg)
154154
: Exception(err_msg) {}
155155
};
156156

@@ -159,7 +159,7 @@ class PropertyException: public Exception {
159159
///
160160
class ReferenceException: public Exception {
161161
public:
162-
ReferenceException(const std::string& err_msg)
162+
explicit ReferenceException(const std::string& err_msg)
163163
: Exception(err_msg) {}
164164
};
165165
} // namespace HighFive

include/highfive/H5Group.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Group: public Object,
5656
return details::get_plist<GroupCreateProps>(*this, H5Gget_create_plist);
5757
}
5858

59-
Group(Object&& o) noexcept
59+
explicit Group(Object&& o) noexcept
6060
: Object(std::move(o)) {};
6161

6262
protected:

include/highfive/H5Utility.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace HighFive {
2323
///
2424
class SilenceHDF5 {
2525
public:
26-
inline SilenceHDF5(bool enable = true)
26+
inline explicit SilenceHDF5(bool enable = true)
2727
: _client_data(nullptr) {
2828
detail::nothrow::h5e_get_auto2(H5E_DEFAULT, &_func, &_client_data);
2929

include/highfive/bits/H5Iterables_misc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace details {
2121
// iterator for H5 iterate
2222

2323
struct HighFiveIterateData {
24-
inline HighFiveIterateData(std::vector<std::string>& my_names)
24+
explicit HighFiveIterateData(std::vector<std::string>& my_names)
2525
: names(my_names)
2626
, err(nullptr) {}
2727

include/highfive/bits/H5Slice_traits.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class ElementSet {
2727
///
2828
/// \param list List of continuous coordinates (e.g.: in 2 dimensions space
2929
/// `ElementSet{1, 2, 3 ,4}` creates points `(1, 2)` and `(3, 4)`).
30-
explicit ElementSet(std::initializer_list<std::size_t> list);
30+
ElementSet(std::initializer_list<std::size_t> list);
3131
///
3232
/// \brief Create a list of points of N-dimension for selection.
3333
///
3434
/// \param list List of N-dim points.
35-
explicit ElementSet(std::initializer_list<std::vector<std::size_t>> list);
35+
ElementSet(std::initializer_list<std::vector<std::size_t>> list);
3636
///
3737
/// \brief Create a list of points of N-dimension for selection.
3838
///
@@ -63,10 +63,10 @@ inline std::vector<size_t> toSTLSizeVector(const std::vector<hsize_t>& from) {
6363
struct RegularHyperSlab {
6464
RegularHyperSlab() = default;
6565

66-
RegularHyperSlab(const std::vector<size_t>& offset_,
67-
const std::vector<size_t>& count_ = {},
68-
const std::vector<size_t>& stride_ = {},
69-
const std::vector<size_t>& block_ = {})
66+
explicit RegularHyperSlab(const std::vector<size_t>& offset_,
67+
const std::vector<size_t>& count_ = {},
68+
const std::vector<size_t>& stride_ = {},
69+
const std::vector<size_t>& block_ = {})
7070
: offset(toHDF5SizeVector(offset_))
7171
, count(toHDF5SizeVector(count_))
7272
, stride(toHDF5SizeVector(stride_))

include/highfive/bits/H5Slice_traits_misc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ inline ElementSet::ElementSet(const std::vector<std::vector<std::size_t>>& eleme
6969
namespace detail {
7070
class HyperCube {
7171
public:
72-
HyperCube(size_t rank)
72+
explicit HyperCube(size_t rank)
7373
: offset(rank)
7474
, count(rank) {}
7575

tests/unit/tests_high_five_data_type.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,10 @@ TEST_CASE("HighFiveReadType") {
395395

396396
File file(file_name, File::ReadWrite | File::Create | File::Truncate);
397397

398-
CompoundType t1 = create_compound_csl1();
398+
auto t1 = create_compound_csl1();
399399
t1.commit(file, datatype_name1);
400400

401-
CompoundType t2 = file.getDataType(datatype_name1);
401+
auto t2 = CompoundType(file.getDataType(datatype_name1));
402402

403403
auto t3 = create_enum_position();
404404
t3.commit(file, datatype_name2);
@@ -407,4 +407,4 @@ TEST_CASE("HighFiveReadType") {
407407

408408
CHECK(t2 == t1);
409409
CHECK(t4 == t3);
410-
}
410+
}

0 commit comments

Comments
 (0)