from gadget import gadget, undo_magic_name
from IPython.core.getipython import get_ipython
ipython = get_ipython()
ipython.register_magic_function(gadget, 'cell')
array = [1, 2, 3, 4]
print(sum(array))
10
%%gadget -c ./oldc.c

#include<stdlib.h>
#include<stdio.h>

int main(){
    size_t nv = 4;
    int *v = (int *)malloc(nv * sizeof(int));
    v[0] = 4;
    v[1] = 3;
    v[2] = 2;
    v[3] = 1;

    int sum = 0;
    for(size_t i=0; i<nv; i++)
        sum += v[i];
    printf("%d\n", sum);
    free(v);
    return 0;
}
文件 ./oldc.c 创建成功,内容已写入。
!gcc ./oldc.c -o ./oldc
!./oldc
10
%%gadget -c cpp_98_stl.cpp

#include<vector>
#include<iostream>

int main(){
    std::vector<int> v(4);
    v[0] = 4;
    v[1] = 3;
    v[2] = 2;
    v[3] = 1;

    int sum = 0;
    for(size_t i=0; i<v.size(); i++)
        sum += v[i];
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_98_stl.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)

# 设置项目名称
project(Cpp98StlProject)

# 指定使用 C++98 标准
set(CMAKE_CXX_STANDARD 98)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_98_stl cpp_98_stl.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_98_stl
!build/cpp_98_stl
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
gmake: Warning: File 'Makefile' has modification time 0.22 s in the future
gmake[1]: Warning: File 'CMakeFiles/Makefile2' has modification time 0.35 s in the future
gmake[2]: Warning: File 'CMakeFiles/Makefile2' has modification time 0.28 s in the future
gmake[3]: Warning: File 'CMakeFiles/cpp_98_stl.dir/progress.make' has modification time 0.22 s in the future
Consolidate compiler generated dependencies of target cpp_98_stl
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[3]: Warning: File 'CMakeFiles/cpp_98_stl.dir/progress.make' has modification time 0.06 s in the future
[ 50%] Building CXX object CMakeFiles/cpp_98_stl.dir/cpp_98_stl.cpp.o
[100%] Linking CXX executable cpp_98_stl
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
[100%] Built target cpp_98_stl
gmake[2]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[1]: warning:  Clock skew detected.  Your build may be incomplete.
gmake: warning:  Clock skew detected.  Your build may be incomplete.
10
%%gadget -c cpp_11_lambda.cpp

#include<vector>
#include<iostream>

int main(){
    std::vector<int> v = {4, 3, 2, 1};
    int sum = 0;
    for(size_t i=0; i<v.size(); i++)
        sum += v[i];
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_11_lambda.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)

# 设置项目名称
project(Cpp11LambdaProject)

# 指定使用 C++11 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_11_lambda cpp_11_lambda.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_11_lambda
!build/cpp_11_lambda
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
Consolidate compiler generated dependencies of target cpp_11_lambda
gmake[3]: Warning: File 'CMakeFiles/cpp_11_lambda.dir/compiler_depend.make' has modification time 0.19 s in the future
[ 50%] Building CXX object CMakeFiles/cpp_11_lambda.dir/cpp_11_lambda.cpp.o
[100%] Linking CXX executable cpp_11_lambda
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
[100%] Built target cpp_11_lambda
10
%%gadget -c cpp_11_range_based_for_loop.cpp

#include<vector>
#include<iostream>

int main(){
    std::vector<int> v = {4, 3, 2, 1};
    int sum = 0;
    for (int vi:v)
        sum += vi;
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_11_range_based_for_loop.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)

# 设置项目名称
project(cpp11RangeBasedForLoopProject)

# 指定使用 C++11 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_11_range_based_for_loop cpp_11_range_based_for_loop.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_11_range_based_for_loop
!build/cpp_11_range_based_for_loop
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
Consolidate compiler generated dependencies of target cpp_11_range_based_for_loop
[ 50%] Building CXX object CMakeFiles/cpp_11_range_based_for_loop.dir/cpp_11_range_based_for_loop.cpp.o
[100%] Linking CXX executable cpp_11_range_based_for_loop
[100%] Built target cpp_11_range_based_for_loop
10
%%gadget -c cpp_11_for_each.cpp

