aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-02-02 21:22:39 +0100
committerAdrian Kummerlaender2018-02-02 21:23:37 +0100
commitf58e836911d5e59ba69e70d459d844ba72523b72 (patch)
treedb4aad1b667e7f8dc9d1d54e0c386c14914621df
parent0985a623e4cbd14da77fddf1bb1a9ca3384b28ea (diff)
downloadSimpleParser-f58e836911d5e59ba69e70d459d844ba72523b72.tar
SimpleParser-f58e836911d5e59ba69e70d459d844ba72523b72.tar.gz
SimpleParser-f58e836911d5e59ba69e70d459d844ba72523b72.tar.bz2
SimpleParser-f58e836911d5e59ba69e70d459d844ba72523b72.tar.lz
SimpleParser-f58e836911d5e59ba69e70d459d844ba72523b72.tar.xz
SimpleParser-f58e836911d5e59ba69e70d459d844ba72523b72.tar.zst
SimpleParser-f58e836911d5e59ba69e70d459d844ba72523b72.zip
Replace boost::optional with std::optional
-rw-r--r--CMakeLists.txt35
-rw-r--r--clc.cc2
-rw-r--r--src/tree.cc29
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 <boost/optional.hpp>
-
+#include <optional>
#include <sstream>
#include <limits>
#include <stack>
@@ -12,18 +11,18 @@
namespace {
using SimpleParser::Node;
- boost::optional<Node*> top(const std::stack<Node*> stack) {
+ std::optional<Node*> top(const std::stack<Node*> stack) {
if ( !stack.empty() ) {
- return boost::make_optional<Node*>(
+ return std::make_optional<Node*>(
stack.top()
);
} else {
- return boost::optional<Node*>();
+ return std::optional<Node*>();
}
}
- boost::optional<Node*> pop(std::stack<Node*>& stack) {
- if ( boost::optional<Node*> node{ top(stack) } ) {
+ std::optional<Node*> pop(std::stack<Node*>& stack) {
+ if ( std::optional<Node*> node{ top(stack) } ) {
stack.pop();
return node;
@@ -130,7 +129,7 @@ Node* Tree::buildTree(const std::string& term) {
this->addNode<OperatorNode>(elementToken)
);
} else {
- if ( boost::optional<Node*> lastNode{ top(operators) } ) {
+ if ( std::optional<Node*> lastNode{ top(operators) } ) {
OperatorNode*const lastOperator{
static_cast<OperatorNode*const>(*lastNode)
};
@@ -141,9 +140,9 @@ Node* Tree::buildTree(const std::string& term) {
this->addNode<OperatorNode>(elementToken)
);
} else {
- boost::optional<Node*> currentOperator{ pop(operators) };
- boost::optional<Node*> rightChild { pop(operands) };
- boost::optional<Node*> leftChild { pop(operands) };
+ std::optional<Node*> currentOperator{ pop(operators) };
+ std::optional<Node*> rightChild { pop(operands) };
+ std::optional<Node*> leftChild { pop(operands) };
if ( currentOperator && rightChild && leftChild ) {
static_cast<OperatorNode*const>(
@@ -204,9 +203,9 @@ Node* Tree::buildTree(const std::string& term) {
}
while ( !operators.empty() ) {
- boost::optional<Node*> currentOperator{ pop(operators) };
- boost::optional<Node*> rightChild { pop(operands) };
- boost::optional<Node*> leftChild { pop(operands) };
+ std::optional<Node*> currentOperator{ pop(operators) };
+ std::optional<Node*> rightChild { pop(operands) };
+ std::optional<Node*> leftChild { pop(operands) };
if ( currentOperator && rightChild && leftChild ) {
static_cast<OperatorNode*const>(
@@ -222,7 +221,7 @@ Node* Tree::buildTree(const std::string& term) {
}
}
- if ( boost::optional<Node*> rootNode{ pop(operands) } ) {
+ if ( std::optional<Node*> rootNode{ pop(operands) } ) {
return *rootNode;
} else {
throw operator_exception();