commit 8384b240a8c6f05981b38fa4e1423d5515c05dab Author: Avril Date: Thu Dec 3 17:11:28 2020 +0000 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aff2160 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +test/test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fa98b55 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ + + +.PHONY: test +test: test/test + +test/test: test/test.cpp + $(CXX) -I. --std=c++20 $< -o $@ + if strings $@ | grep Hello; then exit 1; fi + strings $@ | grep bOFFE >> /dev/null + @echo "Passed." + +clean: + rm -f test/test diff --git a/cfrob.hpp b/cfrob.hpp new file mode 100644 index 0000000..c9c84dc --- /dev/null +++ b/cfrob.hpp @@ -0,0 +1,34 @@ +#pragma once + +namespace frob +{ + using u8 = unsigned char; + constexpr u8 rot13(u8 i) + { + return i ^ (u8)42; + } + + template + struct cfrob + { + char out[N]{}; + constexpr cfrob(const char (&sz)[N]) + { + for(std::size_t i=0;i + struct cfrob<0> + { + char out[0]{}; + }; +} + +template +constexpr auto operator "" _frob() +{ + return C.out; +} + diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..f728bf0 --- /dev/null +++ b/test/test.cpp @@ -0,0 +1,18 @@ +#include +#include + +#include + +const auto str = "Hello world."_frob; + +int main() +{ + char* str2 = strdup(str); + memfrob(str2, strlen(str)); + + std::cout << str << std::endl; + std::cout << str2 << std::endl; + free(str2); + + return 0; +}