#include<vector>
#include<iostream>
#include <algorithm>

int sum = 0;

void func(int vi){
    sum += vi;
}

int main(){
    std::vector<int> v = {4, 3, 2, 1};
    std::for_each(v.begin(), v.end(), func);
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_11_for_each.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.12)

# 设置项目名称
project(cpp11ForEachProject)

# 指定使用 C++11 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_11_for_each cpp_11_for_each.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_11_for_each
!build/cpp_11_for_each
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
Consolidate compiler generated dependencies of target cpp_11_for_each
[ 50%] Building CXX object CMakeFiles/cpp_11_for_each.dir/cpp_11_for_each.cpp.o
[100%] Linking CXX executable cpp_11_for_each
[100%] Built target cpp_11_for_each
10
%%gadget -c cpp_11_lambda_expression.cpp

#include<vector>
#include<iostream>
#include <algorithm>

int main(){
    std::vector<int> v = {4, 3, 2, 1};
    int sum = 0;
    std::for_each(v.begin(), v.end(), [&] (int vi){
        sum += vi;
    });
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_11_lambda_expression.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.12)

# 设置项目名称
project(cpp11LambdaExpressionProject)

# 指定使用 C++11 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_11_lambda_expression cpp_11_lambda_expression.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_11_lambda_expression
!build/cpp_11_lambda_expression
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
Consolidate compiler generated dependencies of target cpp_11_lambda_expression
[ 50%] Building CXX object CMakeFiles/cpp_11_lambda_expression.dir/cpp_11_lambda_expression.cpp.o
[100%] Linking CXX executable cpp_11_lambda_expression
[100%] Built target cpp_11_lambda_expression
10
%%gadget -c cpp_14_lambda_auto.cpp

#include<vector>
#include<iostream>
#include <algorithm>

int main(){
    std::vector<int> v = {4, 3, 2, 1};
    int sum = 0;
    std::for_each(v.begin(), v.end(), [&] (auto vi){
        sum += vi;
    });
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_14_lambda_auto.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.12)

# 设置项目名称
project(cpp14LambdaAutoProject)

# 指定使用 C++14 标准
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_14_lambda_auto cpp_14_lambda_auto.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
from gadget import gadget, undo_magic_name
from IPython.core.getipython import get_ipython
ipython = get_ipython()
ipython.register_magic_function(gadget, 'cell')
array = [1, 2, 3, 4]
print(sum(array))
10
%%gadget -c ./oldc.c

#include<stdlib.h>
#include<stdio.h>

int main(){
    size_t nv = 4;
    int *v = (int *)malloc(nv * sizeof(int));
    v[0] = 4;
    v[1] = 3;
    v[2] = 2;
    v[3] = 1;

    int sum = 0;
    for(size_t i=0; i<nv; i++)
        sum += v[i];
    printf("%d\n", sum);
    free(v);
    return 0;
}
文件 ./oldc.c 创建成功,内容已写入。
!gcc ./oldc.c -o ./oldc
!./oldc
10
%%gadget -c cpp_98_stl.cpp

#include<vector>
#include<iostream>

int main(){
    std::vector<int> v(4);
    v[0] = 4;
    v[1] = 3;
    v[2] = 2;
    v[3] = 1;

    int sum = 0;
    for(size_t i=0; i<v.size(); i++)
        sum += v[i];
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_98_stl.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)

# 设置项目名称
project(Cpp98StlProject)

# 指定使用 C++98 标准
set(CMAKE_CXX_STANDARD 98)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_98_stl cpp_98_stl.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_98_stl
!build/cpp_98_stl
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
Consolidate compiler generated dependencies of target cpp_98_stl
[ 50%] Building CXX object CMakeFiles/cpp_98_stl.dir/cpp_98_stl.cpp.o
[100%] Linking CXX executable cpp_98_stl
[100%] Built target cpp_98_stl
10
%%gadget -c cpp_11_lambda.cpp

