Replace custom ARRAYSIZE macro with std::size (#208)

* Replace custom ARRAYSIZE macro with std::size
This commit is contained in:
Michał Janiszewski 2019-03-15 05:06:12 +01:00 committed by Daniel Belcher
parent d37c75fec2
commit a5e07418df
7 changed files with 21 additions and 17 deletions

View File

@ -39,11 +39,11 @@ namespace {
int iPrec; int iPrec;
iPrec = 0; iPrec = 0;
while ((iPrec < ARRAYSIZE(rgbPrec)) && (nopCode != rgbPrec[iPrec])) while ((iPrec < size(rgbPrec)) && (nopCode != rgbPrec[iPrec]))
{ {
iPrec += 2; iPrec += 2;
} }
if (iPrec >= ARRAYSIZE(rgbPrec)) if (iPrec >= size(rgbPrec))
{ {
iPrec = 0; iPrec = 0;
} }
@ -947,7 +947,7 @@ wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE
// Try to lookup the ID in the UFNE table // Try to lookup the ID in the UFNE table
int ids = 0; int ids = 0;
int iufne = nOpCode - IDC_UNARYFIRST; int iufne = nOpCode - IDC_UNARYFIRST;
if (iufne >= 0 && iufne < ARRAYSIZE(rgUfne)) if (iufne >= 0 && iufne < size(rgUfne))
{ {
if (fInv) if (fInv)
{ {

View File

@ -6,6 +6,7 @@
using namespace CalcEngine; using namespace CalcEngine;
using namespace CalcEngine::RationalMath; using namespace CalcEngine::RationalMath;
using namespace std;
// To be called when either the radix or num width changes. You can use -1 in either of these values to mean // To be called when either the radix or num width changes. You can use -1 in either of these values to mean
// dont change that. // dont change that.
@ -55,7 +56,7 @@ LONG CCalcEngine::DwWordBitWidthFromeNumWidth(NUM_WIDTH /*numwidth*/)
static constexpr int nBitMax[] = { 64, 32, 16, 8 }; static constexpr int nBitMax[] = { 64, 32, 16, 8 };
LONG wmax = nBitMax[0]; LONG wmax = nBitMax[0];
if (m_numwidth >= 0 && m_numwidth < ARRAYSIZE(nBitMax)) if (m_numwidth >= 0 && m_numwidth < size(nBitMax))
{ {
wmax = nBitMax[m_numwidth]; wmax = nBitMax[m_numwidth];
} }
@ -68,7 +69,7 @@ uint32_t CCalcEngine::NRadixFromRadixType(RADIX_TYPE radixtype)
uint32_t radix = 10; uint32_t radix = 10;
// convert special bases into symbolic values // convert special bases into symbolic values
if (radixtype >= 0 && radixtype < ARRAYSIZE(rgnRadish)) if (radixtype >= 0 && radixtype < size(rgnRadish))
{ {
radix = rgnRadish[radixtype]; radix = rgnRadish[radixtype];
} }

View File

@ -12,6 +12,7 @@
#include <winerror.h> #include <winerror.h>
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
#include <iterator>
#include <string> #include <string>
#include <memory> #include <memory>
#include <vector> #include <vector>

View File

@ -404,7 +404,7 @@ wstring CopyPasteManager::SanitizeOperand(const wstring& operand)
{ {
wchar_t unWantedChars[] = { L'\'', L'_', L'`', L'(', L')', L'-' }; wchar_t unWantedChars[] = { L'\'', L'_', L'`', L'(', L')', L'-' };
return Utils::RemoveUnwantedCharsFromWstring(operand, unWantedChars, ARRAYSIZE(unWantedChars)); return Utils::RemoveUnwantedCharsFromWstring(operand, unWantedChars, static_cast<int>(size(unWantedChars)));
} }
bool CopyPasteManager::TryOperandToULL(const wstring& operand, int numberBase, unsigned long long int& result) bool CopyPasteManager::TryOperandToULL(const wstring& operand, int numberBase, unsigned long long int& result)

View File

@ -4,6 +4,8 @@
#pragma once #pragma once
#include "LocalizationService.h" #include "LocalizationService.h"
#include <iterator>
namespace CalculatorApp namespace CalculatorApp
{ {
namespace Common namespace Common
@ -41,7 +43,7 @@ namespace CalculatorApp
result = GetLocaleInfoEx(m_resolvedName.c_str(), result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_SDECIMAL, LOCALE_SDECIMAL,
decimalString, decimalString,
ARRAYSIZE(decimalString)); static_cast<int>(std::size(decimalString)));
if (result == 0) if (result == 0)
{ {
throw std::runtime_error("Unexpected error while getting locale info"); throw std::runtime_error("Unexpected error while getting locale info");
@ -51,7 +53,7 @@ namespace CalculatorApp
result = GetLocaleInfoEx(m_resolvedName.c_str(), result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_STHOUSAND, LOCALE_STHOUSAND,
groupingSymbolString, groupingSymbolString,
ARRAYSIZE(groupingSymbolString)); static_cast<int>(std::size(groupingSymbolString)));
if (result == 0) if (result == 0)
{ {
throw std::runtime_error("Unexpected error while getting locale info"); throw std::runtime_error("Unexpected error while getting locale info");
@ -61,7 +63,7 @@ namespace CalculatorApp
result = GetLocaleInfoEx(m_resolvedName.c_str(), result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_SGROUPING, LOCALE_SGROUPING,
numberGroupingString, numberGroupingString,
ARRAYSIZE(numberGroupingString)); static_cast<int>(std::size(numberGroupingString)));
if (result == 0) if (result == 0)
{ {
throw std::runtime_error("Unexpected error while getting locale info"); throw std::runtime_error("Unexpected error while getting locale info");
@ -72,7 +74,7 @@ namespace CalculatorApp
result = ::GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, result = ::GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT,
LOCALE_SLIST, LOCALE_SLIST,
listSeparatorString, listSeparatorString,
ARRAYSIZE(listSeparatorString)); // Max length of the expected return value is 4 static_cast<int>(std::size(listSeparatorString))); // Max length of the expected return value is 4
if (result == 0) if (result == 0)
{ {
throw std::runtime_error("Unexpected error while getting locale info"); throw std::runtime_error("Unexpected error while getting locale info");
@ -122,7 +124,7 @@ namespace CalculatorApp
::GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, ::GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT,
LOCALE_IFIRSTDAYOFWEEK, // The first day in a week LOCALE_IFIRSTDAYOFWEEK, // The first day in a week
reinterpret_cast<PWSTR>(day), // Argument is of type PWSTR reinterpret_cast<PWSTR>(day), // Argument is of type PWSTR
ARRAYSIZE(day)); // Max return size are 80 characters static_cast<int>(std::size(day))); // Max return size are 80 characters
// The LOCALE_IFIRSTDAYOFWEEK integer value varies from 0, 1, .. 6 for Monday, Tuesday, ... Sunday // The LOCALE_IFIRSTDAYOFWEEK integer value varies from 0, 1, .. 6 for Monday, Tuesday, ... Sunday
// DayOfWeek enum value varies from 0, 1, .. 6 for Sunday, Monday, ... Saturday // DayOfWeek enum value varies from 0, 1, .. 6 for Sunday, Monday, ... Saturday

View File

@ -1647,7 +1647,7 @@ bool StandardCalculatorViewModel::IsOpnd(int nOpCode)
Command::CommandPNT Command::CommandPNT
}; };
for (int i = 0; i < ARRAYSIZE(opnd); i++) for (int i = 0; i < size(opnd); i++)
{ {
if (nOpCode == static_cast<int>(opnd[i])) if (nOpCode == static_cast<int>(opnd[i]))
{ {
@ -1678,7 +1678,7 @@ bool StandardCalculatorViewModel::IsUnaryOp(int nOpCode)
Command::CommandCUB Command::CommandCUB
}; };
for (int i = 0; i < ARRAYSIZE(unaryOp); i++) for (int i = 0; i < size(unaryOp); i++)
{ {
if (nOpCode == static_cast<int>(unaryOp[i])) if (nOpCode == static_cast<int>(unaryOp[i]))
{ {
@ -1705,7 +1705,7 @@ bool StandardCalculatorViewModel::IsTrigOp(int nOpCode)
Command::CommandATAN Command::CommandATAN
}; };
for (int i = 0; i < ARRAYSIZE(trigOp); i++) for (int i = 0; i < size(trigOp); i++)
{ {
if (nOpCode == static_cast<int>(trigOp[i])) if (nOpCode == static_cast<int>(trigOp[i]))
{ {
@ -1728,7 +1728,7 @@ bool StandardCalculatorViewModel::IsBinOp(int nOpCode)
Command::CommandPWR Command::CommandPWR
}; };
for (int i = 0; i < ARRAYSIZE(binOp); i++) for (int i = 0; i < size(binOp); i++)
{ {
if (nOpCode == static_cast<int>(binOp[i])) if (nOpCode == static_cast<int>(binOp[i]))
{ {
@ -1762,7 +1762,7 @@ bool StandardCalculatorViewModel::IsRecoverableCommand(int nOpCode)
Command::CommandF Command::CommandF
}; };
for (int i = 0; i < ARRAYSIZE(recoverableCommands); i++) for (int i = 0; i < size(recoverableCommands); i++)
{ {
if (nOpCode == static_cast<int>(recoverableCommands[i])) if (nOpCode == static_cast<int>(recoverableCommands[i]))
{ {

View File

@ -26,7 +26,7 @@
#include <sstream> #include <sstream>
#include <concrt.h> #include <concrt.h>
#include <regex> #include <regex>
#include <iterator>
// C++\WinRT Headers // C++\WinRT Headers
#include "winrt/base.h" #include "winrt/base.h"
#include "winrt/Windows.Foundation.Diagnostics.h" #include "winrt/Windows.Foundation.Diagnostics.h"