changeset 0:c0219423b5b2

Add binary example (p. 4)
author Lewin Bormann <lbo@spheniscida.de>
date Mon, 23 Mar 2020 18:29:46 +0100
parents
children 3707ed11b401
files .hgignore CMakeLists.txt src/binary.cc src/example.cc
diffstat 4 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Mon Mar 23 18:29:46 2020 +0100
@@ -0,0 +1,1 @@
+^build
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CMakeLists.txt	Mon Mar 23 18:29:46 2020 +0100
@@ -0,0 +1,6 @@
+
+project("CTMP")
+
+add_executable(example src/example.cc)
+
+add_executable(binary src/binary.cc)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/binary.cc	Mon Mar 23 18:29:46 2020 +0100
@@ -0,0 +1,16 @@
+#include <iostream>
+
+template<unsigned long In>
+struct binary {
+    static const unsigned long value = binary<In/10>::value * 2 + In%10;
+};
+
+template<>
+struct binary<1> {
+    static const unsigned value = 1;
+};
+
+int main(void) {
+    std::cout << binary<1101011101>::value << "\n";
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/example.cc	Mon Mar 23 18:29:46 2020 +0100
@@ -0,0 +1,6 @@
+#include <iostream>
+
+int main(void) {
+    std::cout << "hello\n";
+    return 0;
+}