Skip to content

Instantly share code, notes, and snippets.

View Zaryob's full-sized avatar
🦾
Sayılmayız Parmak İle Tükenmeyiz Kırmak İle

Suleyman Poyraz Zaryob

🦾
Sayılmayız Parmak İle Tükenmeyiz Kırmak İle
View GitHub Profile
import std.core; // C++ standart kütüphane çekirdeğini içe aktar
#include <iostream>
int main() {
std::cout << "Hello, Modules!" << std::endl;
return 0;
}
import MathModule;
#include <iostream>
int main() {
std::cout << "Multiply: " << multiply(3, 4) << std::endl; // 12
std::cout << "Divide: " << divide(10, 2) << std::endl; // 5.0
return 0;
}
module MathModule;
int multiply(int a, int b) {
return a * b;
}
double divide(double a, double b) {
if (b == 0) {
throw std::invalid_argument("Division by zero!");
}
return a / b;
}
export module MathModule; // modül tanımı
export int multiply(int a, int b); // modüle export edilecek fonksiyonlar
export double divide(double a, double b);
import MyModule; // Modülü içe aktar
#include <iostream>
int main() {
std::cout << add(3, 4) << std::endl; // 7
// subtract(3, 4); // Hata: subtract dışa açık değil
return 0;
}
export module MyModule; // Modül bildirimi
export int add(int a, int b) { // Export ile dışa açıyoruz
return a + b;
}
int subtract(int a, int b) { // Export olmadan yazılan fonksiyonlar yalnızca modül içerisinde kullanılabilir
return a - b;
}
#include <iostream>
#include <future>
#include <coroutine>
std::future<void> asyncPrint(int value) {
std::cout << "İşleniyor: " << value << std::endl;
co_await std::suspend_always{};
std::cout << "Tamamlandı: " << value << std::endl;
}
int main() {
auto result = asyncPrint(42);
#include <iostream>
#include <coroutine>
struct Generator {
struct promise_type {
int current_value;
Generator get_return_object() {
return Generator{std::coroutine_handle<promise_type>::from_promise(*this)};
}
std::suspend_always initial_suspend() { return {}; }
std::suspend_always final_suspend() noexcept { return {}; }
#include <concepts>
#include <iostream>
template <typename T>
concept Addable = requires(T a, T b) {
a + b;
};
void addAndPrint(Addable auto a, Addable auto b) {
std::cout << a + b << std::endl;
template <typename T>
concept Addable = requires(T a, T b) {
a + b; // T türü toplama işlemini desteklemeli
};