pdeitel / CPlusPlus20ForProgrammers

Code examples for our book _C++ 20 for Programmers_ (Pearson, 2020)
191 stars 89 forks source link

zip_file.hpp is missing #4

Open mikucionisaau opened 2 years ago

mikucionisaau commented 2 years ago

Congratulations with the book! I did not read it, I am looking for one for teaching, hence I am trying to compile blindly. Got stuck with an error:

examples/ch04/fig04_11.cpp:5:10: fatal error: zip_file.hpp: No such file or directory
    5 | #include "zip_file.hpp"

zip_file.hpp is not in the repo, where can we get it?

I hastily came up with CMake script to compile it (something like this would be nice to have in the repo):

cmake_minimum_required(VERSION 3.15)
project(CXX20ForProgrammers LANGUAGES CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # for clang-tidy
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)

add_subdirectory("examples/libraries/fmt")
add_subdirectory("examples/libraries/GSL")

file(GLOB sources "${CMAKE_CURRENT_SOURCE_DIR}/examples/ch*/*.cpp")
foreach(source ${sources})
  file(STRINGS ${source} hasmain REGEX ".+\ main\(.+\).+")
  if (hasmain)
    get_filename_component(name "${source}" NAME_WLE)
    if (NOT ${name} STREQUAL "fig04_07_with_error")
        add_executable(${name} ${source})
        file(STRINGS ${source} usesfmt REGEX ".+fmt/format.+")
        if (usesfmt)
          target_include_directories(${name} PRIVATE "examples/libraries/fmt/include")
          target_link_libraries(${name} PRIVATE fmt)
        endif()
        file(STRINGS ${source} usesgsl REGEX ".+gsl/gsl.+")
        if (usesgsl)
            target_include_directories(${name} PRIVATE "examples/libraries/GSL/include")
        endif()
    endif()
  endif(hasmain)
endforeach()

Then used the usual cmake dance:

cmake -S . -B build -G Ninja
cmake --build build
mikucionisaau commented 2 years ago

Some more similar issues:

examples/ch18/fig18_03.cpp:3:10: fatal error: concurrencpp/concurrencpp.h: No such file or directory
    3 | #include <concurrencpp/concurrencpp.h>
examples/ch18/fig18_01.cpp:7:10: fatal error: tl/generator.hpp: No such file or directory
    7 | #include <tl/generator.hpp>
examples/ch19/fig19_02.cpp:3:10: fatal error: format: No such file or directory
    3 | #include <format>
examples/ch19/fig19_18.cpp:3:10: fatal error: format: No such file or directory
    3 | #include <format>
examples/ch19/fig19_20.cpp:3:10: fatal error: format: No such file or directory
    3 | #include <format>
examples/ch19/fig19_03.cpp:3:10: fatal error: format: No such file or directory
    3 | #include <format>
examples/ch19/fig19_04.cpp:3:10: fatal error: format: No such file or directory
    3 | #include <format>
examples/ch19/fig19_21.cpp:3:10: fatal error: format: No such file or directory
    3 | #include <format>
examples/ch19/fig19_22.cpp:3:10: fatal error: format: No such file or directory
    3 | #include <format>
examples/ch19/fig19_23.cpp:3:10: fatal error: format: No such file or directory
    3 | #include <format>

This one assumes that format is available (which is not yet in GCC), maybe we could use fmt/format.h instead (as it is already supplied in this repo). I think the best would be to provide a header which would check for that feature using macro and include the appropriate header.

examples/ch15/fig15_20.cpp:19:18: error: no match for ‘operator-’ (operand types are ‘std::_List_const_iterator<int>’ and ‘std::_List_const_iterator<int>’)
   19 |       return end - begin; // O(1) operation for random-access iterators

I think it would be better to use std::distance(begin, end); which always works.

pdeitel commented 2 years ago

@mikucionisaau Thanks for posting. I will check the libraries folder and make sure I post the missing items. As for the ch19 header, we state in the chapter 1. that we purposely used it for demos, 2. that it only works in VC++ right now, and 3. that you can run the examples using <fmt/format.h> and fmt::format rather than and std::format. We actually used the {fmt} library throughout the rest of the book's earlier chapters. In fact, I may just post a separate version of the ch19 examples using {fmt} for those on other compilers.