How does Circle's CTFE compare to D?

Johannes Riecken johannes.riecken at gmail.com
Sat Dec 4 08:43:14 UTC 2021


I've watched [Don't constexpr all the 
things](https://www.youtube.com/watch?v=NNU6cbG96M4), which is a 
talk explaining how [Cirlce](https://www.circle-lang.org/) does 
meta-programming and I found it very interesting that it looks as 
simple as I as a newbie would imagine meta-programming should be, 
i.e. it can execute any C++ function or library function at 
compile time. Here are two interesting examples:

```
int i = 0;
int f() { return ++i; }
int main()
{
     std::cout << (@meta f()) << std::endl; // Outputs 1
     std::cout << (@meta f()) << std::endl; // Outputs 2
     std::cout << i << std::endl; // Outputs 0
}
```

```
#include <fstream>
#include <iterator>
#include <string>
@meta std::ifstream f("file.txt");
@meta std::string str(std::istreambuf_iterator<char>(t),
std::istreambuf_iterator<char>());
const char file_contents[] = @string(str);
```

How does Circle's approach compare with D's (or with the vision 
of the direction of D's CTFE)? Is it likely that Circle's 
meta-programming also requires ten-thousands of lines of extra 
compiler code? I personally tend to prefer code generation over 
meta-programming, as I find that simpler to reason about and it 
works in any language, but I see the benefits of CTFE as well.


More information about the Digitalmars-d mailing list