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;
iPrec = 0;
while ((iPrec < ARRAYSIZE(rgbPrec)) && (nopCode != rgbPrec[iPrec]))
while ((iPrec < size(rgbPrec)) && (nopCode != rgbPrec[iPrec]))
{
iPrec += 2;
}
if (iPrec >= ARRAYSIZE(rgbPrec))
if (iPrec >= size(rgbPrec))
{
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
int ids = 0;
int iufne = nOpCode - IDC_UNARYFIRST;
if (iufne >= 0 && iufne < ARRAYSIZE(rgUfne))
if (iufne >= 0 && iufne < size(rgUfne))
{
if (fInv)
{

View File

@ -6,6 +6,7 @@
using namespace CalcEngine;
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
// dont change that.
@ -55,7 +56,7 @@ LONG CCalcEngine::DwWordBitWidthFromeNumWidth(NUM_WIDTH /*numwidth*/)
static constexpr int nBitMax[] = { 64, 32, 16, 8 };
LONG wmax = nBitMax[0];
if (m_numwidth >= 0 && m_numwidth < ARRAYSIZE(nBitMax))
if (m_numwidth >= 0 && m_numwidth < size(nBitMax))
{
wmax = nBitMax[m_numwidth];
}
@ -68,7 +69,7 @@ uint32_t CCalcEngine::NRadixFromRadixType(RADIX_TYPE radixtype)
uint32_t radix = 10;
// convert special bases into symbolic values
if (radixtype >= 0 && radixtype < ARRAYSIZE(rgnRadish))
if (radixtype >= 0 && radixtype < size(rgnRadish))
{
radix = rgnRadish[radixtype];
}

View File

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

View File

@ -404,7 +404,7 @@ wstring CopyPasteManager::SanitizeOperand(const wstring& operand)
{
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)

View File

@ -4,6 +4,8 @@
#pragma once
#include "LocalizationService.h"
#include <iterator>
namespace CalculatorApp
{
namespace Common
@ -41,7 +43,7 @@ namespace CalculatorApp
result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_SDECIMAL,
decimalString,
ARRAYSIZE(decimalString));
static_cast<int>(std::size(decimalString)));
if (result == 0)
{
throw std::runtime_error("Unexpected error while getting locale info");
@ -51,7 +53,7 @@ namespace CalculatorApp
result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_STHOUSAND,
groupingSymbolString,
ARRAYSIZE(groupingSymbolString));
static_cast<int>(std::size(groupingSymbolString)));
if (result == 0)
{
throw std::runtime_error("Unexpected error while getting locale info");
@ -61,7 +63,7 @@ namespace CalculatorApp
result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_SGROUPING,
numberGroupingString,
ARRAYSIZE(numberGroupingString));
static_cast<int>(std::size(numberGroupingString)));
if (result == 0)
{
throw std::runtime_error("Unexpected error while getting locale info");
@ -72,7 +74,7 @@ namespace CalculatorApp
result = ::GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT,
LOCALE_SLIST,
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)
{
throw std::runtime_error("Unexpected error while getting locale info");
@ -122,7 +124,7 @@ namespace CalculatorApp
::GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT,
LOCALE_IFIRSTDAYOFWEEK, // The first day in a week
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
// 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
};
for (int i = 0; i < ARRAYSIZE(opnd); i++)
for (int i = 0; i < size(opnd); i++)
{
if (nOpCode == static_cast<int>(opnd[i]))
{
@ -1678,7 +1678,7 @@ bool StandardCalculatorViewModel::IsUnaryOp(int nOpCode)
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]))
{
@ -1705,7 +1705,7 @@ bool StandardCalculatorViewModel::IsTrigOp(int nOpCode)
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]))
{
@ -1728,7 +1728,7 @@ bool StandardCalculatorViewModel::IsBinOp(int nOpCode)
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]))
{
@ -1762,7 +1762,7 @@ bool StandardCalculatorViewModel::IsRecoverableCommand(int nOpCode)
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]))
{

View File

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