Skip to content

Commit b194fd7

Browse files
authored
AMREX_ENUM: Allow non-decimal base (#5251)
1 parent 8531217 commit b194fd7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Src/Base/AMReX_Enum.H

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ namespace detail
4242
T this_value;
4343
if (it != r.end()) {
4444
this_value = it->second;
45-
} else { // v is an int
45+
} else { // v is an int literal
4646
// Note that if value_string is not a valid string for int,
4747
// it will fail at compile time, because the compiler
4848
// will not allow something like `enum FOO : int { x = 3% }`.
49-
this_value = static_cast<T>(std::stoi(value_string));
49+
// The base of the integer is auto detected, so 0x/0 prefixes work.
50+
this_value = static_cast<T>(std::stoi(value_string, nullptr, 0));
5051
}
5152
r.emplace_back(amrex::trim(kv[0]), this_value);
5253
next_value = static_cast<int>(this_value) + 1;

0 commit comments

Comments
 (0)