Switch to C++17

With C++17, optionals, an experimental language feature, were moved to
the “std” namespace. This makes C++17 mandatory and drops the now
obsolete “experimental” namespace.
This commit is contained in:
Patrick Lühne 2018-03-22 17:20:54 +01:00 committed by Patrick Lühne
parent c7d1026a31
commit 22238bb398
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
9 changed files with 48 additions and 48 deletions

View File

@ -7,7 +7,7 @@ option(ANTHEM_BUILD_STATIC "Build static binaries" OFF)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic ${CMAKE_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "-g ${CMAKE_CXX_FLAGS_DEBUG}") set(CMAKE_CXX_FLAGS_DEBUG "-g ${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)

View File

@ -17,7 +17,7 @@ With the option `--simplify`, output formulas are simplified by applying several
## Building ## Building
`anthem` requires [CMake](https://cmake.org/) and [Boost](http://www.boost.org/) for building. `anthem` requires [CMake](https://cmake.org/) and [Boost](http://www.boost.org/) for building.
After installing the dependencies, `anthem` is built with a C++14 compiler (GCC ≥ 6.1 or clang ≥ 3.8). After installing the dependencies, `anthem` is built with a C++17 compiler (GCC ≥ 7.3 or clang ≥ 5.0).
```bash ```bash
$ git clone https://github.com/potassco/anthem.git $ git clone https://github.com/potassco/anthem.git

View File

@ -1,7 +1,7 @@
#ifndef __ANTHEM__AST_UTILS_H #ifndef __ANTHEM__AST_UTILS_H
#define __ANTHEM__AST_UTILS_H #define __ANTHEM__AST_UTILS_H
#include <experimental/optional> #include <optional>
#include <anthem/AST.h> #include <anthem/AST.h>
#include <anthem/ASTVisitors.h> #include <anthem/ASTVisitors.h>
@ -28,7 +28,7 @@ class VariableStack
void push(Layer layer); void push(Layer layer);
void pop(); void pop();
std::experimental::optional<VariableDeclaration *> findUserVariableDeclaration(const char *variableName) const; std::optional<VariableDeclaration *> findUserVariableDeclaration(const char *variableName) const;
bool contains(const VariableDeclaration &variableDeclaration) const; bool contains(const VariableDeclaration &variableDeclaration) const;
private: private:

View File

@ -43,7 +43,7 @@ ast::Comparison::Operator translate(Clingo::AST::ComparisonOperator comparisonOp
struct BodyTermTranslateVisitor struct BodyTermTranslateVisitor
{ {
// TODO: refactor // TODO: refactor
std::experimental::optional<ast::Formula> visit(const Clingo::AST::Function &function, const Clingo::AST::Literal &literal, const Clingo::AST::Term &, RuleContext &ruleContext, ast::VariableStack &variableStack) std::optional<ast::Formula> visit(const Clingo::AST::Function &function, const Clingo::AST::Literal &literal, const Clingo::AST::Term &, RuleContext &ruleContext, ast::VariableStack &variableStack)
{ {
if (literal.sign == Clingo::AST::Sign::DoubleNegation) if (literal.sign == Clingo::AST::Sign::DoubleNegation)
throw TranslationException(literal.location, "double-negated literals currently unsupported"); throw TranslationException(literal.location, "double-negated literals currently unsupported");
@ -93,12 +93,12 @@ struct BodyTermTranslateVisitor
} }
template<class T> template<class T>
std::experimental::optional<ast::Formula> visit(const T &, const Clingo::AST::Literal &, const Clingo::AST::Term &term, RuleContext &, ast::VariableStack &) std::optional<ast::Formula> visit(const T &, const Clingo::AST::Literal &, const Clingo::AST::Term &term, RuleContext &, ast::VariableStack &)
{ {
assert(!term.data.is<Clingo::AST::Function>()); assert(!term.data.is<Clingo::AST::Function>());
throw TranslationException(term.location, "term currently unsupported in this context, expected function"); throw TranslationException(term.location, "term currently unsupported in this context, expected function");
return std::experimental::nullopt; return std::nullopt;
} }
}; };
@ -106,18 +106,18 @@ struct BodyTermTranslateVisitor
struct BodyLiteralTranslateVisitor struct BodyLiteralTranslateVisitor
{ {
std::experimental::optional<ast::Formula> visit(const Clingo::AST::Boolean &boolean, const Clingo::AST::Literal &, RuleContext &, ast::VariableStack &) std::optional<ast::Formula> visit(const Clingo::AST::Boolean &boolean, const Clingo::AST::Literal &, RuleContext &, ast::VariableStack &)
{ {
return ast::Formula::make<ast::Boolean>(boolean.value); return ast::Formula::make<ast::Boolean>(boolean.value);
} }
std::experimental::optional<ast::Formula> visit(const Clingo::AST::Term &term, const Clingo::AST::Literal &literal, RuleContext &ruleContext, ast::VariableStack &variableStack) std::optional<ast::Formula> visit(const Clingo::AST::Term &term, const Clingo::AST::Literal &literal, RuleContext &ruleContext, ast::VariableStack &variableStack)
{ {
return term.data.accept(BodyTermTranslateVisitor(), literal, term, ruleContext, variableStack); return term.data.accept(BodyTermTranslateVisitor(), literal, term, ruleContext, variableStack);
} }
// TODO: refactor // TODO: refactor
std::experimental::optional<ast::Formula> visit(const Clingo::AST::Comparison &comparison, const Clingo::AST::Literal &literal, RuleContext &ruleContext, ast::VariableStack &variableStack) std::optional<ast::Formula> visit(const Clingo::AST::Comparison &comparison, const Clingo::AST::Literal &literal, RuleContext &ruleContext, ast::VariableStack &variableStack)
{ {
// Comparisons should never have a sign, because these are converted to positive comparisons by clingo // Comparisons should never have a sign, because these are converted to positive comparisons by clingo
if (literal.sign != Clingo::AST::Sign::None) if (literal.sign != Clingo::AST::Sign::None)
@ -140,10 +140,10 @@ struct BodyLiteralTranslateVisitor
} }
template<class T> template<class T>
std::experimental::optional<ast::Formula> visit(const T &, const Clingo::AST::Literal &literal, RuleContext &, ast::VariableStack &) std::optional<ast::Formula> visit(const T &, const Clingo::AST::Literal &literal, RuleContext &, ast::VariableStack &)
{ {
throw TranslationException(literal.location, "literal currently unsupported in this context, expected function or term"); throw TranslationException(literal.location, "literal currently unsupported in this context, expected function or term");
return std::experimental::nullopt; return std::nullopt;
} }
}; };
@ -151,7 +151,7 @@ struct BodyLiteralTranslateVisitor
struct BodyBodyLiteralTranslateVisitor struct BodyBodyLiteralTranslateVisitor
{ {
std::experimental::optional<ast::Formula> visit(const Clingo::AST::Literal &literal, const Clingo::AST::BodyLiteral &bodyLiteral, RuleContext &ruleContext, ast::VariableStack &variableStack) std::optional<ast::Formula> visit(const Clingo::AST::Literal &literal, const Clingo::AST::BodyLiteral &bodyLiteral, RuleContext &ruleContext, ast::VariableStack &variableStack)
{ {
if (bodyLiteral.sign != Clingo::AST::Sign::None) if (bodyLiteral.sign != Clingo::AST::Sign::None)
throw TranslationException(bodyLiteral.location, "only positive body literals supported currently"); throw TranslationException(bodyLiteral.location, "only positive body literals supported currently");
@ -160,10 +160,10 @@ struct BodyBodyLiteralTranslateVisitor
} }
template<class T> template<class T>
std::experimental::optional<ast::Formula> visit(const T &, const Clingo::AST::BodyLiteral &bodyLiteral, RuleContext &, ast::VariableStack &) std::optional<ast::Formula> visit(const T &, const Clingo::AST::BodyLiteral &bodyLiteral, RuleContext &, ast::VariableStack &)
{ {
throw TranslationException(bodyLiteral.location, "body literal currently unsupported in this context, expected literal"); throw TranslationException(bodyLiteral.location, "body literal currently unsupported in this context, expected literal");
return std::experimental::nullopt; return std::nullopt;
} }
}; };

View File

@ -1,7 +1,7 @@
#ifndef __ANTHEM__CONTEXT_H #ifndef __ANTHEM__CONTEXT_H
#define __ANTHEM__CONTEXT_H #define __ANTHEM__CONTEXT_H
#include <experimental/optional> #include <optional>
#include <anthem/AST.h> #include <anthem/AST.h>
#include <anthem/output/Logger.h> #include <anthem/output/Logger.h>
@ -30,7 +30,7 @@ struct Context
bool performSimplification = false; bool performSimplification = false;
bool performCompletion = false; bool performCompletion = false;
std::experimental::optional<std::vector<ast::PredicateSignature>> visiblePredicateSignatures; std::optional<std::vector<ast::PredicateSignature>> visiblePredicateSignatures;
ast::ParenthesisStyle parenthesisStyle = ast::ParenthesisStyle::Normal; ast::ParenthesisStyle parenthesisStyle = ast::ParenthesisStyle::Normal;
}; };

View File

@ -2,7 +2,7 @@
#define __ANTHEM__HEAD_H #define __ANTHEM__HEAD_H
#include <algorithm> #include <algorithm>
#include <experimental/optional> #include <optional>
#include <anthem/AST.h> #include <anthem/AST.h>
#include <anthem/Exception.h> #include <anthem/Exception.h>
@ -119,7 +119,7 @@ struct HeadLiteralCollectFunctionTermsVisitor
struct FunctionTermTranslateVisitor struct FunctionTermTranslateVisitor
{ {
// TODO: check correctness // TODO: check correctness
std::experimental::optional<ast::Formula> visit(const Clingo::AST::Function &function, const Clingo::AST::Term &term, RuleContext &ruleContext, size_t &headVariableIndex) std::optional<ast::Formula> visit(const Clingo::AST::Function &function, const Clingo::AST::Term &term, RuleContext &ruleContext, size_t &headVariableIndex)
{ {
if (function.external) if (function.external)
throw TranslationException(term.location, "external functions currently unsupported"); throw TranslationException(term.location, "external functions currently unsupported");
@ -134,10 +134,10 @@ struct FunctionTermTranslateVisitor
} }
template<class T> template<class T>
std::experimental::optional<ast::Formula> visit(const T &, const Clingo::AST::Term &term, RuleContext &, size_t &) std::optional<ast::Formula> visit(const T &, const Clingo::AST::Term &term, RuleContext &, size_t &)
{ {
throw TranslationException(term.location, "term currently unsupported in this context, function expected"); throw TranslationException(term.location, "term currently unsupported in this context, function expected");
return std::experimental::nullopt; return std::nullopt;
} }
}; };
@ -145,21 +145,21 @@ struct FunctionTermTranslateVisitor
struct LiteralTranslateVisitor struct LiteralTranslateVisitor
{ {
std::experimental::optional<ast::Formula> visit(const Clingo::AST::Boolean &boolean, const Clingo::AST::Literal &, RuleContext &, size_t &) std::optional<ast::Formula> visit(const Clingo::AST::Boolean &boolean, const Clingo::AST::Literal &, RuleContext &, size_t &)
{ {
return ast::Formula::make<ast::Boolean>(boolean.value); return ast::Formula::make<ast::Boolean>(boolean.value);
} }
std::experimental::optional<ast::Formula> visit(const Clingo::AST::Term &term, const Clingo::AST::Literal &, RuleContext &ruleContext, size_t &headVariableIndex) std::optional<ast::Formula> visit(const Clingo::AST::Term &term, const Clingo::AST::Literal &, RuleContext &ruleContext, size_t &headVariableIndex)
{ {
return term.data.accept(FunctionTermTranslateVisitor(), term, ruleContext, headVariableIndex); return term.data.accept(FunctionTermTranslateVisitor(), term, ruleContext, headVariableIndex);
} }
template<class T> template<class T>
std::experimental::optional<ast::Formula> visit(const T &, const Clingo::AST::Literal &literal, RuleContext &, size_t &) std::optional<ast::Formula> visit(const T &, const Clingo::AST::Literal &literal, RuleContext &, size_t &)
{ {
throw TranslationException(literal.location, "only disjunctions of literals allowed as head literals"); throw TranslationException(literal.location, "only disjunctions of literals allowed as head literals");
return std::experimental::nullopt; return std::nullopt;
} }
}; };
@ -167,7 +167,7 @@ struct LiteralTranslateVisitor
struct HeadLiteralTranslateToConsequentVisitor struct HeadLiteralTranslateToConsequentVisitor
{ {
std::experimental::optional<ast::Formula> visit(const Clingo::AST::Literal &literal, const Clingo::AST::HeadLiteral &, RuleContext &ruleContext, size_t &headVariableIndex) std::optional<ast::Formula> visit(const Clingo::AST::Literal &literal, const Clingo::AST::HeadLiteral &, RuleContext &ruleContext, size_t &headVariableIndex)
{ {
if (literal.sign == Clingo::AST::Sign::DoubleNegation) if (literal.sign == Clingo::AST::Sign::DoubleNegation)
throw TranslationException(literal.location, "double-negated head literals currently unsupported"); throw TranslationException(literal.location, "double-negated head literals currently unsupported");
@ -178,12 +178,12 @@ struct HeadLiteralTranslateToConsequentVisitor
return translatedLiteral; return translatedLiteral;
if (!translatedLiteral) if (!translatedLiteral)
return std::experimental::nullopt; return std::nullopt;
return ast::Formula::make<ast::Not>(std::move(translatedLiteral.value())); return ast::Formula::make<ast::Not>(std::move(translatedLiteral.value()));
} }
std::experimental::optional<ast::Formula> visit(const Clingo::AST::Disjunction &disjunction, const Clingo::AST::HeadLiteral &headLiteral, RuleContext &ruleContext, size_t &headVariableIndex) std::optional<ast::Formula> visit(const Clingo::AST::Disjunction &disjunction, const Clingo::AST::HeadLiteral &headLiteral, RuleContext &ruleContext, size_t &headVariableIndex)
{ {
std::vector<ast::Formula> arguments; std::vector<ast::Formula> arguments;
arguments.reserve(disjunction.elements.size()); arguments.reserve(disjunction.elements.size());
@ -204,7 +204,7 @@ struct HeadLiteralTranslateToConsequentVisitor
return ast::Formula::make<ast::Or>(std::move(arguments)); return ast::Formula::make<ast::Or>(std::move(arguments));
} }
std::experimental::optional<ast::Formula> visit(const Clingo::AST::Aggregate &aggregate, const Clingo::AST::HeadLiteral &headLiteral, RuleContext &ruleContext, size_t &headVariableIndex) std::optional<ast::Formula> visit(const Clingo::AST::Aggregate &aggregate, const Clingo::AST::HeadLiteral &headLiteral, RuleContext &ruleContext, size_t &headVariableIndex)
{ {
if (aggregate.left_guard || aggregate.right_guard) if (aggregate.left_guard || aggregate.right_guard)
throw TranslationException(headLiteral.location, "aggregates with left or right guards currently unsupported"); throw TranslationException(headLiteral.location, "aggregates with left or right guards currently unsupported");
@ -238,10 +238,10 @@ struct HeadLiteralTranslateToConsequentVisitor
} }
template<class T> template<class T>
std::experimental::optional<ast::Formula> visit(const T &, const Clingo::AST::HeadLiteral &headLiteral, RuleContext &, size_t &) std::optional<ast::Formula> visit(const T &, const Clingo::AST::HeadLiteral &headLiteral, RuleContext &, size_t &)
{ {
throw TranslationException(headLiteral.location, "head literal currently unsupported in this context, expected literal, disjunction, or aggregate"); throw TranslationException(headLiteral.location, "head literal currently unsupported in this context, expected literal, disjunction, or aggregate");
return std::experimental::nullopt; return std::nullopt;
} }
}; };

View File

@ -48,7 +48,7 @@ ast::Term translate(const Clingo::AST::Term &term, RuleContext &ruleContext, con
struct TermTranslateVisitor struct TermTranslateVisitor
{ {
std::experimental::optional<ast::Term> visit(const Clingo::Symbol &symbol, const Clingo::AST::Term &term, RuleContext &ruleContext, const ast::VariableStack &variableStack) std::optional<ast::Term> visit(const Clingo::Symbol &symbol, const Clingo::AST::Term &term, RuleContext &ruleContext, const ast::VariableStack &variableStack)
{ {
switch (symbol.type()) switch (symbol.type())
{ {
@ -81,10 +81,10 @@ struct TermTranslateVisitor
} }
} }
return std::experimental::nullopt; return std::nullopt;
} }
std::experimental::optional<ast::Term> visit(const Clingo::AST::Variable &variable, const Clingo::AST::Term &, RuleContext &ruleContext, const ast::VariableStack &variableStack) std::optional<ast::Term> visit(const Clingo::AST::Variable &variable, const Clingo::AST::Term &, RuleContext &ruleContext, const ast::VariableStack &variableStack)
{ {
const auto matchingVariableDeclaration = variableStack.findUserVariableDeclaration(variable.name); const auto matchingVariableDeclaration = variableStack.findUserVariableDeclaration(variable.name);
const auto isAnonymousVariable = (strcmp(variable.name, "_") == 0); const auto isAnonymousVariable = (strcmp(variable.name, "_") == 0);
@ -100,13 +100,13 @@ struct TermTranslateVisitor
return ast::Term::make<ast::Variable>(ruleContext.freeVariables.back().get()); return ast::Term::make<ast::Variable>(ruleContext.freeVariables.back().get());
} }
std::experimental::optional<ast::Term> visit(const Clingo::AST::UnaryOperation &, const Clingo::AST::Term &term, RuleContext &, const ast::VariableStack &) std::optional<ast::Term> visit(const Clingo::AST::UnaryOperation &, const Clingo::AST::Term &term, RuleContext &, const ast::VariableStack &)
{ {
throw TranslationException(term.location, "“unary operation” terms currently unsupported"); throw TranslationException(term.location, "“unary operation” terms currently unsupported");
return std::experimental::nullopt; return std::nullopt;
} }
std::experimental::optional<ast::Term> visit(const Clingo::AST::BinaryOperation &binaryOperation, const Clingo::AST::Term &term, RuleContext &ruleContext, const ast::VariableStack &variableStack) std::optional<ast::Term> visit(const Clingo::AST::BinaryOperation &binaryOperation, const Clingo::AST::Term &term, RuleContext &ruleContext, const ast::VariableStack &variableStack)
{ {
const auto operator_ = translate(binaryOperation.binary_operator, term); const auto operator_ = translate(binaryOperation.binary_operator, term);
auto left = translate(binaryOperation.left, ruleContext, variableStack); auto left = translate(binaryOperation.left, ruleContext, variableStack);
@ -115,7 +115,7 @@ struct TermTranslateVisitor
return ast::Term::make<ast::BinaryOperation>(operator_, std::move(left), std::move(right)); return ast::Term::make<ast::BinaryOperation>(operator_, std::move(left), std::move(right));
} }
std::experimental::optional<ast::Term> visit(const Clingo::AST::Interval &interval, const Clingo::AST::Term &, RuleContext &ruleContext, const ast::VariableStack &variableStack) std::optional<ast::Term> visit(const Clingo::AST::Interval &interval, const Clingo::AST::Term &, RuleContext &ruleContext, const ast::VariableStack &variableStack)
{ {
auto left = translate(interval.left, ruleContext, variableStack); auto left = translate(interval.left, ruleContext, variableStack);
auto right = translate(interval.right, ruleContext, variableStack); auto right = translate(interval.right, ruleContext, variableStack);
@ -123,7 +123,7 @@ struct TermTranslateVisitor
return ast::Term::make<ast::Interval>(std::move(left), std::move(right)); return ast::Term::make<ast::Interval>(std::move(left), std::move(right));
} }
std::experimental::optional<ast::Term> visit(const Clingo::AST::Function &function, const Clingo::AST::Term &term, RuleContext &ruleContext, const ast::VariableStack &variableStack) std::optional<ast::Term> visit(const Clingo::AST::Function &function, const Clingo::AST::Term &term, RuleContext &ruleContext, const ast::VariableStack &variableStack)
{ {
if (function.external) if (function.external)
throw TranslationException(term.location, "external functions currently unsupported"); throw TranslationException(term.location, "external functions currently unsupported");
@ -137,10 +137,10 @@ struct TermTranslateVisitor
return ast::Term::make<ast::Function>(function.name, std::move(arguments)); return ast::Term::make<ast::Function>(function.name, std::move(arguments));
} }
std::experimental::optional<ast::Term> visit(const Clingo::AST::Pool &, const Clingo::AST::Term &term, RuleContext &, const ast::VariableStack &) std::optional<ast::Term> visit(const Clingo::AST::Pool &, const Clingo::AST::Term &term, RuleContext &, const ast::VariableStack &)
{ {
throw TranslationException(term.location, "“pool” terms currently unsupported"); throw TranslationException(term.location, "“pool” terms currently unsupported");
return std::experimental::nullopt; return std::nullopt;
} }
}; };

