Skip to content

Commit

Permalink
remove another if constexpr
Browse files Browse the repository at this point in the history
More efficient before C++17

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jul 4, 2023
1 parent 901e8ba commit 97b9d86
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions include/exiv2/xmp_exiv2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class EXIV2API Xmpdatum : public Metadatum {
*/
template <typename T>
Xmpdatum& operator=(const T& value);
template <typename T>
void setValueHelper(const T& value, std::true_type);
template <typename T>
void setValueHelper(const T& value, std::false_type);
/*!
@brief Assign Value \em value to the %Xmpdatum.
Calls setValue(const Value*).
Expand Down Expand Up @@ -393,19 +397,20 @@ class EXIV2API XmpParser {
// *****************************************************************************
// free functions, template and inline definitions

template <typename T>
void Xmpdatum::setValueHelper(const T& value, std::true_type) {
setValue(Exiv2::toString(value ? "True" : "False"));
}

template <typename T>
void Xmpdatum::setValueHelper(const T& value, std::false_type) {
setValue(Exiv2::toString(value));
}

template <typename T>
Xmpdatum& Xmpdatum::operator=(const T& value) {
#ifdef __cpp_if_constexpr
if constexpr (std::is_same_v<T, bool>) {
#else
if (std::is_same<T, bool>::value) {
#endif
setValue(Exiv2::toString(value ? "True" : "False"));
return *this;
} else {
setValue(Exiv2::toString(value));
return *this;
}
setValueHelper(value, std::is_same<T, bool>());
return *this;
}

} // namespace Exiv2
Expand Down

0 comments on commit 97b9d86

Please sign in to comment.