Skip to content

Commit

Permalink
Code for 2nd edition
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasfertig committed Feb 8, 2024
1 parent 7eebcbd commit 3917d50
Show file tree
Hide file tree
Showing 302 changed files with 1,251 additions and 1,381 deletions.
48 changes: 24 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: ci
on: [push, pull_request]

env:
CMAKE_VERSION: 3.16.2
CMAKE_VERSION: 3.28.2
NINJA_VERSION: 1.10.0

jobs:
Expand All @@ -15,22 +15,22 @@ jobs:
fail-fast: false
matrix:
config:
# GCC-10
# GCC-13
- {
name: "Linux GCC 11",
os: ubuntu-20.04,
name: "Linux GCC 13",
os: ubuntu-22.04,
build_type: Release,
cxx: "g++-11",
gcc_version: 11,
cxx: "g++-13",
gcc_version: 13,
}

# Clang-14
# Clang-17
- {
name: "Linux Clang 14",
os: ubuntu-20.04,
name: "Linux Clang 17",
os: ubuntu-22.04,
build_type: Release,
cxx: "clang++-14",
clang_version: 14,
cxx: "clang++-17",
clang_version: 17,
libcxx: true
}

Expand All @@ -52,7 +52,7 @@ jobs:
}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 2

Expand All @@ -67,16 +67,16 @@ jobs:
if ("${{ runner.os }}" STREQUAL "Windows")
set(ninja_suffix "win.zip")
set(cmake_suffix "win64-x64.zip")
set(cmake_dir "cmake-${cmake_version}-win64-x64/bin")
set(cmake_suffix "windows-x86_64.zip")
set(cmake_dir "cmake-${cmake_version}-windows-x86_64/bin")
elseif ("${{ runner.os }}" STREQUAL "Linux")
set(ninja_suffix "linux.zip")
set(cmake_suffix "Linux-x86_64.tar.gz")
set(cmake_dir "cmake-${cmake_version}-Linux-x86_64/bin")
set(cmake_suffix "linux-x86_64.tar.gz")
set(cmake_dir "cmake-${cmake_version}-linux-x86_64/bin")
elseif ("${{ runner.os }}" STREQUAL "macOS")
set(ninja_suffix "mac.zip")
set(cmake_suffix "Darwin-x86_64.tar.gz")
set(cmake_dir "cmake-${cmake_version}-Darwin-x86_64/CMake.app/Contents/bin")
set(cmake_suffix "macos-universal.tar.gz")
set(cmake_dir "cmake-${cmake_version}-macos-universal/CMake.app/Contents/bin")
endif()
set(ninja_url "https://github.com/ninja-build/ninja/releases/download/v${ninja_version}/ninja-${ninja_suffix}")
Expand All @@ -98,8 +98,8 @@ jobs:
)
endif()
- name: Install Clang 14
id: install_clang_11
- name: Install Clang 17
id: install_clang_17
if: startsWith(matrix.config.os, 'ubuntu') && startsWith(matrix.config.cxx, 'clang++-')
shell: bash
working-directory: ${{ env.HOME }}
Expand All @@ -109,9 +109,9 @@ jobs:
sudo ./llvm.sh ${{ matrix.config.clang_version }}
sudo apt-get install -y libunwind-${{ matrix.config.clang_version }}-dev libunwind-${{ matrix.config.clang_version }}
- name: Install g++ 11
id: install_gcc_11
if: startsWith(matrix.config.os, 'ubuntu') && ( matrix.config.cxx == 'g++-11' )
- name: Install g++ 13
id: install_gcc_13
if: startsWith(matrix.config.os, 'ubuntu') && ( matrix.config.cxx == 'g++-13' )
shell: bash
working-directory: ${{ env.HOME }}
env:
Expand All @@ -121,7 +121,7 @@ jobs:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-${{ matrix.config.gcc_version }}
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 100
- name: Install libc++
id: install_libcxx
Expand Down
2 changes: 1 addition & 1 deletion 01.01-variadicTemplateSum2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
Expand Down
2 changes: 1 addition & 1 deletion 01.02-variableTemplate0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 14)
Expand Down
2 changes: 1 addition & 1 deletion 01.05-variadicTemplateSum3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand Down
2 changes: 1 addition & 1 deletion 01.06-simpleRequirement0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand Down
9 changes: 4 additions & 5 deletions 01.06-simpleRequirement0/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ template<typename T, typename... Ts>
constexpr bool are_same_v = std::conjunction_v<std::is_same<T, Ts>...>;

template<typename... Args>
requires
requires

requires(Args... args)
{
(... + args); // #C SR: args provides +
}
requires(Args... args) {
(... + args); // #C SR: args provides +
}