#include<vector>
#include<iostream>

int main(){
    std::vector<int> v = {4, 3, 2, 1};
    int sum = 0;
    for(size_t i=0; i<v.size(); i++)
        sum += v[i];
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_11_lambda.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)

# 设置项目名称
project(Cpp11LambdaProject)

# 指定使用 C++11 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_11_lambda cpp_11_lambda.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_11_lambda
!build/cpp_11_lambda
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
gmake[1]: Warning: File 'CMakeFiles/Makefile2' has modification time 1.6 s in the future
gmake[2]: Warning: File 'CMakeFiles/Makefile2' has modification time 1.6 s in the future
gmake[3]: Warning: File 'CMakeFiles/cpp_11_lambda.dir/progress.make' has modification time 1.5 s in the future
Consolidate compiler generated dependencies of target cpp_11_lambda
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[3]: Warning: File 'CMakeFiles/cpp_11_lambda.dir/progress.make' has modification time 1.1 s in the future
[ 50%] Building CXX object CMakeFiles/cpp_11_lambda.dir/cpp_11_lambda.cpp.o
[100%] Linking CXX executable cpp_11_lambda
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
[100%] Built target cpp_11_lambda
gmake[2]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[1]: warning:  Clock skew detected.  Your build may be incomplete.
10
%%gadget -c cpp_11_range_based_for_loop.cpp

#include<vector>
#include<iostream>

int main(){
    std::vector<int> v = {4, 3, 2, 1};
    int sum = 0;
    for (int vi:v)
        sum += vi;
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_11_range_based_for_loop.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)

# 设置项目名称
project(cpp11RangeBasedForLoopProject)

# 指定使用 C++11 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_11_range_based_for_loop cpp_11_range_based_for_loop.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_11_range_based_for_loop
!build/cpp_11_range_based_for_loop
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
gmake: Warning: File 'Makefile' has modification time 1.4 s in the future
gmake[1]: Warning: File 'CMakeFiles/Makefile2' has modification time 1.4 s in the future
gmake[2]: Warning: File 'CMakeFiles/Makefile2' has modification time 1.3 s in the future
gmake[3]: Warning: File 'CMakeFiles/cpp_11_range_based_for_loop.dir/progress.make' has modification time 1.2 s in the future
Consolidate compiler generated dependencies of target cpp_11_range_based_for_loop
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[3]: Warning: File 'CMakeFiles/cpp_11_range_based_for_loop.dir/progress.make' has modification time 0.75 s in the future
[ 50%] Building CXX object CMakeFiles/cpp_11_range_based_for_loop.dir/cpp_11_range_based_for_loop.cpp.o
[100%] Linking CXX executable cpp_11_range_based_for_loop
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
[100%] Built target cpp_11_range_based_for_loop
gmake[2]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[1]: warning:  Clock skew detected.  Your build may be incomplete.
gmake: warning:  Clock skew detected.  Your build may be incomplete.
10
%%gadget -c cpp_11_for_each.cpp

#include<vector>
#include<iostream>
#include <algorithm>

int sum = 0;

void func(int vi){
    sum += vi;
}

int main(){
    std::vector<int> v = {4, 3, 2, 1};
    std::for_each(v.begin(), v.end(), func);
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_11_for_each.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.12)

# 设置项目名称
project(cpp11ForEachProject)

# 指定使用 C++11 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_11_for_each cpp_11_for_each.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_11_for_each
!build/cpp_11_for_each
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
gmake: Warning: File 'Makefile' has modification time 1.1 s in the future
gmake[1]: Warning: File 'CMakeFiles/Makefile2' has modification time 1.2 s in the future
gmake[2]: Warning: File 'CMakeFiles/Makefile2' has modification time 1.1 s in the future
gmake[3]: Warning: File 'CMakeFiles/cpp_11_for_each.dir/progress.make' has modification time 0.96 s in the future
Consolidate compiler generated dependencies of target cpp_11_for_each
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[3]: Warning: File 'CMakeFiles/cpp_11_for_each.dir/progress.make' has modification time 0.51 s in the future
[ 50%] Building CXX object CMakeFiles/cpp_11_for_each.dir/cpp_11_for_each.cpp.o
[100%] Linking CXX executable cpp_11_for_each
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
[100%] Built target cpp_11_for_each
gmake[2]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[1]: warning:  Clock skew detected.  Your build may be incomplete.
gmake: warning:  Clock skew detected.  Your build may be incomplete.
10
%%gadget -c cpp_11_lambda_expression.cpp

