Skip to content

Commit a91eb91

Browse files
committed
Move from C++17 to C++20
* constexpr the rest of the things * use concepts where appropriate * add UDL (could have been done in C++11, but these are consteval (C++20)) * simplify output with std::format
1 parent c8dd3c5 commit a91eb91

10 files changed

+247
-234
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.21)
66

77
# Only set the cxx_standard if it is not set by someone else
88
if (NOT DEFINED CMAKE_CXX_STANDARD)
9-
set(CMAKE_CXX_STANDARD 17)
9+
set(CMAKE_CXX_STANDARD 20)
1010
endif()
1111

1212
# strongly encouraged to enable this globally to avoid conflicts between

src/infiz/infiz.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
#include "../libinfiz/Evaluator.hpp"
44

55
#include <array>
6+
#include <format>
67
#include <iostream>
78

89
constexpr int max_line = 255;
910

10-
auto main(int /*argc*/, char * /*args*/[]) -> int
11+
auto main() -> int
1112
{
1213
std::array<char, max_line> input{};
1314

@@ -18,9 +19,10 @@ auto main(int /*argc*/, char * /*args*/[]) -> int
1819
std::cout << "answer: ";
1920

2021
if (answer.getDenominator() == 1) {
21-
std::cout << answer.getNumerator() << '\n';
22+
std::cout << std::format("{}\n", answer.getNumerator());
2223
} else {
23-
std::cout << answer.getNumerator() << '/' << answer.getDenominator() << " (" << answer.getFloat() << ")" << '\n';
24+
std::cout << std::format(
25+
"{}/{} ({})\n", answer.getNumerator(), answer.getDenominator(), answer.asFloat<double>());
2426
}
2527

2628
std::cin.getline(input.data(), max_line - 1, '\n');

src/libinfiz/CMakeLists.txt

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
include(GenerateExportHeader)
22

33

4-
add_library(libinfiz
5-
Evaluator.cpp
6-
)
4+
add_library(libinfiz INTERFACE)
75

86

97

108
add_library(infiz::libinfiz ALIAS libinfiz)
119

12-
target_link_libraries(libinfiz PRIVATE infiz_options infiz_warnings -fsanitize=fuzzer-no-link)
1310

14-
if (infiz_BUILD_FUZZ_TESTS)
15-
target_link_libraries(libinfiz PRIVATE -fsanitize=fuzzer-no-link)
16-
target_compile_options(libinfiz PRIVATE -fsanitize=fuzzer-no-link)
17-
endif()
18-
19-
target_include_directories(libinfiz ${WARNING_GUARD} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
11+
target_include_directories(libinfiz ${WARNING_GUARD} INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
2012
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>)
2113

2214

@@ -28,6 +20,3 @@ set_target_properties(
2820

2921
generate_export_header(libinfiz EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/include/infiz/libinfiz_export.hpp)
3022

31-
if(NOT BUILD_SHARED_LIBS)
32-
target_compile_definitions(libinfiz PUBLIC libinfiz_STATIC_DEFINE)
33-
endif()

src/libinfiz/Evaluator.cpp

-164
This file was deleted.

0 commit comments

Comments
 (0)