Skip to content

Commit 3917d50

Browse files
committed
Code for 2nd edition
1 parent 7eebcbd commit 3917d50

File tree

302 files changed

+1251
-1381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

302 files changed

+1251
-1381
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: ci
44
on: [push, pull_request]
55

66
env:
7-
CMAKE_VERSION: 3.16.2
7+
CMAKE_VERSION: 3.28.2
88
NINJA_VERSION: 1.10.0
99

1010
jobs:
@@ -15,22 +15,22 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
config:
18-
# GCC-10
18+
# GCC-13
1919
- {
20-
name: "Linux GCC 11",
21-
os: ubuntu-20.04,
20+
name: "Linux GCC 13",
21+
os: ubuntu-22.04,
2222
build_type: Release,
23-
cxx: "g++-11",
24-
gcc_version: 11,
23+
cxx: "g++-13",
24+
gcc_version: 13,
2525
}
2626

27-
# Clang-14
27+
# Clang-17
2828
- {
29-
name: "Linux Clang 14",
30-
os: ubuntu-20.04,
29+
name: "Linux Clang 17",
30+
os: ubuntu-22.04,
3131
build_type: Release,
32-
cxx: "clang++-14",
33-
clang_version: 14,
32+
cxx: "clang++-17",
33+
clang_version: 17,
3434
libcxx: true
3535
}
3636

@@ -52,7 +52,7 @@ jobs:
5252
}
5353

5454
steps:
55-
- uses: actions/checkout@v2
55+
- uses: actions/checkout@v4
5656
with:
5757
fetch-depth: 2
5858

@@ -67,16 +67,16 @@ jobs:
6767
6868
if ("${{ runner.os }}" STREQUAL "Windows")
6969
set(ninja_suffix "win.zip")
70-
set(cmake_suffix "win64-x64.zip")
71-
set(cmake_dir "cmake-${cmake_version}-win64-x64/bin")
70+
set(cmake_suffix "windows-x86_64.zip")
71+
set(cmake_dir "cmake-${cmake_version}-windows-x86_64/bin")
7272
elseif ("${{ runner.os }}" STREQUAL "Linux")
7373
set(ninja_suffix "linux.zip")
74-
set(cmake_suffix "Linux-x86_64.tar.gz")
75-
set(cmake_dir "cmake-${cmake_version}-Linux-x86_64/bin")
74+
set(cmake_suffix "linux-x86_64.tar.gz")
75+
set(cmake_dir "cmake-${cmake_version}-linux-x86_64/bin")
7676
elseif ("${{ runner.os }}" STREQUAL "macOS")
7777
set(ninja_suffix "mac.zip")
78-
set(cmake_suffix "Darwin-x86_64.tar.gz")
79-
set(cmake_dir "cmake-${cmake_version}-Darwin-x86_64/CMake.app/Contents/bin")
78+
set(cmake_suffix "macos-universal.tar.gz")
79+
set(cmake_dir "cmake-${cmake_version}-macos-universal/CMake.app/Contents/bin")
8080
endif()
8181
8282
set(ninja_url "https://github.com/ninja-build/ninja/releases/download/v${ninja_version}/ninja-${ninja_suffix}")
@@ -98,8 +98,8 @@ jobs:
9898
)
9999
endif()
100100
101-
- name: Install Clang 14
102-
id: install_clang_11
101+
- name: Install Clang 17
102+
id: install_clang_17
103103
if: startsWith(matrix.config.os, 'ubuntu') && startsWith(matrix.config.cxx, 'clang++-')
104104
shell: bash
105105
working-directory: ${{ env.HOME }}
@@ -109,9 +109,9 @@ jobs:
109109
sudo ./llvm.sh ${{ matrix.config.clang_version }}
110110
sudo apt-get install -y libunwind-${{ matrix.config.clang_version }}-dev libunwind-${{ matrix.config.clang_version }}
111111
112-
- name: Install g++ 11
113-
id: install_gcc_11
114-
if: startsWith(matrix.config.os, 'ubuntu') && ( matrix.config.cxx == 'g++-11' )
112+
- name: Install g++ 13
113+
id: install_gcc_13
114+
if: startsWith(matrix.config.os, 'ubuntu') && ( matrix.config.cxx == 'g++-13' )
115115
shell: bash
116116
working-directory: ${{ env.HOME }}
117117
env:
@@ -121,7 +121,7 @@ jobs:
121121
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
122122
sudo apt-get update
123123
sudo apt-get install g++-${{ matrix.config.gcc_version }}
124-
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
124+
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 100
125125
126126
- name: Install libc++
127127
id: install_libcxx

01.01-variadicTemplateSum2/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 17)

01.02-variableTemplate0/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 14)

01.05-variadicTemplateSum3/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 20)

01.06-simpleRequirement0/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 20)