#include<vector>
#include<iostream>
#include <algorithm>

int main(){
    std::vector<int> v = {4, 3, 2, 1};
    int sum = 0;
    std::for_each(v.begin(), v.end(), [&] (int vi){
        sum += vi;
    });
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_11_lambda_expression.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.12)

# 设置项目名称
project(cpp11LambdaExpressionProject)

# 指定使用 C++11 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_11_lambda_expression cpp_11_lambda_expression.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_11_lambda_expression
!build/cpp_11_lambda_expression
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
gmake: Warning: File 'Makefile' has modification time 0.97 s in the future
gmake[1]: Warning: File 'CMakeFiles/Makefile2' has modification time 1 s in the future
gmake[2]: Warning: File 'CMakeFiles/Makefile2' has modification time 0.91 s in the future
gmake[3]: Warning: File 'CMakeFiles/cpp_11_lambda_expression.dir/progress.make' has modification time 0.84 s in the future
Consolidate compiler generated dependencies of target cpp_11_lambda_expression
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[3]: Warning: File 'CMakeFiles/cpp_11_lambda_expression.dir/progress.make' has modification time 0.49 s in the future
[ 50%] Building CXX object CMakeFiles/cpp_11_lambda_expression.dir/cpp_11_lambda_expression.cpp.o
[100%] Linking CXX executable cpp_11_lambda_expression
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
[100%] Built target cpp_11_lambda_expression
gmake[2]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[1]: warning:  Clock skew detected.  Your build may be incomplete.
gmake: warning:  Clock skew detected.  Your build may be incomplete.
10
%%gadget -c cpp_14_lambda_auto.cpp

#include<vector>
#include<iostream>
#include <algorithm>

int main(){
    std::vector<int> v = {4, 3, 2, 1};
    int sum = 0;
    std::for_each(v.begin(), v.end(), [&] (auto vi){
        sum += vi;
    });
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_14_lambda_auto.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.12)

# 设置项目名称
project(cpp14LambdaAutoProject)

# 指定使用 C++14 标准
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_14_lambda_auto cpp_14_lambda_auto.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_14_lambda_auto
!build/cpp_14_lambda_auto
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
gmake: Warning: File 'Makefile' has modification time 0.68 s in the future
gmake[1]: Warning: File 'CMakeFiles/Makefile2' has modification time 0.72 s in the future
gmake[2]: Warning: File 'CMakeFiles/Makefile2' has modification time 0.56 s in the future
gmake[3]: Warning: File 'CMakeFiles/cpp_14_lambda_auto.dir/progress.make' has modification time 0.46 s in the future
Consolidate compiler generated dependencies of target cpp_14_lambda_auto
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[3]: Warning: File 'CMakeFiles/cpp_14_lambda_auto.dir/compiler_depend.make' has modification time 0.88 s in the future
[ 50%] Building CXX object CMakeFiles/cpp_14_lambda_auto.dir/cpp_14_lambda_auto.cpp.o
[100%] Linking CXX executable cpp_14_lambda_auto
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
[100%] Built target cpp_14_lambda_auto
gmake[2]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[1]: warning:  Clock skew detected.  Your build may be incomplete.
gmake: warning:  Clock skew detected.  Your build may be incomplete.
10
!cmake -B build
!cmake --build build --target cpp_14_lambda_auto
!build/cpp_14_lambda_auto
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
gmake: Warning: File 'Makefile' has modification time 0.48 s in the future
gmake[1]: Warning: File 'CMakeFiles/Makefile2' has modification time 0.61 s in the future
gmake[2]: Warning: File 'CMakeFiles/Makefile2' has modification time 0.53 s in the future
gmake[3]: Warning: File 'CMakeFiles/cpp_14_lambda_auto.dir/progress.make' has modification time 0.44 s in the future
Consolidate compiler generated dependencies of target cpp_14_lambda_auto
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[3]: Warning: File 'CMakeFiles/cpp_14_lambda_auto.dir/progress.make' has modification time 0.15 s in the future
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
[100%] Built target cpp_14_lambda_auto
gmake[2]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[1]: warning:  Clock skew detected.  Your build may be incomplete.
gmake: warning:  Clock skew detected.  Your build may be incomplete.
10
%%gadget -c cpp_17_CTAD.cpp