auto add(const Args&... args)
{
Expand Down
2 changes: 1 addition & 1 deletion 01.07-nestedRequirement0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand Down
2 changes: 1 addition & 1 deletion 01.08-compoundRequirement0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand Down
2 changes: 1 addition & 1 deletion 01.08-compoundRequirement0/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ requires(Args... args)
}


auto add(Args&&... args)
auto add(Args&&... args) noexcept
{
return (... + args);
}
Expand Down
2 changes: 1 addition & 1 deletion 01.09-typeRequirement0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand Down
3 changes: 1 addition & 2 deletions 01.09-typeRequirement0/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#include <vector>

template<typename T>
concept containerTypes = requires(T t)
{ // #A Testing for various types in T
concept containerTypes = requires(T t) { // #A Testing for various types in T
typename T::value_type;
typename T::size_type;
typename T::allocator_type;
Expand Down
2 changes: 1 addition & 1 deletion 01.10-compoundRequirement1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand Down
2 changes: 1 addition & 1 deletion 01.10-compoundRequirement1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ requires requires(Args... args)
requires sizeof...(Args) > 1;
{ (... + args) } noexcept -> same_as<first_arg_t<Args...>>;
}
auto Add(Args&&... args)
auto Add(Args&&... args) noexcept
{
return (... + args);
}
Expand Down
2 changes: 1 addition & 1 deletion 01.11-compoundRequirement2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand Down
2 changes: 1 addition & 1 deletion 01.11-compoundRequirement2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ concept Addable = requires(Args... args)

template<typename... Args>
requires Addable<Args...>
auto Add(Args&&... args)
auto Add(Args&&... args) noexcept
{
return (... + args);
}
Expand Down
2 changes: 1 addition & 1 deletion 01.12-testingRequirements0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand Down
16 changes: 7 additions & 9 deletions 01.12-testingRequirements0/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ template<typename... Args>
using first_arg_t = typename first_arg<Args...>::type;

template<typename... Args>
concept Addable = requires(Args... args)
{
concept Addable = requires(Args... args) {
(... + args);
requires are_same_v<Args...>;
requires sizeof...(Args) > 1;
{
(... + args)
}
noexcept->same_as<first_arg_t<Args...>>;
} noexcept -> same_as<first_arg_t<Args...>>;
};

template<typename... Args>
requires Addable<Args...>
requires Addable<Args...>
auto Add(Args&&... args)
{
return (... + args);
Expand All @@ -44,15 +42,15 @@ auto Add(Args&&... args)
template<bool nexcept, bool operatorPlus, bool validReturnType>
struct Stub {
// #B Operator plus with controlled noexcept can be enabled
Stub& operator+(const Stub& rhs) noexcept(nexcept) requires(
operatorPlus&& validReturnType)
Stub& operator+(const Stub& rhs) noexcept(nexcept)
requires(operatorPlus && validReturnType)
{
return *this;
}

// #C Operator plus with invalid return type
int operator+(const Stub& rhs) noexcept(nexcept) requires(
operatorPlus && not validReturnType)
int operator+(const Stub& rhs) noexcept(nexcept)
requires(operatorPlus && not validReturnType)
{
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion 01.14-invocable0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand Down
2 changes: 1 addition & 1 deletion 01.14-invocable0/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ void DoLocked(T&& f)

int main()
{
DoLocked([] { printf("hello\n"); });
DoLocked([] { puts("hello"); });
}
2 changes: 1 addition & 1 deletion 01.15-invocable1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand Down
2 changes: 1 addition & 1 deletion 01.15-invocable1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ void DoLocked(std::invocable auto&& f)

int main()
{
DoLocked([] { printf("hello\n"); });
DoLocked([] { puts("hello"); });
}
2 changes: 1 addition & 1 deletion 01.16-constexprFunctionInConcept0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand Down
2 changes: 1 addition & 1 deletion 01.18-vectorsSize0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
Expand Down
2 changes: 1 addition & 1 deletion 01.21-vectorsSize1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand Down
2 changes: 1 addition & 1 deletion 01.22-validateInDebugModeIfExists0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
Expand Down
5 changes: 1 addition & 4 deletions 01.22-validateInDebugModeIfExists0/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
#include <cstdio>

template<typename T>
concept SupportsValidation = requires(T t)
{
t.validate();
};
concept SupportsValidation = requires(T t) { t.validate(); };

template<typename T>
void Send(const T& data)
Expand Down
2 changes: 1 addition & 1 deletion 01.24-optional0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
Expand Down
2 changes: 1 addition & 1 deletion 01.26-optional1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Andreas Fertig.
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.16.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.28.2 FATAL_ERROR)

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
Expand Down
Loading

0 comments on commit 3917d50

Please sign in to comment.