From f58e836911d5e59ba69e70d459d844ba72523b72 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Fri, 2 Feb 2018 21:22:39 +0100 Subject: Replace boost::optional with std::optional --- src/tree.cc | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/tree.cc') diff --git a/src/tree.cc b/src/tree.cc index 8e29255..23294da 100644 --- a/src/tree.cc +++ b/src/tree.cc @@ -1,8 +1,7 @@ #include "tree.h" #include "exceptions.h" -#include - +#include #include #include #include @@ -12,18 +11,18 @@ namespace { using SimpleParser::Node; - boost::optional top(const std::stack stack) { + std::optional top(const std::stack stack) { if ( !stack.empty() ) { - return boost::make_optional( + return std::make_optional( stack.top() ); } else { - return boost::optional(); + return std::optional(); } } - boost::optional pop(std::stack& stack) { - if ( boost::optional node{ top(stack) } ) { + std::optional pop(std::stack& stack) { + if ( std::optional node{ top(stack) } ) { stack.pop(); return node; @@ -130,7 +129,7 @@ Node* Tree::buildTree(const std::string& term) { this->addNode(elementToken) ); } else { - if ( boost::optional lastNode{ top(operators) } ) { + if ( std::optional lastNode{ top(operators) } ) { OperatorNode*const lastOperator{ static_cast(*lastNode) }; @@ -141,9 +140,9 @@ Node* Tree::buildTree(const std::string& term) { this->addNode(elementToken) ); } else { - boost::optional currentOperator{ pop(operators) }; - boost::optional rightChild { pop(operands) }; - boost::optional leftChild { pop(operands) }; + std::optional currentOperator{ pop(operators) }; + std::optional rightChild { pop(operands) }; + std::optional leftChild { pop(operands) }; if ( currentOperator && rightChild && leftChild ) { static_cast( @@ -204,9 +203,9 @@ Node* Tree::buildTree(const std::string& term) { } while ( !operators.empty() ) { - boost::optional currentOperator{ pop(operators) }; - boost::optional rightChild { pop(operands) }; - boost::optional leftChild { pop(operands) }; + std::optional currentOperator{ pop(operators) }; + std::optional rightChild { pop(operands) }; + std::optional leftChild { pop(operands) }; if ( currentOperator && rightChild && leftChild ) { static_cast( @@ -222,7 +221,7 @@ Node* Tree::buildTree(const std::string& term) { } } - if ( boost::optional rootNode{ pop(operands) } ) { + if ( std::optional rootNode{ pop(operands) } ) { return *rootNode; } else { throw operator_exception(); -- cgit v1.2.3