aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-02-08 14:54:01 +0100
committerAdrian Kummerlaender2015-02-08 14:54:01 +0100
commit3feb8a168075c4007fc466a0a4353e62e69d9802 (patch)
tree7e926e574cdcc75212c9d32771095b274cdea85e
parent32abf81176f654217c30f3a1dd25ba9ff4a67dc4 (diff)
downloadTypeAsValue-3feb8a168075c4007fc466a0a4353e62e69d9802.tar
TypeAsValue-3feb8a168075c4007fc466a0a4353e62e69d9802.tar.gz
TypeAsValue-3feb8a168075c4007fc466a0a4353e62e69d9802.tar.bz2
TypeAsValue-3feb8a168075c4007fc466a0a4353e62e69d9802.tar.lz
TypeAsValue-3feb8a168075c4007fc466a0a4353e62e69d9802.tar.xz
TypeAsValue-3feb8a168075c4007fc466a0a4353e62e69d9802.tar.zst
TypeAsValue-3feb8a168075c4007fc466a0a4353e62e69d9802.zip
Added _Scheme_ variant of prime example as documentation
-rw-r--r--README.md2
-rw-r--r--example/prime/prime.cc11
2 files changed, 12 insertions, 1 deletions
diff --git a/README.md b/README.md
index 2efea02..f7f0b5d 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# TypeAsValue
-…is a template metaprogramming library intended for compile time computation written in C++. As its name implies it follows the overall concept of viewing types as values and templates as functions manipulating those values.
+…is a template metaprogramming library intended for compile time computation written in C++. As its name implies it follows the overall concept of viewing types as values and templates as functions manipulating those values.
This library is currently primarily a reimplementation of my previous attempt at this problem: [ConstList](https://github.com/KnairdA/ConstList). As detailed in the appropriate [blog article](http://blog.kummerlaender.eu/article/a_look_at_compile_time_computation_in_cpp/) the mixed approach between generic lambda expressions, `constexpr` marked functions and template metaprogramming doesn't offer sufficient flexibility which led me to approach compile time computation in a slightly different manner via this new library.
diff --git a/example/prime/prime.cc b/example/prime/prime.cc
index 17d437c..f1771a6 100644
--- a/example/prime/prime.cc
+++ b/example/prime/prime.cc
@@ -9,8 +9,10 @@
#include "runtime/list/for_each.h"
+// (define candidates (iota 1000 2 1))
using candidates = tav::Iota<tav::Size<1000>, tav::Int<2>, tav::Int<1>>::type;
+// (define (isMultipleOf candidate base) (= (modulo candidate base) 0))
template <
typename Candidate,
typename Base
@@ -20,6 +22,9 @@ using isMultipleOf = tav::EqualValue<
tav::Int<0>
>;
+// (define (removeMultiplesOf candidates base)
+// (remove (lambda (x) (isMultipleOf x base))
+// candidates))
template <
typename Candidates,
typename Base
@@ -29,6 +34,11 @@ using removeMultiplesOf = tav::Remove<
Candidates
>;
+// (define (sieve candidates)
+// (cond ((null-list? candidates) (list))
+// (else (cons (car candidates)
+// (sieve (removeMultiplesOf (cdr candidates)
+// (car candidates)))))))
template <typename Candidates>
struct Sieve {
typedef typename tav::Cons<
@@ -47,6 +57,7 @@ struct Sieve<void> {
typedef void type;
};
+// (define primes (sieve candidates))
using primes = Sieve<candidates>::type;
int main(int, char **) {