01.06-simpleRequirement0/main.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ template<typename T, typename... Ts>
88
constexpr bool are_same_v = std::conjunction_v<std::is_same<T, Ts>...>;
99

1010
template<typename... Args>
11-
requires
11+
requires
1212

13-
requires(Args... args)
14-
{
15-
(... + args); // #C SR: args provides +
16-
}
13+
requires(Args... args) {
14+
(... + args); // #C SR: args provides +
15+
}
1716

1817
auto add(const Args&... args)
1918
{

01.07-nestedRequirement0/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 20)

01.08-compoundRequirement0/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 20)

01.08-compoundRequirement0/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ requires(Args... args)
3434
}
3535

3636

37-
auto add(Args&&... args)
37+
auto add(Args&&... args) noexcept
3838
{
3939
return (... + args);
4040
}

01.09-typeRequirement0/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 20)

01.09-typeRequirement0/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#include <vector>
66

77
template<typename T>
8-
concept containerTypes = requires(T t)
9-
{ // #A Testing for various types in T
8+
concept containerTypes = requires(T t) { // #A Testing for various types in T
109
typename T::value_type;
1110
typename T::size_type;
1211
typename T::allocator_type;

01.10-compoundRequirement1/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 20)

01.10-compoundRequirement1/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ requires requires(Args... args)
2727
requires sizeof...(Args) > 1;
2828
{ (... + args) } noexcept -> same_as<first_arg_t<Args...>>;
2929
}
30-
auto Add(Args&&... args)
30+
auto Add(Args&&... args) noexcept
3131
{
3232
return (... + args);
3333
}

01.11-compoundRequirement2/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 20)

01.11-compoundRequirement2/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ concept Addable = requires(Args... args)
3030

3131
template<typename... Args>
3232
requires Addable<Args...>
33-
auto Add(Args&&... args)
33+
auto Add(Args&&... args) noexcept
3434
{
3535
return (... + args);
3636
}

01.12-testingRequirements0/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 20)

01.12-testingRequirements0/main.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,17 @@ template<typename... Args>
2121
using first_arg_t = typename first_arg<Args...>::type;
2222

2323
template<typename... Args>
24-
concept Addable = requires(Args... args)
25-
{
24+
concept Addable = requires(Args... args) {
2625
(... + args);
2726
requires are_same_v<Args...>;
2827
requires sizeof...(Args) > 1;
2928
{
3029
(... + args)
31-
}
32-
noexcept->same_as<first_arg_t<Args...>>;
30+
} noexcept -> same_as<first_arg_t<Args...>>;
3331
};
3432

3533
template<typename... Args>
36-
requires Addable<Args...>
34+
requires Addable<Args...>
3735
auto Add(Args&&... args)
3836
{
3937
return (... + args);
@@ -44,15 +42,15 @@ auto Add(Args&&... args)
4442
template<bool nexcept, bool operatorPlus, bool validReturnType>
4543
struct Stub {
4644
// #B Operator plus with controlled noexcept can be enabled
47-
Stub& operator+(const Stub& rhs) noexcept(nexcept) requires(
48-
operatorPlus&& validReturnType)
45+
Stub& operator+(const Stub& rhs) noexcept(nexcept)
46+
requires(operatorPlus && validReturnType)
4947
{
5048
return *this;
5149
}
5250

5351
// #C Operator plus with invalid return type
54-
int operator+(const Stub& rhs) noexcept(nexcept) requires(
55-
operatorPlus && not validReturnType)
52+
int operator+(const Stub& rhs) noexcept(nexcept)
53+
requires(operatorPlus && not validReturnType)
5654
{
5755
return {};
5856
}

01.14-invocable0/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 20)

01.14-invocable0/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ void DoLocked(T&& f)
1818

1919
int main()
2020
{
21-
DoLocked([] { printf("hello\n"); });
21+
DoLocked([] { puts("hello"); });
2222
}

01.15-invocable1/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 20)

01.15-invocable1/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ void DoLocked(std::invocable auto&& f)
1919

2020
int main()
2121
{
22-
DoLocked([] { printf("hello\n"); });
22+
DoLocked([] { puts("hello"); });
2323
}

01.16-constexprFunctionInConcept0/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 20)

01.18-vectorsSize0/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 11)

01.21-vectorsSize1/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 20)

01.22-validateInDebugModeIfExists0/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 20)

01.22-validateInDebugModeIfExists0/main.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
#include <cstdio>
55

66
template<typename T>
7-
concept SupportsValidation = requires(T t)
8-
{
9-
t.validate();
10-
};
7+
concept SupportsValidation = requires(T t) { t.validate(); };
118

129
template<typename T>
1310
void Send(const T& data)

01.24-optional0/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 17)

01.26-optional1/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Andreas Fertig.
22
# SPDX-License-Identifier: MIT
33

4-
cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)
55

66
set(CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_STANDARD 17)

0 commit comments

Comments
 (0)