From c52dbf5513ae7f106634967162da5cfb01dc5af3 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 26 Jul 2025 01:47:32 +0100 Subject: feat: SOCL v1.0.2, changelog soon! Signed-off-by: Amlal El Mahrouss --- dev/examples/opt/CMakeLists.txt | 12 +++++++++++ dev/examples/opt/opt.cc | 44 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 dev/examples/opt/CMakeLists.txt create mode 100644 dev/examples/opt/opt.cc (limited to 'dev/examples/opt') diff --git a/dev/examples/opt/CMakeLists.txt b/dev/examples/opt/CMakeLists.txt new file mode 100644 index 0000000..b63b1de --- /dev/null +++ b/dev/examples/opt/CMakeLists.txt @@ -0,0 +1,12 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + Opt + VERSION 1.0 + LANGUAGES CXX) + +add_executable(Opt opt.cc) + +set_property(TARGET Opt PROPERTY CXX_STANDARD 20) +target_include_directories(Opt PUBLIC ../../) diff --git a/dev/examples/opt/opt.cc b/dev/examples/opt/opt.cc new file mode 100644 index 0000000..a914d8d --- /dev/null +++ b/dev/examples/opt/opt.cc @@ -0,0 +1,44 @@ +/* + string checksum example + written by Amlal El Mahrouss. + licensed under the MIT license + */ + +#include +#include +#include + +static const char do_hash(const std::string& in) +{ + int hash = 0; + + for (long index = 0; index < in.size(); ++index) + { + hash += in[index]; + } + + return hash; +} + +static auto do_some(const std::string recv_data, const std::string check_data) +{ + const int hash_to_check = do_hash(check_data); /* here we assume this should match opt_hash */ + const int opt_hash = do_hash(recv_data); /* we assume that the hash is correct */ + + auto opt = snu::opt::opt(snu::opt::eval_eq(hash_to_check, opt_hash)); /* do the compute */ + return opt; +} + +/* finally test it */ +int main(int argc, char** argv) +{ + // ... let's assume we fetch data from network... + + snu::println("Testing data..."); + + auto opt = do_some("Ohio", "Ohio"); + opt.expect("Checksum failed, Ohio isn't Ohio!"); + + + return 0; +} -- cgit v1.2.3