Skip to content

Commit 24b4376

Browse files
committed
Adding one more example for lecture
1 parent d66dec9 commit 24b4376

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

modules/imports/imported.cppm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module;
2+
3+
#include <cassert>
4+
5+
export module imported;
6+
7+
import<string>;
8+
9+
export std::string foo(int n) {
10+
assert(n < 42 && "argument shall be less than 42");
11+
return "Hello, world!";
12+
}
13+

modules/imports/main.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <iostream>
2+
3+
import imported;
4+
5+
int main() {
6+
std::cout << "foo: " << foo(0) << std::endl;
7+
}

modules/imports/runme.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
CXX=clang++-18
4+
5+
${CXX} --std=c++23 -fmodules --stdlib=libc++ --precompile imported.cppm -o imported.pcm
6+
${CXX} --std=c++23 -fmodules --stdlib=libc++ -fmodule-file=imported=imported.pcm imported.pcm main.cc

0 commit comments

Comments
 (0)