#include<vector>
#include<iostream>
#include <algorithm>

int main(){
    std::vector<int> v = {4, 3, 2, 1};
    int sum = 0;
    std::for_each(v.begin(), v.end(), [&] (auto vi){
        sum += vi;
    });
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_17_CTAD.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.12)

# 设置项目名称
project(cpp17CTADProject)

# 指定使用 C++17 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_17_CTAD cpp_17_CTAD.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_17_CTAD
!build/cpp_17_CTAD
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
gmake: Warning: File 'Makefile' has modification time 0.35 s in the future
gmake[1]: Warning: File 'CMakeFiles/Makefile2' has modification time 0.45 s in the future
gmake[2]: Warning: File 'CMakeFiles/Makefile2' has modification time 0.34 s in the future
gmake[3]: Warning: File 'CMakeFiles/cpp_17_CTAD.dir/progress.make' has modification time 0.23 s in the future
Consolidate compiler generated dependencies of target cpp_17_CTAD
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[3]: Warning: File 'CMakeFiles/cpp_17_CTAD.dir/compiler_depend.make' has modification time 0.51 s in the future
[ 50%] Building CXX object CMakeFiles/cpp_17_CTAD.dir/cpp_17_CTAD.cpp.o
[100%] Linking CXX executable cpp_17_CTAD
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
[100%] Built target cpp_17_CTAD
gmake[2]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[1]: warning:  Clock skew detected.  Your build may be incomplete.
gmake: warning:  Clock skew detected.  Your build may be incomplete.
10
%%gadget -c cpp_17_numeric.cpp

#include<vector>
#include<iostream>
#include <numeric>

int main(){
    std::vector v = {4, 3, 2, 1};
    int sum = std::reduce(v.begin(), v.end());
    std::cout << sum << std::endl;
    return 0;
}
文件 cpp_17_numeric.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.12)

# 设置项目名称
project(cpp17CTADProject)

# 指定使用 C++17 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_17_numeric cpp_17_numeric.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_17_numeric
!build/cpp_17_numeric
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
gmake[1]: Warning: File 'CMakeFiles/Makefile2' has modification time 0.12 s in the future
gmake[2]: Warning: File 'CMakeFiles/Makefile2' has modification time 0.0069 s in the future
Consolidate compiler generated dependencies of target cpp_17_numeric
gmake[3]: Warning: File 'CMakeFiles/cpp_17_numeric.dir/compiler_depend.make' has modification time 0.33 s in the future
[ 50%] Building CXX object CMakeFiles/cpp_17_numeric.dir/cpp_17_numeric.cpp.o
[100%] Linking CXX executable cpp_17_numeric
gmake[3]: warning:  Clock skew detected.  Your build may be incomplete.
[100%] Built target cpp_17_numeric
gmake[2]: warning:  Clock skew detected.  Your build may be incomplete.
gmake[1]: warning:  Clock skew detected.  Your build may be incomplete.
10
%%gadget -c cpp_20_ranges.cpp

#include<vector>
#include<iostream>
#include<numeric>
#include<ranges>
#include<cmath>

int main(){
    std::vector v = {4, 3, 2, 1, 0, -1, -2};
    for (auto &&vi : v
     | std::views::filter([](auto &&x) {return x >= 0; }) 
     | std::views::transform([] (auto &&x) { return sqrtf(x); })
     ){
        std::cout << vi << std::endl;
     }
    return 0;
}
文件 cpp_20_ranges.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.12)

