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 --- CMakeLists.txt | 35 ++++++++++++++++++++++------------- clc.cc | 2 +- src/tree.cc | 29 ++++++++++++++--------------- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 763be29..fbbb8fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,41 +3,50 @@ project(SimpleParser) set( CMAKE_CXX_FLAGS - "-std=c++14 -W -Wall -Wextra -Winline -pedantic" + "${CMAKE_CXX_FLAGS} -std=c++17 -W -Wall -Wextra -Winline -pedantic" ) add_library( SimpleParser SHARED - src/nodes.cc - src/tree.cc - src/utils.cc - src/parser.cc + src/nodes.cc + src/tree.cc + src/utils.cc + src/parser.cc ) add_executable( tests - test.cc + test.cc ) add_executable( clc - clc.cc + clc.cc ) target_link_libraries( tests - SimpleParser - gtest + SimpleParser + gtest ) target_link_libraries( clc - SimpleParser - boost_program_options + SimpleParser + boost_program_options +) + +install( + TARGETS + clc + DESTINATION + bin ) add_custom_command( - TARGET tests - POST_BUILD COMMAND ./tests + TARGET + tests + POST_BUILD COMMAND + ./tests ) diff --git a/clc.cc b/clc.cc index 9c029e4..2ee76b8 100644 --- a/clc.cc +++ b/clc.cc @@ -119,4 +119,4 @@ int main(int argc, char** argv) { } else { return 1; } -} +} \ No newline at end of file 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