initial commit

master
Avril 4 years ago
commit 8384b240a8
Signed by: flanchan
GPG Key ID: 284488987C31F630

1
.gitignore vendored

@ -0,0 +1 @@
test/test

@ -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

@ -0,0 +1,34 @@
#pragma once
namespace frob
{
using u8 = unsigned char;
constexpr u8 rot13(u8 i)
{
return i ^ (u8)42;
}
template<std::size_t N>
struct cfrob
{
char out[N]{};
constexpr cfrob(const char (&sz)[N])
{
for(std::size_t i=0;i<N-1;i++)
out[i] = rot13((u8)sz[i]);
out[N-1] = 0;
}
};
template<>
struct cfrob<0>
{
char out[0]{};
};
}
template<frob::cfrob C>
constexpr auto operator "" _frob()
{
return C.out;
}

@ -0,0 +1,18 @@
#include <iostream>
#include <cstring>
#include <cfrob.hpp>
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;
}
Loading…
Cancel
Save