# 设置项目名称
project(cpp20RangesProject)

# 指定使用 C++20 标准
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_20_ranges cpp_20_ranges.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_20_ranges
!build/cpp_20_ranges
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
Consolidate compiler generated dependencies of target cpp_20_ranges
[ 50%] Building CXX object CMakeFiles/cpp_20_ranges.dir/cpp_20_ranges.cpp.o
[100%] Linking CXX executable cpp_20_ranges
[100%] Built target cpp_20_ranges
2
1.73205
1.41421
1
0
%%gadget -c cpp_20_module.cpp

import <vector>;
import <iostream>;
import <numeric>;
import <ranges>;
import <cmath>;

int main(){
    std::vector v = {4, 3, 2, 1, 0, -1, -2};
    for (auto &&vi : v
     | std::views::filter([](auto &&x) {return x >= 0; }) 
     | std::views::transform([] (auto &&x) { return sqrtf(x); })
     ){
        std::cout << vi << std::endl;
     }
    return 0;
}
文件 cpp_20_module.cpp 创建成功,内容已写入。
%%gadget -c CMakeLists.txt

# 设置 CMake 最低版本要求
cmake_minimum_required(VERSION 3.12)

# 设置项目名称
project(cpp20ModuleProject)

# 指定使用 C++20 标准
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 添加可执行文件
add_executable(cpp_20_module cpp_20_module.cpp)
文件 CMakeLists.txt 创建成功,内容已写入。
!cmake -B build
!cmake --build build --target cpp_20_module
!build/cpp_20_module
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/build
Consolidate compiler generated dependencies of target cpp_20_module
[ 50%] Building CXX object CMakeFiles/cpp_20_module.dir/cpp_20_module.cpp.o
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:2:9: error: ‘vector’ was not declared in this scope
    2 | import <vector>;
      |         ^~~~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:2:9: error: ‘vector’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:2:9: error: ‘vector’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:2:9: error: ‘vector’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:2:9: error: ‘vector’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:2:9: error: ‘vector’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:2:9: error: ‘vector’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:2:9: error: ‘vector’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:2:9: error: ‘vector’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:2:1: error: ‘import’ does not name a type
    2 | import <vector>;
      | ^~~~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:2:1: note: C++20 ‘import’ only available with ‘-fmodules-ts’, which is not yet enabled with ‘-std=c++20’
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:3:9: error: ‘iostream’ was not declared in this scope
    3 | import <iostream>;
      |         ^~~~~~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:3:9: error: ‘iostream’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:3:9: error: ‘iostream’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:3:9: error: ‘iostream’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:3:9: error: ‘iostream’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:3:9: error: ‘iostream’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:3:9: error: ‘iostream’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:3:9: error: ‘iostream’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:3:9: error: ‘iostream’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:3:1: error: ‘import’ does not name a type
    3 | import <iostream>;
      | ^~~~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:3:1: note: C++20 ‘import’ only available with ‘-fmodules-ts’, which is not yet enabled with ‘-std=c++20’
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:4:9: error: ‘numeric’ was not declared in this scope
    4 | import <numeric>;
      |         ^~~~~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:4:9: error: ‘numeric’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:4:9: error: ‘numeric’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:4:9: error: ‘numeric’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:4:9: error: ‘numeric’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:4:9: error: ‘numeric’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:4:9: error: ‘numeric’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:4:9: error: ‘numeric’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:4:9: error: ‘numeric’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:4:1: error: ‘import’ does not name a type
    4 | import <numeric>;
      | ^~~~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:4:1: note: C++20 ‘import’ only available with ‘-fmodules-ts’, which is not yet enabled with ‘-std=c++20’
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:5:9: error: ‘ranges’ was not declared in this scope
    5 | import <ranges>;
      |         ^~~~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:5:9: error: ‘ranges’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:5:9: error: ‘ranges’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:5:9: error: ‘ranges’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:5:9: error: ‘ranges’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:5:9: error: ‘ranges’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:5:9: error: ‘ranges’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:5:9: error: ‘ranges’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:5:9: error: ‘ranges’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:5:1: error: ‘import’ does not name a type
    5 | import <ranges>;
      | ^~~~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:5:1: note: C++20 ‘import’ only available with ‘-fmodules-ts’, which is not yet enabled with ‘-std=c++20’
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:6:9: error: ‘cmath’ was not declared in this scope
    6 | import <cmath>;
      |         ^~~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:6:9: error: ‘cmath’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:6:9: error: ‘cmath’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:6:9: error: ‘cmath’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:6:9: error: ‘cmath’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:6:9: error: ‘cmath’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:6:9: error: ‘cmath’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:6:9: error: ‘cmath’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:6:9: error: ‘cmath’ was not declared in this scope
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:6:1: error: ‘import’ does not name a type
    6 | import <cmath>;
      | ^~~~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:6:1: note: C++20 ‘import’ only available with ‘-fmodules-ts’, which is not yet enabled with ‘-std=c++20’
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp: In function ‘int main()’:
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:9:10: error: ‘vector’ is not a member of ‘std’
    9 |     std::vector v = {4, 3, 2, 1, 0, -1, -2};
      |          ^~~~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:1:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
  +++ |+#include <vector>
    1 | 
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:10:22: error: ‘v’ was not declared in this scope; did you mean ‘vi’?
   10 |     for (auto &&vi : v
      |                      ^
      |                      vi
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:11:13: error: ‘std::views’ has not been declared
   11 |      | std::views::filter([](auto &&x) {return x >= 0; })
      |             ^~~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:12:13: error: ‘std::views’ has not been declared
   12 |      | std::views::transform([] (auto &&x) { return sqrtf(x); })
      |             ^~~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:14:14: error: ‘cout’ is not a member of ‘std’
   14 |         std::cout << vi << std::endl;
      |              ^~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:1:1: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
  +++ |+#include <iostream>
    1 | 
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:14:33: error: ‘endl’ is not a member of ‘std’
   14 |         std::cout << vi << std::endl;
      |                                 ^~~~
/mnt/c/Users/Jeff/Desktop/cpp_course_from_scratch/cpp_20_module.cpp:1:1: note: ‘std::endl’ is defined in header ‘<ostream>’; did you forget to ‘#include <ostream>’?
  +++ |+#include <ostream>
    1 | 
gmake[3]: *** [CMakeFiles/cpp_20_module.dir/build.make:76: CMakeFiles/cpp_20_module.dir/cpp_20_module.cpp.o] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:83: CMakeFiles/cpp_20_module.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/cpp_20_module.dir/rule] Error 2
gmake: *** [Makefile:124: cpp_20_module] Error 2
/bin/bash: line 1: build/cpp_20_module: No such file or directory