View File

@ -27,7 +27,7 @@ void VariableStack::pop()
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
std::experimental::optional<VariableDeclaration *> VariableStack::findUserVariableDeclaration(const char *variableName) const std::optional<VariableDeclaration *> VariableStack::findUserVariableDeclaration(const char *variableName) const
{ {
const auto variableDeclarationMatches = const auto variableDeclarationMatches =
[&variableName](const auto &variableDeclaration) [&variableName](const auto &variableDeclaration)
@ -45,7 +45,7 @@ std::experimental::optional<VariableDeclaration *> VariableStack::findUserVariab
return matchingVariableDeclaration->get(); return matchingVariableDeclaration->get();
} }
return std::experimental::nullopt; return std::nullopt;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -1,6 +1,6 @@
#include <anthem/Simplification.h> #include <anthem/Simplification.h>
#include <experimental/optional> #include <optional>
#include <anthem/ASTCopy.h> #include <anthem/ASTCopy.h>
#include <anthem/ASTVisitors.h> #include <anthem/ASTVisitors.h>
@ -27,15 +27,15 @@ bool matchesVariableDeclaration(const ast::Term &term, const ast::VariableDeclar
// Extracts the term t if the given formula is of the form “X = t” and X matches the given variable // Extracts the term t if the given formula is of the form “X = t” and X matches the given variable
// The input formula is no longer usable after this call if a term is returned // The input formula is no longer usable after this call if a term is returned
std::experimental::optional<ast::Term> extractAssignedTerm(ast::Formula &formula, const ast::VariableDeclaration &variableDeclaration) std::optional<ast::Term> extractAssignedTerm(ast::Formula &formula, const ast::VariableDeclaration &variableDeclaration)
{ {
if (!formula.is<ast::Comparison>()) if (!formula.is<ast::Comparison>())
return std::experimental::nullopt; return std::nullopt;
auto &comparison = formula.get<ast::Comparison>(); auto &comparison = formula.get<ast::Comparison>();
if (comparison.operator_ != ast::Comparison::Operator::Equal) if (comparison.operator_ != ast::Comparison::Operator::Equal)
return std::experimental::nullopt; return std::nullopt;
if (matchesVariableDeclaration(comparison.left, variableDeclaration)) if (matchesVariableDeclaration(comparison.left, variableDeclaration))
return std::move(comparison.right); return std::move(comparison.right);
@ -43,7 +43,7 @@ std::experimental::optional<ast::Term> extractAssignedTerm(ast::Formula &formula
if (matchesVariableDeclaration(comparison.right, variableDeclaration)) if (matchesVariableDeclaration(comparison.right, variableDeclaration))
return std::move(comparison.left); return std::move(comparison.left);
return std::experimental::nullopt; return std::nullopt;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////