Skip to content

Commit b386486

Browse files
authored
Use std::is_arithmetic* instead of std::is_fundamental* for type traits tests, (#1282)
because std::nullptr_t and void should not be included.
1 parent 6fc989d commit b386486

File tree

5 files changed

+25
-29
lines changed

5 files changed

+25
-29
lines changed

src/sst/core/from_string.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,16 @@ from_string(const std::string& input)
9999
return static_cast<T>(from_string<std::underlying_type_t<T>>(input));
100100
}
101101

102+
///////////////////////////////////////////////////////////////////////////////
103+
102104
template <class T>
103105
std::enable_if_t<!std::is_enum_v<T>, std::string>
104106
to_string(const T& input)
105107
{
106-
if constexpr ( std::is_fundamental_v<T> )
108+
if constexpr ( std::is_arithmetic_v<T> )
107109
return std::to_string(input);
108110
else
109-
return typeid(T).name(); // For now, return a string if the type isn't fundamental or handled elsewhere
111+
return typeid(T).name(); // For now, return a string if the type isn't handled elsewhere
110112
}
111113

112114
template <class T>
@@ -116,6 +118,7 @@ to_string(const T& input)
116118
return std::to_string(static_cast<std::underlying_type_t<T>>(input));
117119
}
118120

121+
// for std::string no-op, or class types which define operator std::string()
119122
inline std::string
120123
to_string(std::string s)
121124
{

src/sst/core/serialization/impl/serialize_array.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ raw_ptr(TPtr*& ptr)
8282

8383
/**
8484
Version of serialize that works for statically allocated arrays of
85-
fundamental types and enums.
85+
arithmetic types and enums.
8686
*/
8787
template <class T, size_t N>
88-
class serialize_impl<T[N], std::enable_if_t<std::is_fundamental_v<T> || std::is_enum_v<T>>>
88+
class serialize_impl<T[N], std::enable_if_t<std::is_arithmetic_v<T> || std::is_enum_v<T>>>
8989
{
9090
template <class A>
9191
friend class serialize;
@@ -102,7 +102,7 @@ class serialize_impl<T[N], std::enable_if_t<std::is_fundamental_v<T> || std::is_
102102
non base types.
103103
*/
104104
template <class T, size_t N>
105-
class serialize_impl<T[N], std::enable_if_t<!std::is_fundamental_v<T> && !std::is_enum_v<T>>>
105+
class serialize_impl<T[N], std::enable_if_t<!std::is_arithmetic_v<T> && !std::is_enum_v<T>>>
106106
{
107107
template <class A>
108108
friend class serialize;
@@ -120,11 +120,10 @@ class serialize_impl<T[N], std::enable_if_t<!std::is_fundamental_v<T> && !std::i
120120

121121
/**
122122
Version of serialize that works for dynamically allocated arrays of
123-
fundamental types and enums.
123+
arithmetic types and enums.
124124
*/
125125
template <class T, class IntType>
126-
class serialize_impl<
127-
pvt::ser_array_wrapper<T, IntType>, std::enable_if_t<std::is_fundamental_v<T> || std::is_enum_v<T>>>
126+
class serialize_impl<pvt::ser_array_wrapper<T, IntType>, std::enable_if_t<std::is_arithmetic_v<T> || std::is_enum_v<T>>>
128127
{
129128
template <class A>
130129
friend class serialize;
@@ -142,7 +141,7 @@ class serialize_impl<
142141
*/
143142
template <class T, class IntType>
144143
class serialize_impl<
145-
pvt::ser_array_wrapper<T, IntType>, std::enable_if_t<!std::is_fundamental_v<T> && !std::is_enum_v<T>>>
144+
pvt::ser_array_wrapper<T, IntType>, std::enable_if_t<!std::is_arithmetic_v<T> && !std::is_enum_v<T>>>
146145
{
147146
template <class A>
148147
friend class serialize;

src/sst/core/serialization/serialize.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,11 @@ class serialize<T*>
280280

281281

282282
/**
283-
Version of serialize that works for fundamental types and enums.
283+
Version of serialize that works for arithmetic and enum types.
284284
*/
285285

286286
template <class T>
287-
class serialize_impl<T, std::enable_if_t<std::is_fundamental_v<T> || std::is_enum_v<T>>>
287+
class serialize_impl<T, std::enable_if_t<std::is_arithmetic_v<T> || std::is_enum_v<T>>>
288288
{
289289
public:
290290
void operator()(T& t, serializer& ser)
@@ -300,15 +300,14 @@ class serialize_impl<T, std::enable_if_t<std::is_fundamental_v<T> || std::is_enu
300300
};
301301

302302
/**
303-
Version of serialize that works for pointers to fundamental types
304-
and enums. Note that the pointer tracking happens at a higher
305-
level, and only if it is turned on. If it is not turned on, then
306-
this only copies the value pointed to into the buffer. If multiple
307-
objects point to the same location, they will each have an
308-
independent copy after deserialization.
303+
Version of serialize that works for pointers to arithmetic and enum types.
304+
Note that the pointer tracking happens at a higher level, and only if it is
305+
turned on. If it is not turned on, then this only copies the value pointed
306+
to into the buffer. If multiple objects point to the same location, they
307+
will each have an independent copy after deserialization.
309308
*/
310309
template <class T>
311-
class serialize_impl<T*, std::enable_if_t<std::is_fundamental_v<T> || std::is_enum_v<T>>>
310+
class serialize_impl<T*, std::enable_if_t<std::is_arithmetic_v<T> || std::is_enum_v<T>>>
312311
{
313312
template <typename>
314313
friend class serialize;

src/sst/core/statapi/statbase.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,11 @@ class StatisticBase
318318
/**
319319
\class StatisticCollector
320320
* Base type that creates the virtual addData(...) interface
321-
* Used for distinguishing fundamental types (collected by value)
321+
* Used for distinguishing arithmetic types (collected by value)
322322
* and composite struct types (collected by reference)
323323
*/
324-
template <class T, bool = std::is_fundamental_v<T>>
325-
struct StatisticCollector
326-
{};
324+
template <class T, bool = std::is_arithmetic_v<T>>
325+
struct StatisticCollector;
327326

328327
template <class T>
329328
struct StatisticCollector<T, true>

src/sst/core/statapi/statnull.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ namespace SST::Statistics {
3434
3535
@tparam T A template for holding the main data type of this statistic
3636
*/
37-
template <class T, bool = std::is_fundamental_v<T>>
38-
class NullStatisticBase
39-
{};
37+
template <class T, bool = std::is_arithmetic_v<T>>
38+
class NullStatisticBase;
4039

4140
template <class T>
4241
class NullStatisticBase<T, true> : public Statistic<T>
@@ -137,12 +136,9 @@ class NullStatistic : public NullStatisticBase<T>
137136
static bool isLoaded() { return loaded_; }
138137

139138
private:
140-
static bool loaded_;
139+
inline static bool loaded_ = true;
141140
};
142141

143-
template <class T>
144-
bool NullStatistic<T>::loaded_ = true;
145-
146142
template <>
147143
class NullStatistic<void> : public Statistic<void>
148144
{

0 commit comments

Comments
 (0)