Skip to content

Commit

Permalink
Move from C++17 to C++20
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lefticus committed Jan 15, 2024
1 parent c8dd3c5 commit a91eb91
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 234 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.21)

# Only set the cxx_standard if it is not set by someone else
if (NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
endif()

# strongly encouraged to enable this globally to avoid conflicts between
Expand Down
8 changes: 5 additions & 3 deletions src/infiz/infiz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#include "../libinfiz/Evaluator.hpp"

#include <array>
#include <format>
#include <iostream>

constexpr int max_line = 255;

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

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

if (answer.getDenominator() == 1) {
std::cout << answer.getNumerator() << '\n';
std::cout << std::format("{}\n", answer.getNumerator());
} else {
std::cout << answer.getNumerator() << '/' << answer.getDenominator() << " (" << answer.getFloat() << ")" << '\n';
std::cout << std::format(
"{}/{} ({})\n", answer.getNumerator(), answer.getDenominator(), answer.asFloat<double>());
}

std::cin.getline(input.data(), max_line - 1, '\n');
Expand Down
15 changes: 2 additions & 13 deletions src/libinfiz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
include(GenerateExportHeader)


add_library(libinfiz
Evaluator.cpp
)
add_library(libinfiz INTERFACE)



add_library(infiz::libinfiz ALIAS libinfiz)

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

if (infiz_BUILD_FUZZ_TESTS)
target_link_libraries(libinfiz PRIVATE -fsanitize=fuzzer-no-link)
target_compile_options(libinfiz PRIVATE -fsanitize=fuzzer-no-link)
endif()

target_include_directories(libinfiz ${WARNING_GUARD} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
target_include_directories(libinfiz ${WARNING_GUARD} INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>)


Expand All @@ -28,6 +20,3 @@ set_target_properties(

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

if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(libinfiz PUBLIC libinfiz_STATIC_DEFINE)
endif()
164 changes: 0 additions & 164 deletions src/libinfiz/Evaluator.cpp

This file was deleted.

Loading

0 comments on commit a91eb91

Please sign in to comment.