Made the acccessors method to return const references

Reviewed By: emilsjolander

Differential Revision: D7321801

fbshipit-source-id: 9fc4da724bc2f58a0d95824ca3c0b5bf1690bccf
This commit is contained in:
Pritesh Nandgaonkar 2018-04-04 07:55:23 -07:00 committed by Facebook Github Bot
parent d4add3fc1c
commit 2ace555972
2 changed files with 4 additions and 4 deletions

View File

@ -14,7 +14,7 @@ YGFloatOptional::YGFloatOptional(const float& value)
: value_(value), isUndefined_(false) {}
YGFloatOptional::YGFloatOptional() : value_(0), isUndefined_(true) {}
float YGFloatOptional::getValue() const {
const float& YGFloatOptional::getValue() const {
if (isUndefined_) {
// Abort, accessing a value of an undefined float optional
std::cerr << "Tried to get value of an undefined YGFloatOptional\n";
@ -28,7 +28,7 @@ void YGFloatOptional::setValue(const float& val) {
isUndefined_ = false;
}
bool YGFloatOptional::isUndefined() const {
const bool& YGFloatOptional::isUndefined() const {
return isUndefined_;
}

View File

@ -17,12 +17,12 @@ struct YGFloatOptional {
// Program will terminate if the value of an undefined is accessed. Please
// make sure to check if the optional is defined before calling this function.
// To check if float optional is defined, use `isUndefined()`.
float getValue() const;
const float& getValue() const;
// Sets the value of float optional, and thus isUndefined is assigned false.
void setValue(const float& val);
bool isUndefined() const;
const bool& isUndefined() const;
bool operator==(const YGFloatOptional& op) const;
bool operator!=(const YGFloatOptional& op) const;