Skip to content

Commit fcffc31

Browse files
authored
Merge pull request #1680 from cyrossignol/fix-optional-references
Replace boost::optional<T&> with non-owning pointers
2 parents e7388bc + a31e0ac commit fcffc31

File tree

6 files changed

+30
-31
lines changed

6 files changed

+30
-31
lines changed

src/neuralnet/beacon.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ BeaconOption BeaconRegistry::Try(const Cpid& cpid) const
148148
const auto iter = m_beacons.find(cpid);
149149

150150
if (iter == m_beacons.end()) {
151-
return boost::none;
151+
return nullptr;
152152
}
153153

154-
return iter->second;
154+
return &iter->second;
155155
}
156156

157157
BeaconOption BeaconRegistry::TryActive(const Cpid& cpid, const int64_t now) const
@@ -162,7 +162,7 @@ BeaconOption BeaconRegistry::TryActive(const Cpid& cpid, const int64_t now) cons
162162
}
163163
}
164164

165-
return boost::none;
165+
return nullptr;
166166
}
167167

168168
bool BeaconRegistry::ContainsActive(const Cpid& cpid, const int64_t now) const

src/neuralnet/beacon.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "neuralnet/cpid.h"
77
#include "serialize.h"
88

9-
#include <boost/optional.hpp>
109
#include <string>
1110
#include <vector>
1211

@@ -161,9 +160,9 @@ class Beacon
161160
};
162161

163162
//!
164-
//! \brief A type that either contains a reference to some beacon or does not.
163+
//! \brief A type that either points to to some beacon or does not.
165164
//!
166-
typedef boost::optional<const Beacon&> BeaconOption;
165+
typedef const Beacon* BeaconOption;
167166

168167
//!
169168
//! \brief The body of a beacon contract advertised in a transaction.

src/neuralnet/quorum.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,19 +1126,19 @@ class SuperblockValidator
11261126
//! \brief Record the supplied scraper ID for the specified project to
11271127
//! track supermajority status.
11281128
//!
1129-
//! \return A reference to the project resolution state if the project
1129+
//! \return A pointer to the project resolution state if the project
11301130
//! exists in the superblock.
11311131
//!
1132-
boost::optional<ResolvedProject&>
1132+
ResolvedProject*
11331133
TallyProject(const std::string& project, const ScraperID& scraper_id)
11341134
{
11351135
if (m_resolved_projects.count(project)) {
1136-
return m_resolved_projects.at(project);
1136+
return &m_resolved_projects.at(project);
11371137
}
11381138

11391139
m_other_projects[project].emplace(scraper_id);
11401140

1141-
return boost::none;
1141+
return nullptr;
11421142
}
11431143

11441144
//!

src/neuralnet/researcher.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <boost/algorithm/string/case_conv.hpp>
1313
#include <boost/algorithm/string/join.hpp>
1414
#include <boost/algorithm/string/replace.hpp>
15+
#include <boost/optional.hpp>
1516
#include <openssl/md5.h>
1617
#include <set>
1718

@@ -613,10 +614,10 @@ ProjectOption MiningProjectMap::Try(const std::string& name) const
613614
const auto iter = m_projects.find(name);
614615

615616
if (iter == m_projects.end()) {
616-
return boost::none;
617+
return nullptr;
617618
}
618619

619-
return iter->second;
620+
return &iter->second;
620621
}
621622

622623
void MiningProjectMap::Set(MiningProject project)
@@ -660,22 +661,22 @@ AdvertiseBeaconResult::AdvertiseBeaconResult(const BeaconError error)
660661
{
661662
}
662663

663-
boost::optional<CPubKey&> AdvertiseBeaconResult::TryPublicKey()
664+
CPubKey* AdvertiseBeaconResult::TryPublicKey()
664665
{
665666
if (m_result.which() == 0) {
666-
return boost::get<CPubKey>(m_result);
667+
return &boost::get<CPubKey>(m_result);
667668
}
668669

669-
return boost::none;
670+
return nullptr;
670671
}
671672

672-
boost::optional<const CPubKey&> AdvertiseBeaconResult::TryPublicKey() const
673+
const CPubKey* AdvertiseBeaconResult::TryPublicKey() const
673674
{
674675
if (m_result.which() == 0) {
675-
return boost::get<CPubKey>(m_result);
676+
return &boost::get<CPubKey>(m_result);
676677
}
677678

678-
return boost::none;
679+
return nullptr;
679680
}
680681

681682
BeaconError AdvertiseBeaconResult::Error() const

src/neuralnet/researcher.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "key.h"
44
#include "neuralnet/cpid.h"
55

6-
#include <boost/optional.hpp>
76
#include <boost/variant/get.hpp>
87
#include <boost/variant/variant.hpp>
98
#include <map>
@@ -90,10 +89,10 @@ struct MiningProject
9089
};
9190

9291
//!
93-
//! \brief An optional type that either contains a reference to some local BOINC
94-
//! project or does not.
92+
//! \brief An optional type that either points to some local BOINC project or
93+
//! does not.
9594
//!
96-
typedef boost::optional<const MiningProject&> ProjectOption;
95+
typedef const MiningProject* ProjectOption;
9796

9897
//!
9998
//! \brief Contains a local set of BOINC projects loaded from client_state.xml.
@@ -228,18 +227,18 @@ class AdvertiseBeaconResult
228227
//!
229228
//! \brief Get the beacon public key if advertisement succeeded.
230229
//!
231-
//! \return An object that contains a reference to the beacon public key
232-
//! if advertisement succeeded or does not.
230+
//! \return An object that points to the beacon public key if advertisement
231+
//! succeeded or does not.
233232
//!
234-
boost::optional<CPubKey&> TryPublicKey();
233+
CPubKey* TryPublicKey();
235234

236235
//!
237236
//! \brief Get the beacon public key if advertisement succeeded.
238237
//!
239-
//! \return An object that contains a reference to the beacon public key
240-
//! if advertisement succeeded or does not.
238+
//! \return An object that points to the beacon public key if advertisement
239+
//! succeeded or does not.
241240
//!
242-
boost::optional<const CPubKey&> TryPublicKey() const;
241+
const CPubKey* TryPublicKey() const;
243242

244243
//!
245244
//! \brief Get a description of the error that occurred, if any.

src/test/neuralnet/researcher_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ BOOST_AUTO_TEST_CASE(it_fetches_a_project_by_name)
380380

381381
projects.Set(NN::MiningProject("project name", NN::Cpid(), "team name"));
382382

383-
BOOST_CHECK(projects.Try("project name").value().m_name == "project name");
384-
BOOST_CHECK(projects.Try("nonexistent") == boost::none);
383+
BOOST_CHECK(projects.Try("project name")->m_name == "project name");
384+
BOOST_CHECK(projects.Try("nonexistent") == nullptr);
385385
}
386386

387387
BOOST_AUTO_TEST_CASE(it_does_not_overwrite_projects_with_the_same_name)
@@ -391,7 +391,7 @@ BOOST_AUTO_TEST_CASE(it_does_not_overwrite_projects_with_the_same_name)
391391
projects.Set(NN::MiningProject("project name", NN::Cpid(), "team name 1"));
392392
projects.Set(NN::MiningProject("project name", NN::Cpid(), "team name 2"));
393393

394-
BOOST_CHECK(projects.Try("project name").value().m_team == "team name 1");
394+
BOOST_CHECK(projects.Try("project name")->m_team == "team name 1");
395395
}
396396

397397
BOOST_AUTO_TEST_CASE(it_applies_a_provided_team_whitelist)

0 commit comments

Comments
 (0)