cmake is not support c++ 20 module currently

%%gadget -c cpp_20_module.cpp

import std.vector;
import std.iostream;
import std.numeric;
import std.ranges;
import std.cmath;

int main(){
    std::vector v = {4, 3, 2, 1, 0, -1, -2};
    for (auto &&vi : v
     | std::views::filter([](auto &&x) {return x >= 0; }) 
     | std::views::transform([] (auto &&x) { return sqrtf(x); })
     ){
        std::cout << vi << std::endl;
     }
    return 0;
}
文件 cpp_20_module.cpp 创建成功,内容已写入。
!g++-10 -std=c++20 -fmodules-ts ./cpp_20_module.cpp -o ./cpp_20_module
g++-10: error: unrecognized command-line option ‘-fmodules-ts’; did you mean ‘-fmodules’?
%%gadget -c cpp_20_module.cpp

import <vector>;
import <iostream>;
import <numeric>;
import <ranges>;
import <cmath>;

int main(){
    std::vector v = {4, 3, 2, 1, 0, -1, -2};
    for (auto &&vi : v
     | std::views::filter([](auto &&x) {return x >= 0; }) 
     | std::views::transform([] (auto &&x) { return sqrtf(x); })
     ){
        std::cout << vi << std::endl;
     }
    return 0;
}
文件 cpp_20_module.cpp 创建成功,内容已写入。
!clang++ -std=c++20 -fmodules -fcxx-modules ./cpp_20_module.cpp -o ./cpp_20_module
./cpp_20_module.cpp:2:8: error: header file <vector> (aka '/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/vector') cannot be imported because it is not known to be a header unit
import <vector>;
       ^
