Skip to content

Commit 187116d

Browse files
authored
[ML] Replace boost functions by their std equivalents (elastic#508) (elastic#510)
Following boost functions have been raplaced with their std equivalents: boost::array, boost::begin, boost::end, boost::is_pod, boost::ref, boost::cref, boost::reference_wrapper, boost::make_unique, boost::algorithm::is_sorted, boost::bind. Due to the limitations of the std::ref implementation, boost::ref cannot be removed where it is used in Input and Output filters (e.g. lib/core/CCompressOStream.cc and lib/core/CStateDecompressor.cc).
1 parent 60f710e commit 187116d

File tree

261 files changed

+2361
-2348
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+2361
-2348
lines changed

bin/autoconfig/Main.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
#include "CCmdLineParser.h"
3434

35-
#include <boost/bind.hpp>
36-
3735
#include <memory>
3836
#include <string>
3937

bin/autodetect/Main.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646

4747
#include "CCmdLineParser.h"
4848

49-
#include <boost/bind.hpp>
50-
49+
#include <functional>
5150
#include <memory>
5251
#include <string>
5352

@@ -242,8 +241,8 @@ int main(int argc, char** argv) {
242241

243242
// The anomaly job knows how to detect anomalies
244243
ml::api::CAnomalyJob job(jobId, limits, fieldConfig, modelConfig, wrappedOutputStream,
245-
boost::bind(&ml::api::CModelSnapshotJsonWriter::write,
246-
&modelSnapshotWriter, _1),
244+
std::bind(&ml::api::CModelSnapshotJsonWriter::write,
245+
&modelSnapshotWriter, std::placeholders::_1),
247246
periodicPersister.get(), maxQuantileInterval,
248247
timeField, timeFormat, maxAnomalyRecords);
249248

@@ -274,8 +273,9 @@ int main(int argc, char** argv) {
274273
}
275274

276275
if (periodicPersister != nullptr) {
277-
periodicPersister->firstProcessorPeriodicPersistFunc(boost::bind(
278-
&ml::api::CDataProcessor::periodicPersistState, firstProcessor, _1));
276+
periodicPersister->firstProcessorPeriodicPersistFunc(
277+
std::bind(&ml::api::CDataProcessor::periodicPersistState,
278+
firstProcessor, std::placeholders::_1));
279279
}
280280

281281
// The skeleton avoids the need to duplicate a lot of boilerplate code

bin/categorize/Main.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242

4343
#include "CCmdLineParser.h"
4444

45-
#include <boost/bind.hpp>
46-
45+
#include <functional>
4746
#include <memory>
4847
#include <string>
4948

@@ -177,8 +176,8 @@ int main(int argc, char** argv) {
177176
outputWriter, periodicPersister.get());
178177

179178
if (periodicPersister != nullptr) {
180-
periodicPersister->firstProcessorPeriodicPersistFunc(boost::bind(
181-
&ml::api::CFieldDataTyper::periodicPersistState, &typer, _1));
179+
periodicPersister->firstProcessorPeriodicPersistFunc(std::bind(
180+
&ml::api::CFieldDataTyper::periodicPersistState, &typer, std::placeholders::_1));
182181
}
183182

184183
// The skeleton avoids the need to duplicate a lot of boilerplate code

bin/normalize/Main.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232

3333
#include "CCmdLineParser.h"
3434

35-
#include <boost/bind.hpp>
36-
35+
#include <functional>
3736
#include <memory>
3837
#include <string>
3938

@@ -128,8 +127,9 @@ int main(int argc, char** argv) {
128127
}
129128

130129
// Now handle the numbers to be normalised from stdin
131-
if (inputParser->readStreamIntoMaps(boost::bind(
132-
&ml::api::CResultNormalizer::handleRecord, &normalizer, _1)) == false) {
130+
if (inputParser->readStreamIntoMaps(
131+
std::bind(&ml::api::CResultNormalizer::handleRecord, &normalizer,
132+
std::placeholders::_1)) == false) {
133133
LOG_FATAL(<< "Failed to handle input to be normalized");
134134
return EXIT_FAILURE;
135135
}

include/api/CBackgroundPersister.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace api {
4747
//! This class expects to call a persistence function taking
4848
//! just the data adder as an argument. It's easy to wrap up
4949
//! extra data to be passed to a function that requires more by
50-
//! using a boost:bind. boost::bind copies its arguments, which
50+
//! using a std::bind. std::bind copies its arguments, which
5151
//! is generally what is required for access in a separate
5252
//! thread. However, note that a couple of copies are made, so
5353
//! if the bound data is very large then binding a

include/api/CInputParser.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <api/ImportExport.h>
1212

13-
#include <boost/ref.hpp>
1413
#include <boost/unordered_map.hpp>
1514

1615
#include <functional>
@@ -43,7 +42,7 @@ class API_EXPORT CInputParser : private core::CNonCopyable {
4342

4443
//! For fast access to the field values without repeatedly computing the
4544
//! hash, we maintain references to the values in the hash map
46-
using TStrRef = boost::reference_wrapper<std::string>;
45+
using TStrRef = std::reference_wrapper<std::string>;
4746
using TStrRefVec = std::vector<TStrRef>;
4847
using TStrRefVecItr = TStrRefVec::iterator;
4948
using TStrRefVecCItr = TStrRefVec::const_iterator;

include/api/CLengthEncodedInputParser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class API_EXPORT CLengthEncodedInputParser : public CInputParser {
116116

117117
//! Attempt to parse a single length encoded record from the stream into
118118
//! the strings in the vector provided. The vector is a template
119-
//! argument so that it may be a vector of boost::reference_wrappers
119+
//! argument so that it may be a vector of std::reference_wrappers
120120
//! of std::strings instead of std::strings. The first template
121121
//! argument indicates whether the vector must have the correct size
122122
//! when the function is called or whether the function is allowed to

include/api/COutputChainer.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include <api/COutputHandler.h>
1010
#include <api/ImportExport.h>
1111

12-
#include <boost/ref.hpp>
13-
12+
#include <functional>
1413
#include <string>
1514

1615
namespace ml {
@@ -102,7 +101,7 @@ class API_EXPORT COutputChainer : public COutputHandler {
102101
//! processor
103102
TStrStrUMap m_WorkRecordFields;
104103

105-
using TStrRef = boost::reference_wrapper<std::string>;
104+
using TStrRef = std::reference_wrapper<std::string>;
106105
using TStrRefVec = std::vector<TStrRef>;
107106
using TStrRefVecCItr = TStrRefVec::const_iterator;
108107

include/config/CAutoconfigurerDetectorPenalties.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
#include <config/ImportExport.h>
1111

12-
#include <boost/ref.hpp>
13-
12+
#include <functional>
1413
#include <memory>
1514
#include <vector>
1615

@@ -43,9 +42,9 @@ class CONFIG_EXPORT CAutoconfigurerDetectorPenalties {
4342
TPenaltyPtr penaltyFor(const CDetectorSpecification& spec);
4443

4544
private:
46-
using TAutoconfigurerParamsCRef = boost::reference_wrapper<const CAutoconfigurerParams>;
45+
using TAutoconfigurerParamsCRef = std::reference_wrapper<const CAutoconfigurerParams>;
4746
using TAutoconfigurerFieldRolePenaltiesCRef =
48-
boost::reference_wrapper<const CAutoconfigurerFieldRolePenalties>;
47+
std::reference_wrapper<const CAutoconfigurerFieldRolePenalties>;
4948
using TPenaltyPtrVec = std::vector<TPenaltyPtr>;
5049

5150
private:

include/config/CDataCountStatistics.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#include <config/ImportExport.h>
2020

2121
#include <boost/optional.hpp>
22-
#include <boost/ref.hpp>
2322
#include <boost/unordered_map.hpp>
2423
#include <boost/unordered_set.hpp>
2524

2625
#include <cstddef>
26+
#include <functional>
2727
#include <stdint.h>
2828
#include <vector>
2929

@@ -203,7 +203,7 @@ class CONFIG_EXPORT CDataCountStatistics {
203203
using TSizeSizePr = std::pair<std::size_t, std::size_t>;
204204
using TSizeSizePrUSet = boost::unordered_set<TSizeSizePr>;
205205
using TOptionalTime = boost::optional<core_t::TTime>;
206-
using TAutoconfigurerParamsCRef = boost::reference_wrapper<const CAutoconfigurerParams>;
206+
using TAutoconfigurerParamsCRef = std::reference_wrapper<const CAutoconfigurerParams>;
207207
using TMinTimeAccumulator =
208208
maths::CBasicStatistics::COrderStatisticsStack<core_t::TTime, 1>;
209209
using TMaxTimeAccumulator =
@@ -340,7 +340,7 @@ class CONFIG_EXPORT CDataCountStatisticsDirectAddressTable {
340340
using TSizeVec = std::vector<std::size_t>;
341341
using TPtrDiffVec = std::vector<ptrdiff_t>;
342342
using TPtrDiffVecVec = std::vector<TPtrDiffVec>;
343-
using TAutoconfigurerParamsCRef = boost::reference_wrapper<const CAutoconfigurerParams>;
343+
using TAutoconfigurerParamsCRef = std::reference_wrapper<const CAutoconfigurerParams>;
344344
using TDataCountStatisticsPtr = std::shared_ptr<CDataCountStatistics>;
345345
using TDataCountStatisticsPtrVec = std::vector<TDataCountStatisticsPtr>;
346346

include/config/CDetectorEnumerator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <config/ImportExport.h>
1212

1313
#include <boost/optional.hpp>
14-
#include <boost/ref.hpp>
1514

15+
#include <functional>
1616
#include <string>
1717
#include <vector>
1818

@@ -72,7 +72,7 @@ class CONFIG_EXPORT CDetectorEnumerator {
7272
using TStrVec = std::vector<std::string>;
7373
using TOptionalStr = boost::optional<std::string>;
7474
using TFunctionCategoryVec = std::vector<config_t::EFunctionCategory>;
75-
using TAutoconfigurerParamsCRef = boost::reference_wrapper<const CAutoconfigurerParams>;
75+
using TAutoconfigurerParamsCRef = std::reference_wrapper<const CAutoconfigurerParams>;
7676

7777
private:
7878
//! Add the detectors with no partitioning fields.

include/config/CDetectorRecord.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#include <config/Constants.h>
1414
#include <config/ImportExport.h>
1515

16-
#include <boost/array.hpp>
1716
#include <boost/unordered_map.hpp>
1817

18+
#include <array>
1919
#include <string>
2020
#include <utility>
2121
#include <vector>
@@ -32,8 +32,8 @@ class CDetectorSpecification;
3232
//! and partitioning field(s) used by the detector.
3333
class CONFIG_EXPORT CDetectorRecord {
3434
public:
35-
using TSizeAry = boost::array<std::size_t, constants::NUMBER_FIELD_INDICES>;
36-
using TStrCPtrAry = boost::array<const std::string*, constants::NUMBER_FIELD_INDICES>;
35+
using TSizeAry = std::array<std::size_t, constants::NUMBER_FIELD_INDICES>;
36+
using TStrCPtrAry = std::array<const std::string*, constants::NUMBER_FIELD_INDICES>;
3737
using TStrStrUMap = boost::unordered_map<std::string, std::string>;
3838

3939
public:
@@ -138,7 +138,7 @@ class CONFIG_EXPORT CDetectorRecordDirectAddressTable {
138138
using TSizeVec = std::vector<std::size_t>;
139139
using TStrSizePr = std::pair<std::string, std::size_t>;
140140
using TStrSizePrVec = std::vector<TStrSizePr>;
141-
using TSizeAry = boost::array<std::size_t, constants::NUMBER_FIELD_INDICES>;
141+
using TSizeAry = std::array<std::size_t, constants::NUMBER_FIELD_INDICES>;
142142
using TSizeAryVec = std::vector<TSizeAry>;
143143
using TStrCPtrVec = std::vector<const std::string*>;
144144

include/config/CDetectorSpecification.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
#include <config/Constants.h>
1414
#include <config/ImportExport.h>
1515

16-
#include <boost/array.hpp>
1716
#include <boost/operators.hpp>
1817
#include <boost/optional.hpp>
19-
#include <boost/ref.hpp>
2018

19+
#include <array>
20+
#include <functional>
2121
#include <memory>
2222
#include <string>
2323
#include <vector>
@@ -203,8 +203,8 @@ class CONFIG_EXPORT CDetectorSpecification
203203
private:
204204
using TStrVecVec = std::vector<TStrVec>;
205205
using TOptionalTime = boost::optional<core_t::TTime>;
206-
using TSizeVecCPtrAry = boost::array<const TSizeVec*, 2>;
207-
using TAutoconfigurerParamsCRef = boost::reference_wrapper<const CAutoconfigurerParams>;
206+
using TSizeVecCPtrAry = std::array<const TSizeVec*, 2>;
207+
using TAutoconfigurerParamsCRef = std::reference_wrapper<const CAutoconfigurerParams>;
208208

209209
private:
210210
//! Get the parameters.

include/config/CFieldStatistics.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
#include <config/ConfigTypes.h>
1313
#include <config/ImportExport.h>
1414

15+
#include <boost/variant.hpp>
16+
17+
#include <functional>
1518
#include <string>
1619
#include <vector>
1720

18-
#include <boost/ref.hpp>
19-
#include <boost/variant.hpp>
20-
2121
namespace ml {
2222
namespace config {
2323
class CAutoconfigurerParams;
@@ -30,7 +30,7 @@ class CPenalty;
3030
//! and gather the appropriate summary statistics.
3131
class CONFIG_EXPORT CFieldStatistics {
3232
public:
33-
using TAutoconfigurerParamsCRef = boost::reference_wrapper<const CAutoconfigurerParams>;
33+
using TAutoconfigurerParamsCRef = std::reference_wrapper<const CAutoconfigurerParams>;
3434

3535
public:
3636
CFieldStatistics(const std::string& fieldName, const CAutoconfigurerParams& params);

include/config/CLongTailPenalty.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <config/CPenalty.h>
1111
#include <config/ImportExport.h>
1212

13-
#include <boost/ref.hpp>
1413
#include <boost/unordered_map.hpp>
1514

1615
namespace ml {

include/config/CPenalty.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#include <config/ImportExport.h>
1414

1515
#include <boost/operators.hpp>
16-
#include <boost/ref.hpp>
1716

1817
#include <cstddef>
18+
#include <functional>
1919
#include <memory>
2020
#include <vector>
2121

@@ -125,7 +125,7 @@ class CONFIG_EXPORT CPenalty {
125125
static bool scoreIsZeroFor(double penalty);
126126

127127
protected:
128-
using TAutoconfigurerParamsCRef = boost::reference_wrapper<const CAutoconfigurerParams>;
128+
using TAutoconfigurerParamsCRef = std::reference_wrapper<const CAutoconfigurerParams>;
129129

130130
protected:
131131
//! Get the parameters.

include/core/CCompressedDictionary.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#include <core/CHashing.h>
1212
#include <core/CStringUtils.h>
1313

14-
#include <boost/array.hpp>
1514
#include <boost/operators.hpp>
1615
#include <boost/unordered/unordered_map_fwd.hpp>
1716
#include <boost/unordered/unordered_set_fwd.hpp>
1817

18+
#include <array>
1919
#include <map>
2020
#include <set>
2121
#include <string>
@@ -42,7 +42,7 @@ namespace core {
4242
template<std::size_t N>
4343
class CCompressedDictionary {
4444
public:
45-
using TUInt64Array = boost::array<uint64_t, N>;
45+
using TUInt64Array = std::array<uint64_t, N>;
4646
using TStrCPtr = const std::string*;
4747

4848
//! \brief A hash representation of a string in the dictionary

0 commit comments

Comments
 (0)