Skip to content

Commit

Permalink
Make HexString() not constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Dec 1, 2023
1 parent e2dcdcd commit fc3cbe3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 36 deletions.
24 changes: 4 additions & 20 deletions wpilibc/src/main/native/include/frc/util/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <stdexcept>
#include <string>
#include <string_view>
#include <type_traits>

#include <fmt/core.h>
#include <wpi/StringExtras.h>
Expand Down Expand Up @@ -849,25 +848,10 @@ class Color {
*
* @return a string of the format <tt>\#RRGGBB</tt>
*/
constexpr std::string HexString() const {
int r = static_cast<int>(255.0 * red);
int g = static_cast<int>(255.0 * green);
int b = static_cast<int>(255.0 * blue);

if (std::is_constant_evaluated()) {
std::string str = "#";

str += wpi::hexdigit(r / 16);
str += wpi::hexdigit(r % 16);
str += wpi::hexdigit(g / 16);
str += wpi::hexdigit(g % 16);
str += wpi::hexdigit(b / 16);
str += wpi::hexdigit(b % 16);

return str;
} else {
return fmt::format("#{:02X}{:02X}{:02X}", r, g, b);
}
std::string HexString() const {
return fmt::format("#{:02X}{:02X}{:02X}", static_cast<int>(255.0 * red),
static_cast<int>(255.0 * green),
static_cast<int>(255.0 * blue));
}

double red = 0.0;
Expand Down
18 changes: 2 additions & 16 deletions wpilibc/src/main/native/include/frc/util/Color8Bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <stdexcept>
#include <string>
#include <string_view>
#include <type_traits>

#include <fmt/core.h>
#include <wpi/StringExtras.h>
Expand Down Expand Up @@ -105,21 +104,8 @@ class Color8Bit {
*
* @return a string of the format <tt>\#RRGGBB</tt>
*/
constexpr std::string HexString() const {
if (std::is_constant_evaluated()) {
std::string str = "#";

str += wpi::hexdigit(red / 16);
str += wpi::hexdigit(red % 16);
str += wpi::hexdigit(green / 16);
str += wpi::hexdigit(green % 16);
str += wpi::hexdigit(blue / 16);
str += wpi::hexdigit(blue % 16);

return str;
} else {
return fmt::format("#{:02X}{:02X}{:02X}", red, green, blue);
}
std::string HexString() const {
return fmt::format("#{:02X}{:02X}{:02X}", red, green, blue);
}

int red = 0;
Expand Down

0 comments on commit fc3cbe3

Please sign in to comment.