./cpp_20_module.cpp:3:8: error: header file <iostream> (aka '/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/iostream') cannot be imported because it is not known to be a header unit
import <iostream>;
       ^
./cpp_20_module.cpp:4:8: error: header file <numeric> (aka '/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/numeric') cannot be imported because it is not known to be a header unit
import <numeric>;
       ^
./cpp_20_module.cpp:5:8: error: header file <ranges> (aka '/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/ranges') cannot be imported because it is not known to be a header unit
import <ranges>;
       ^
./cpp_20_module.cpp:6:8: error: header file <cmath> (aka '/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/cmath') cannot be imported because it is not known to be a header unit
import <cmath>;
       ^
./cpp_20_module.cpp:9:5: error: use of undeclared identifier 'std'
    std::vector v = {4, 3, 2, 1, 0, -1, -2};
    ^
./cpp_20_module.cpp:11:8: error: use of undeclared identifier 'std'
     | std::views::filter([](auto &&x) {return x >= 0; }) 
       ^
./cpp_20_module.cpp:12:8: error: use of undeclared identifier 'std'
     | std::views::transform([] (auto &&x) { return sqrtf(x); })
       ^
./cpp_20_module.cpp:14:9: error: use of undeclared identifier 'std'
        std::cout << vi << std::endl;
        ^
./cpp_20_module.cpp:14:28: error: use of undeclared identifier 'std'
        std::cout << vi << std::endl;
                           ^
10 errors generated.
%%gadget -c cpp_20_module_auto.cpp

import <vector>;
import <iostream>;
import <numeric>;
import <ranges>;
import <cmath>;

void myfunc(auto &&v){
    for (auto &&vi : v
     | std::views::filter([](auto &&x) {return x >= 0; }) 
     | std::views::transform([] (auto &&x) { return sqrtf(x); })
     ){
        std::cout << vi << std::endl;
     }
}

int main(){
    std::vector v = {4, 3, 2, 1, 0, -1, -2};
    myfunc(v);
    return 0;
}
文件 cpp_20_module_auto.cpp 创建成功,内容已写入。
%%gadget -c cpp_20_coroutine_generator.cpp

import <vector>;
import <iostream>;
import <numeric>;
import <ranges>;
import <cmath>;
import <generator>;

std::generator<int> myfunc(auto &&v){
    for (auto &&vi : v
     | std::views::filter([](auto &&x) {return x >= 0; }) 
     | std::views::transform([] (auto &&x) { return sqrtf(x); })
     ){
        co_yield vi;
     }
}

int main(){
    std::vector v = {4, 3, 2, 1, 0, -1, -2};
    for (auto &&vi : myfunc(v))
        std::cout << vi << std::endl;
    return 0;
}
文件 cpp_20_coroutine_generator.cpp 创建成功,内容已写入。
%%gadget -c cpp_20_coroutine_generator_format.cpp

import <vector>;
import <iostream>;
import <numeric>;
import <ranges>;
import <cmath>;
import <generator>;

std::generator<int> myfunc(auto &&v){
    for (auto &&vi : v
     | std::views::filter([](auto &&x) {return x >= 0; }) 
     | std::views::transform([] (auto &&x) { return sqrtf(x); })
     ){
        co_yield vi;
     }
}

int main(){
    std::vector v = {4, 3, 2, 1, 0, -1, -2};
    for (auto &&vi : myfunc(v))
        std::format_to(std::cout, "num is: {}\n", vi);
    return 0;
}
文件 cpp_20_coroutine_generator_format.cpp 创建成功,内容已写入。