Skip to content

Commit fb53fc7

Browse files
author
David Roberts
authored
[ML] Rename anonymous namespace apply function to avoid clash (#871)
In C++17 there is a std::apply function that gets chosen in preference to the apply function in the anonymous namespace in the metric and event rate bucket gatherers. This change renames our function so the compiler does not have to resolve an ambiguity when it's called.
1 parent 9979b8a commit fb53fc7

File tree

2 files changed

+68
-63
lines changed

2 files changed

+68
-63
lines changed

lib/model/CEventRateBucketGatherer.cc

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ struct SMaybeConst<TCategoryAnyMap::const_iterator, T> {
320320

321321
//! Apply a function \p f to all the data held in [\p begin, \p end).
322322
template<typename ITR, typename F>
323-
void apply(ITR begin, ITR end, const F& f) {
323+
void applyFunc(ITR begin, ITR end, const F& f) {
324324
for (ITR itr = begin; itr != end; ++itr) {
325325
model_t::EEventRateCategory category = itr->first;
326326
try {
@@ -351,8 +351,8 @@ void apply(ITR begin, ITR end, const F& f) {
351351

352352
//! Apply a function \p f to all the data held in \p featureData.
353353
template<typename T, typename F>
354-
void apply(T& featureData, const F& f) {
355-
apply(featureData.begin(), featureData.end(), f);
354+
void applyFunc(T& featureData, const F& f) {
355+
applyFunc(featureData.begin(), featureData.end(), f);
356356
}
357357

358358
//! \brief Removes people from the feature data.
@@ -960,15 +960,15 @@ void CEventRateBucketGatherer::recyclePeople(const TSizeVec& peopleToRemove) {
960960
return;
961961
}
962962

963-
apply(m_FeatureData, std::bind<void>(SRemovePeople(), std::placeholders::_1,
964-
std::cref(peopleToRemove)));
963+
applyFunc(m_FeatureData, std::bind<void>(SRemovePeople(), std::placeholders::_1,
964+
std::cref(peopleToRemove)));
965965

966966
this->CBucketGatherer::recyclePeople(peopleToRemove);
967967
}
968968

969969
void CEventRateBucketGatherer::removePeople(std::size_t lowestPersonToRemove) {
970-
apply(m_FeatureData, std::bind<void>(SRemovePeople(), std::placeholders::_1, lowestPersonToRemove,
971-
m_DataGatherer.numberPeople()));
970+
applyFunc(m_FeatureData, std::bind<void>(SRemovePeople(), std::placeholders::_1, lowestPersonToRemove,
971+
m_DataGatherer.numberPeople()));
972972
this->CBucketGatherer::removePeople(lowestPersonToRemove);
973973
}
974974

@@ -977,24 +977,24 @@ void CEventRateBucketGatherer::recycleAttributes(const TSizeVec& attributesToRem
977977
return;
978978
}
979979

980-
apply(m_FeatureData, std::bind<void>(SRemoveAttributes(), std::placeholders::_1,
981-
std::cref(attributesToRemove)));
980+
applyFunc(m_FeatureData, std::bind<void>(SRemoveAttributes(), std::placeholders::_1,
981+
std::cref(attributesToRemove)));
982982

983983
this->CBucketGatherer::recycleAttributes(attributesToRemove);
984984
}
985985

986986
void CEventRateBucketGatherer::removeAttributes(std::size_t lowestAttributeToRemove) {
987-
apply(m_FeatureData, std::bind<void>(SRemoveAttributes(), std::placeholders::_1,
988-
lowestAttributeToRemove));
987+
applyFunc(m_FeatureData, std::bind<void>(SRemoveAttributes(), std::placeholders::_1,
988+
lowestAttributeToRemove));
989989
this->CBucketGatherer::removeAttributes(lowestAttributeToRemove);
990990
}
991991

992992
uint64_t CEventRateBucketGatherer::checksum() const {
993993
uint64_t seed = this->CBucketGatherer::checksum();
994994

995995
TStrUInt64Map hashes;
996-
apply(m_FeatureData, std::bind<void>(SChecksum(), std::placeholders::_1,
997-
std::cref(m_DataGatherer), std::ref(hashes)));
996+
applyFunc(m_FeatureData, std::bind<void>(SChecksum(), std::placeholders::_1,
997+
std::cref(m_DataGatherer), std::ref(hashes)));
998998
LOG_TRACE(<< "seed = " << seed);
999999
LOG_TRACE(<< "hashes = " << core::CContainerPrinter::print(hashes));
10001000
core::CHashing::CSafeMurmurHash2String64 hasher;
@@ -1510,7 +1510,7 @@ void CEventRateBucketGatherer::bucketMeanTimesPerPersonAttribute(model_t::EFeatu
15101510
}
15111511

15121512
void CEventRateBucketGatherer::resize(std::size_t pid, std::size_t cid) {
1513-
apply(m_FeatureData, std::bind<void>(SResize(), std::placeholders::_1, pid, cid));
1513+
applyFunc(m_FeatureData, std::bind<void>(SResize(), std::placeholders::_1, pid, cid));
15141514
}
15151515

15161516
void CEventRateBucketGatherer::addValue(std::size_t pid,
@@ -1522,13 +1522,14 @@ void CEventRateBucketGatherer::addValue(std::size_t pid,
15221522
const TStoredStringPtrVec& influences) {
15231523
// Check that we are correctly sized - a person/attribute might have been added
15241524
this->resize(pid, cid);
1525-
apply(m_FeatureData, std::bind<void>(SAddValue(), std::placeholders::_1, pid,
1526-
cid, time, count, std::cref(values),
1527-
std::cref(stringValue), std::cref(influences)));
1525+
applyFunc(m_FeatureData,
1526+
std::bind<void>(SAddValue(), std::placeholders::_1, pid, cid,
1527+
time, count, std::cref(values),
1528+
std::cref(stringValue), std::cref(influences)));
15281529
}
15291530

15301531
void CEventRateBucketGatherer::startNewBucket(core_t::TTime time, bool /*skipUpdates*/) {
1531-
apply(m_FeatureData, std::bind<void>(SNewBucket(), std::placeholders::_1, time));
1532+
applyFunc(m_FeatureData, std::bind<void>(SNewBucket(), std::placeholders::_1, time));
15321533
}
15331534

15341535
void CEventRateBucketGatherer::initializeFieldNames(const std::string& personFieldName,

lib/model/CMetricBucketGatherer.cc

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -196,44 +196,44 @@ void registerMemoryCallbacks() {
196196
//! Apply a function \p f to a gatherer held as a value by map entry \p i
197197
//! of an explicit metric category
198198
template<model_t::EMetricCategory CATEGORY, typename ITR, typename F>
199-
void apply(ITR i, const F& f) {
199+
void applyFunc(ITR i, const F& f) {
200200
using TDataType = typename SDataType<CATEGORY>::Type;
201201
f(i->first, boost::any_cast<typename SMaybeConst<ITR, TDataType>::Type&>(i->second));
202202
}
203203

204204
//! Apply a function \p f to all the gatherers held in [\p begin, \p end).
205205
template<typename ITR, typename F>
206-
bool apply(ITR begin, ITR end, const F& f) {
206+
bool applyFunc(ITR begin, ITR end, const F& f) {
207207
for (ITR i = begin; i != end; ++i) {
208208
model_t::EMetricCategory category = i->first.first;
209209
try {
210210
switch (category) {
211211
case model_t::E_Mean:
212-
apply<model_t::E_Mean>(i, f);
212+
applyFunc<model_t::E_Mean>(i, f);
213213
break;
214214
case model_t::E_Median:
215-
apply<model_t::E_Median>(i, f);
215+
applyFunc<model_t::E_Median>(i, f);
216216
break;
217217
case model_t::E_Min:
218-
apply<model_t::E_Min>(i, f);
218+
applyFunc<model_t::E_Min>(i, f);
219219
break;
220220
case model_t::E_Max:
221-
apply<model_t::E_Max>(i, f);
221+
applyFunc<model_t::E_Max>(i, f);
222222
break;
223223
case model_t::E_Variance:
224-
apply<model_t::E_Variance>(i, f);
224+
applyFunc<model_t::E_Variance>(i, f);
225225
break;
226226
case model_t::E_Sum:
227-
apply<model_t::E_Sum>(i, f);
227+
applyFunc<model_t::E_Sum>(i, f);
228228
break;
229229
case model_t::E_MultivariateMean:
230-
apply<model_t::E_MultivariateMean>(i, f);
230+
applyFunc<model_t::E_MultivariateMean>(i, f);
231231
break;
232232
case model_t::E_MultivariateMin:
233-
apply<model_t::E_MultivariateMin>(i, f);
233+
applyFunc<model_t::E_MultivariateMin>(i, f);
234234
break;
235235
case model_t::E_MultivariateMax:
236-
apply<model_t::E_MultivariateMax>(i, f);
236+
applyFunc<model_t::E_MultivariateMax>(i, f);
237237
break;
238238
}
239239
} catch (const std::exception& e) {
@@ -247,8 +247,8 @@ bool apply(ITR begin, ITR end, const F& f) {
247247

248248
//! Apply a function \p f to all the gatherers held in \p data.
249249
template<typename T, typename F>
250-
bool apply(T& data, const F& f) {
251-
return apply(data.begin(), data.end(), f);
250+
bool applyFunc(T& data, const F& f) {
251+
return applyFunc(data.begin(), data.end(), f);
252252
}
253253

254254
//! Initialize feature data for a specific category
@@ -965,8 +965,9 @@ void CMetricBucketGatherer::acceptPersistInserter(core::CStatePersistInserter& i
965965
inserter.insertLevel(BASE_TAG, std::bind(&CBucketGatherer::baseAcceptPersistInserter,
966966
this, std::placeholders::_1));
967967
inserter.insertValue(VERSION_TAG, CURRENT_VERSION);
968-
apply(m_FeatureData, std::bind<void>(CPersistFeatureData(), std::placeholders::_1,
969-
std::placeholders::_2, std::ref(inserter)));
968+
applyFunc(m_FeatureData,
969+
std::bind<void>(CPersistFeatureData(), std::placeholders::_1,
970+
std::placeholders::_2, std::ref(inserter)));
970971
}
971972

972973
bool CMetricBucketGatherer::acceptRestoreTraverser(core::CStateRestoreTraverser& traverser) {
@@ -1270,16 +1271,17 @@ void CMetricBucketGatherer::recyclePeople(const TSizeVec& peopleToRemove) {
12701271
return;
12711272
}
12721273

1273-
apply(m_FeatureData, std::bind<void>(SRemovePeople(), std::placeholders::_1,
1274-
std::placeholders::_2, std::cref(peopleToRemove)));
1274+
applyFunc(m_FeatureData,
1275+
std::bind<void>(SRemovePeople(), std::placeholders::_1,
1276+
std::placeholders::_2, std::cref(peopleToRemove)));
12751277

12761278
this->CBucketGatherer::recyclePeople(peopleToRemove);
12771279
}
12781280

12791281
void CMetricBucketGatherer::removePeople(std::size_t lowestPersonToRemove) {
1280-
apply(m_FeatureData, std::bind<void>(SRemovePeople(), std::placeholders::_1,
1281-
std::placeholders::_2, lowestPersonToRemove,
1282-
m_DataGatherer.numberPeople()));
1282+
applyFunc(m_FeatureData, std::bind<void>(SRemovePeople(), std::placeholders::_1,
1283+
std::placeholders::_2, lowestPersonToRemove,
1284+
m_DataGatherer.numberPeople()));
12831285

12841286
this->CBucketGatherer::removePeople(lowestPersonToRemove);
12851287
}
@@ -1290,19 +1292,20 @@ void CMetricBucketGatherer::recycleAttributes(const TSizeVec& attributesToRemove
12901292
}
12911293

12921294
if (m_DataGatherer.isPopulation()) {
1293-
apply(m_FeatureData,
1294-
std::bind<void>(SRemoveAttributes(), std::placeholders::_1,
1295-
std::placeholders::_2, std::cref(attributesToRemove)));
1295+
applyFunc(m_FeatureData,
1296+
std::bind<void>(SRemoveAttributes(), std::placeholders::_1,
1297+
std::placeholders::_2, std::cref(attributesToRemove)));
12961298
}
12971299

12981300
this->CBucketGatherer::recycleAttributes(attributesToRemove);
12991301
}
13001302

13011303
void CMetricBucketGatherer::removeAttributes(std::size_t lowestAttributeToRemove) {
13021304
if (m_DataGatherer.isPopulation()) {
1303-
apply(m_FeatureData, std::bind<void>(SRemoveAttributes(), std::placeholders::_1,
1304-
std::placeholders::_2, lowestAttributeToRemove,
1305-
m_DataGatherer.numberAttributes()));
1305+
applyFunc(m_FeatureData,
1306+
std::bind<void>(SRemoveAttributes(), std::placeholders::_1,
1307+
std::placeholders::_2, lowestAttributeToRemove,
1308+
m_DataGatherer.numberAttributes()));
13061309
}
13071310

13081311
this->CBucketGatherer::removeAttributes(lowestAttributeToRemove);
@@ -1312,8 +1315,9 @@ uint64_t CMetricBucketGatherer::checksum() const {
13121315
uint64_t seed = this->CBucketGatherer::checksum();
13131316
seed = maths::CChecksum::calculate(seed, m_DataGatherer.params().s_DecayRate);
13141317
TStrCRefStrCRefPrUInt64Map hashes;
1315-
apply(m_FeatureData, std::bind<void>(SHash(), std::placeholders::_1, std::placeholders::_2,
1316-
std::cref(*this), std::ref(hashes)));
1318+
applyFunc(m_FeatureData, std::bind<void>(SHash(), std::placeholders::_1,
1319+
std::placeholders::_2,
1320+
std::cref(*this), std::ref(hashes)));
13171321
LOG_TRACE(<< "seed = " << seed);
13181322
LOG_TRACE(<< "hashes = " << core::CContainerPrinter::print(hashes));
13191323
return maths::CChecksum::calculate(seed, hashes);
@@ -1353,22 +1357,22 @@ bool CMetricBucketGatherer::resetBucket(core_t::TTime bucketStart) {
13531357
if (this->CBucketGatherer::resetBucket(bucketStart) == false) {
13541358
return false;
13551359
}
1356-
apply(m_FeatureData, std::bind<void>(SResetBucket(), std::placeholders::_1,
1357-
std::placeholders::_2, bucketStart));
1360+
applyFunc(m_FeatureData, std::bind<void>(SResetBucket(), std::placeholders::_1,
1361+
std::placeholders::_2, bucketStart));
13581362
return true;
13591363
}
13601364

13611365
void CMetricBucketGatherer::releaseMemory(core_t::TTime samplingCutoffTime) {
1362-
apply(m_FeatureData, std::bind<void>(SReleaseMemory(), std::placeholders::_1,
1363-
std::placeholders::_2, samplingCutoffTime));
1366+
applyFunc(m_FeatureData, std::bind<void>(SReleaseMemory(), std::placeholders::_1,
1367+
std::placeholders::_2, samplingCutoffTime));
13641368
}
13651369

13661370
void CMetricBucketGatherer::sample(core_t::TTime time) {
13671371
if (m_DataGatherer.sampleCounts()) {
1368-
apply(m_FeatureData,
1369-
std::bind<void>(SDoSample(), std::placeholders::_1,
1370-
std::placeholders::_2, time, std::cref(*this),
1371-
std::ref(*m_DataGatherer.sampleCounts())));
1372+
applyFunc(m_FeatureData,
1373+
std::bind<void>(SDoSample(), std::placeholders::_1,
1374+
std::placeholders::_2, time, std::cref(*this),
1375+
std::ref(*m_DataGatherer.sampleCounts())));
13721376
}
13731377
}
13741378

@@ -1392,10 +1396,10 @@ void CMetricBucketGatherer::featureData(core_t::TTime time,
13921396
if (begin != m_FeatureData.end()) {
13931397
auto end = begin;
13941398
++end;
1395-
apply(begin, end,
1396-
std::bind<void>(SExtractFeatureData(), std::placeholders::_1,
1397-
std::placeholders::_2, std::cref(*this), feature,
1398-
time, bucketLength, std::ref(result)));
1399+
applyFunc(begin, end,
1400+
std::bind<void>(SExtractFeatureData(), std::placeholders::_1,
1401+
std::placeholders::_2, std::cref(*this), feature,
1402+
time, bucketLength, std::ref(result)));
13991403
} else {
14001404
LOG_ERROR(<< "No data for category " << model_t::print(category));
14011405
}
@@ -1436,9 +1440,9 @@ void CMetricBucketGatherer::addValue(std::size_t pid,
14361440
}
14371441

14381442
stat.s_Influences = &influences;
1439-
apply(m_FeatureData, std::bind<void>(SAddValue(), std::placeholders::_1,
1440-
std::placeholders::_2, pid, cid,
1441-
std::cref(*this), std::ref(stat)));
1443+
applyFunc(m_FeatureData, std::bind<void>(SAddValue(), std::placeholders::_1,
1444+
std::placeholders::_2, pid, cid,
1445+
std::cref(*this), std::ref(stat)));
14421446
}
14431447

14441448
void CMetricBucketGatherer::startNewBucket(core_t::TTime time, bool skipUpdates) {
@@ -1480,8 +1484,8 @@ void CMetricBucketGatherer::startNewBucket(core_t::TTime time, bool skipUpdates)
14801484
m_DataGatherer.sampleCounts()->refresh(m_DataGatherer);
14811485
}
14821486
}
1483-
apply(m_FeatureData, std::bind<void>(SStartNewBucket(), std::placeholders::_1,
1484-
std::placeholders::_2, time));
1487+
applyFunc(m_FeatureData, std::bind<void>(SStartNewBucket(), std::placeholders::_1,
1488+
std::placeholders::_2, time));
14851489
}
14861490

14871491
void CMetricBucketGatherer::initializeFieldNamesPart1(const std::string& personFieldName,

0 commit comments

Comments
 (0)