Giter Club home page Giter Club logo

cplusplus20forprogrammers's Introduction

C++20 for Programmers

This repository contains the source code and supporting files associated with our book C++20 for Programmers. https://deitel.com/c-plus-plus-20-for-programmers

These files are Copyright 2022 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.

You may use these files for your personal purposes, but please do not repost them without our express written consent.

If you have any questions, open an issue in the Issues tab or email us: deitel at deitel dot com.

The authors and publisher of this book have used their best efforts in preparing this book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The authors and publisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation contained in this book. The authors and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs.

cplusplus20forprogrammers's People

Contributors

pdeitel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cplusplus20forprogrammers's Issues

fig09_28.cpp friend declaration

friend void setX(Count& c, int value); // line 9

I think should be

friend void modifyX(Count& c, int value); // line 9

Thanks for the amazing book, has been an excellent learning resource so far.

fig15_20.cpp was compiled error on VisualStudio 2022.

Hi there,

In my opinion, VS C++ does not fully qualify the iterator's type name due to I verify the below statement true.
std::cout << std::is_base_of_v<std::random_access_iterator_tag, std::array<int, 5>::iterator::iterator_category>; // 1(True)
I couldn't find any workaround yet.
Any idea or suggestion will be welcome.

Regards.

-----snip-----
Build started at 9:54 AM...
1>------ Build started: Project: cpp20_test, Configuration: Debug x64 ------
1>Source.cpp
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(15,24): error C2923: 'std::is_base_of_v': 'std::_Array_const_iterator<_Ty,5>::iterator_category' is not a valid template type argument for parameter '_Derived'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(15,24): error C2923: with
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(15,24): error C2923: [
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(15,24): error C2923: _Ty=int
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(15,24): error C2923: ]
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,19):
1>see declaration of 'std::_Array_const_iterator<_Ty,5>::iterator_category'
1> with
1> [
1> _Ty=int
1> ]
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(15,24):
1>the template instantiation context (the oldest one first) is
1> C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(39,19):
1> see reference to function template instantiation 'auto customDistance<std::_Array_const_iterator<_Ty,5>>(Iterator,Iterator)' being compiled
1> with
1> [
1> _Ty=int,
1> Iterator=std::_Array_const_iterator<int,5>
1> ]
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,19): error C2275: 'std::_Array_const_iterator<_Ty,5>::iterator_category': expected an expression instead of a type
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,19): error C2275: with
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,19): error C2275: [
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,19): error C2275: _Ty=int
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,19): error C2275: ]
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,37): error C2059: syntax error: ')'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,39): error C2143: syntax error: missing ';' before '{'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(13,51): error C2181: illegal else without matching if
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(15,24): error C2923: 'std::is_base_of_v': 'std::_List_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>>::iterator_category' is not a valid template type argument for parameter '_Derived'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(15,24): error C2923: with
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(15,24): error C2923: [
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(15,24): error C2923: _Ty=int
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(15,24): error C2923: ]
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,19):
1>see declaration of 'std::_List_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>>::iterator_category'
1> with
1> [
1> _Ty=int
1> ]
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(15,24):
1>the template instantiation context (the oldest one first) is
1> C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(41,19):
1> see reference to function template instantiation 'auto customDistance<std::_List_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>>>(Iterator,Iterator)' being compiled
1> with
1> [
1> _Ty=int,
1> Iterator=std::_List_const_iterator<std::_List_val<std::_List_simple_types>>
1> ]
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,19): error C2275: 'std::_List_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>>::iterator_category': expected an expression instead of a type
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,19): error C2275: with
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,19): error C2275: [
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,19): error C2275: _Ty=int
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(16,19): error C2275: ]
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(18,20): error C2676: binary '-': 'Iterator' does not define this operator or a conversion to a type acceptable to the predefined operator
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(18,20): error C2676: with
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(18,20): error C2676: [
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(18,20): error C2676: Iterator=std::_List_const_iterator<std::_List_val<std::_List_simple_types>>
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(18,20): error C2676: ]
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\xutility(1775,5):
1>could be 'unknown-type std::operator -(const std::reverse_iterator<_BidIt> &,const std::reverse_iterator<_BidIt2> &) noexcept()'
1> C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(18,16):
1> 'unknown-type std::operator -(const std::reverse_iterator<_BidIt> &,const std::reverse_iterator<_BidIt2> &) noexcept()': could not deduce template argument for 'const std::reverse_iterator<_BidIt> &' from 'Iterator'
1> with
1> [
1> Iterator=std::_List_const_iterator<std::_List_val<std::_List_simple_types>>
1> ]
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\xutility(4326,30):
1>or 'unknown-type std::operator -(const std::move_iterator<_Iter> &,const std::move_iterator<_Iter2> &) noexcept()'
1> C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(18,16):
1> 'unknown-type std::operator -(const std::move_iterator<_Iter> &,const std::move_iterator<_Iter2> &) noexcept()': could not deduce template argument for 'const std::move_iterator<_Iter> &' from 'Iterator'
1> with
1> [
1> Iterator=std::_List_const_iterator<std::_List_val<std::_List_simple_types>>
1> ]
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(20,5): error C2059: syntax error: 'else'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(26,9): error C2059: syntax error: 'for'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(13,51): error C2143: syntax error: missing ')' before ';'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(26,39): error C2143: syntax error: missing ';' before '!='
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(13,51): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(26,47): error C2059: syntax error: '++'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(26,53): error C2059: syntax error: ')'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(28,9): error C2059: syntax error: '}'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(31,5): error C2059: syntax error: '}'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(41,62): error C2143: syntax error: missing ';' before '}'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(41,62): error C2059: syntax error: '}'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(42,15): error C2143: syntax error: missing ';' before '<<'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(42,15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(42,10): error C2371: 'std::cout': redefinition; different basic types
1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\include\iostream(39,75):
1>see declaration of 'std::cout'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(43,1): error C2059: syntax error: '}'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(43,1): error C2143: syntax error: missing ';' before '}'
1>C:\Users\jmche\source\repos\Project1\cpp20_test\Source.cpp(60,1): error C1903: unable to recover from previous error(s); stopping compilation
1>Done building project "cpp20_test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 69 up-to-date, 0 skipped ==========
========== Build completed at 9:54 AM and took 08.896 seconds ==========

zip_file.hpp is missing

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.