Skip to content

Commit 5836b65

Browse files
committed
Fix explicit specialization in non-namespace scope
Although MSVC compiles specializations inside non-specialized classes, this is against C++17 17.8.3/17. Instead we use C++17's "if constexpr".
1 parent 7bd4385 commit 5836b65

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

src/xrGame/ini_id_loader.h

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,24 @@ class CIni_IdToIndex
3232
static T_VECTOR* m_pItemDataVector;
3333

3434
template <u32 NUM>
35-
static void LoadItemData(u32, LPCSTR)
36-
{
37-
static_assert(std::is_same_v<decltype(NUM), bool>, "Specialization for LoadItemData in CIni_IdToIndex not found."); // Xottab_DUTY: Is this correct?
38-
NODEFAULT;
39-
}
40-
41-
template <>
42-
static void LoadItemData<0>(u32 count, LPCSTR cfgRecord)
35+
static void LoadItemData(u32 count, LPCSTR cfgRecord)
4336
{
37+
static_assert(NUM < 2, "Specialization for LoadItemData in CIni_IdToIndex not found."); // Xottab_DUTY: Is this correct?
4438
for (u32 k = 0; k < count; k += 1)
4539
{
4640
string64 buf;
4741
LPCSTR id_str = _GetItem(cfgRecord, k, buf);
48-
char* id_str_lwr = xr_strdup(id_str);
49-
xr_strlwr(id_str_lwr);
50-
ITEM_DATA item_data(T_INDEX(m_pItemDataVector->size()), T_ID(id_str));
51-
m_pItemDataVector->push_back(item_data);
52-
xr_free(id_str_lwr);
53-
}
54-
}
55-
56-
template <>
57-
static void LoadItemData<1>(u32 count, LPCSTR cfgRecord)
58-
{
59-
for (u32 k = 0; k < count; k += 2)
60-
{
61-
string64 buf, buf1;
62-
LPCSTR id_str = _GetItem(cfgRecord, k, buf);
63-
char* id_str_lwr = xr_strdup(id_str);
42+
char* id_str_lwr = xr_strdup(id_str); // not used
6443
xr_strlwr(id_str_lwr);
65-
LPCSTR rec1 = _GetItem(cfgRecord, k + 1, buf1);
66-
ITEM_DATA item_data(T_INDEX(m_pItemDataVector->size()), T_ID(id_str), rec1);
67-
m_pItemDataVector->push_back(item_data);
44+
if constexpr (NUM == 0) {
45+
ITEM_DATA item_data(T_INDEX(m_pItemDataVector->size()), T_ID(id_str));
46+
m_pItemDataVector->push_back(item_data);
47+
} else {
48+
string64 buf1;
49+
LPCSTR rec1 = _GetItem(cfgRecord, k + 1, buf1);
50+
ITEM_DATA item_data(T_INDEX(m_pItemDataVector->size()), T_ID(id_str), rec1);
51+
m_pItemDataVector->push_back(item_data);
52+
}
6853
xr_free(id_str_lwr);
6954
}
7055
}

0 commit comments

Comments
 (0)