Skip to content

Commit

Permalink
Fix explicit specialization in non-namespace scope
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
Zegeri committed Sep 16, 2018
1 parent 7bd4385 commit 5836b65
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions src/xrGame/ini_id_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,24 @@ class CIni_IdToIndex
static T_VECTOR* m_pItemDataVector;

template <u32 NUM>
static void LoadItemData(u32, LPCSTR)
{
static_assert(std::is_same_v<decltype(NUM), bool>, "Specialization for LoadItemData in CIni_IdToIndex not found."); // Xottab_DUTY: Is this correct?
NODEFAULT;
}

template <>
static void LoadItemData<0>(u32 count, LPCSTR cfgRecord)
static void LoadItemData(u32 count, LPCSTR cfgRecord)
{
static_assert(NUM < 2, "Specialization for LoadItemData in CIni_IdToIndex not found."); // Xottab_DUTY: Is this correct?
for (u32 k = 0; k < count; k += 1)
{
string64 buf;
LPCSTR id_str = _GetItem(cfgRecord, k, buf);
char* id_str_lwr = xr_strdup(id_str);
xr_strlwr(id_str_lwr);
ITEM_DATA item_data(T_INDEX(m_pItemDataVector->size()), T_ID(id_str));
m_pItemDataVector->push_back(item_data);
xr_free(id_str_lwr);
}
}

template <>
static void LoadItemData<1>(u32 count, LPCSTR cfgRecord)
{
for (u32 k = 0; k < count; k += 2)
{
string64 buf, buf1;
LPCSTR id_str = _GetItem(cfgRecord, k, buf);
char* id_str_lwr = xr_strdup(id_str);
char* id_str_lwr = xr_strdup(id_str); // not used
xr_strlwr(id_str_lwr);
LPCSTR rec1 = _GetItem(cfgRecord, k + 1, buf1);
ITEM_DATA item_data(T_INDEX(m_pItemDataVector->size()), T_ID(id_str), rec1);
m_pItemDataVector->push_back(item_data);
if constexpr (NUM == 0) {
ITEM_DATA item_data(T_INDEX(m_pItemDataVector->size()), T_ID(id_str));
m_pItemDataVector->push_back(item_data);
} else {
string64 buf1;
LPCSTR rec1 = _GetItem(cfgRecord, k + 1, buf1);
ITEM_DATA item_data(T_INDEX(m_pItemDataVector->size()), T_ID(id_str), rec1);
m_pItemDataVector->push_back(item_data);
}
xr_free(id_str_lwr);
}
}
Expand Down

0 comments on commit 5836b65

Please sign in to comment.